worker.md SPEC
Menu

SQL Migration Linter

SQL Migration Linter is a reference AI Worker specification designed for reliable, bounded task execution.

Reference worker specification for inspecting PostgreSQL and MySQL DDL migrations for lock risks and non-concurrent index operations.

Pricing & Service Level Agreement (SLA)#

Specification Value Target Policy
Invocation Price $0.01 / run (Proposed) Billed per successful schema-validated output.
Payment Methods Stripe Metered • USDC (Base L2) Dual-rail support for teams and autonomous AI agents.
Execution Latency SLA < 8s (Target) Target deadline enforced by runtime deadline timer.
Max Token Budget $0.015 (Ceiling) Hardware token ceiling prevents runaway billing loops.
Benchmark Pass Rate Target: 100% Lock Detection Target evaluation benchmark pass rate on test fixtures.
Web3 Wallet Address 0x89D24A6b4CcB1B6fAA2625fE562bDD9a23260359 Direct on-chain recipient for autonomous HTTP 402 micro-txs.

worker.md Contract#

The formal execution contract defining inputs, outputs, limits, and runtime instructions:

---
name: sql-migration-linter
version: 1.0.0
description: Linters PostgreSQL and MySQL DDL migrations for exclusive table locks, unsafe column additions without defaults, and non-concurrent index operations.
category: database
author: worker.md community
license: MIT
pricing:
  model: per-invocation
  rate_usd: 0.01
  payment_methods:
    - type: stripe_metered
      plan_id: "price_sql_lint_metered_001"
    - type: crypto_micropayment
      network: base
      token: USDC
      wallet: "0x89D24A6b4CcB1B6fAA2625fE562bDD9a23260359"
      http_status_protocol: 402
sla:
  timeout_seconds: 8
  max_cost_usd: 0.015
  concurrency: 100
  eval_accuracy: 100.0%
inputs:
  migration_sql:
    type: string
    required: true
    description: Raw SQL DDL migration text to evaluate.
  database_engine:
    type: string
    enum: [postgresql, mysql]
    required: false
    default: postgresql
    description: Target database engine syntax rules.
  table_size_mb:
    type: number
    required: false
    description: Estimated size of the target table in megabytes to calculate lock downtime.
outputs:
  status:
    type: string
    enum: [safe, warning, dangerous]
    description: Migration safety gate status.
  lock_severity:
    type: string
    enum: [none, share_lock, exclusive_lock]
    description: Maximum table lock type acquired by the statements.
  issues:
    type: array
    description: Specific lock risks with line numbers and explanations.
  suggested_rewrite:
    type: string
    description: Zero-downtime, idempotent SQL rewrite.
constraints:
  timeout_ms: 8000
  max_cost_usd: 0.015
  allowed_tools: [sql-parser]
  temperature: 0.0
---

# SQL Migration Linter Worker

You are a database reliability engineer worker. Your goal is to inspect DDL migrations and detect statements that block concurrent reads or writes on production tables.

## Hazard Rules (PostgreSQL)
1. **Unindexed Foreign Keys:** Adding a foreign key constraint without a supporting index causes table locks on delete/update.
2. **Non-Concurrent Indexes:** `CREATE INDEX` without `CONCURRENTLY` acquires a `SHARE` lock, blocking all concurrent writes (`INSERT`, `UPDATE`, `DELETE`) until completion. Use `CREATE INDEX CONCURRENTLY` instead.
3. **Column with Volatile Default:** `ALTER TABLE ADD COLUMN foo TIMESTAMP DEFAULT now()` locks tables in Postgres < 11.
4. **Altering Column Type / Adding Primary Key:** Acquires an `ACCESS EXCLUSIVE` lock, blocking all reads and writes while rewriting the table.

## Decision Protocol
- If an `ACCESS EXCLUSIVE` or heavy `SHARE` lock will be acquired on a large table: `status: "dangerous"` or `"warning"`.
- If safe with minimal lock: `status: "safe"`.
- Provide an equivalent zero-downtime SQL script in `suggested_rewrite`.

Integration Code Examples#

Test and run this worker with schema-compliant payloads:

1. CLI Runner (Local Execution)

npx worker-md run workers/sql-migration-linter/WORKER.md \
  --input '{"migration_sql":"CREATE INDEX idx_orders_customer_id ON orders(customer_id);","database_engine":"postgresql"}'

2. HTTP Gateway (Stripe API Key)

curl -X POST https://gateway.worker.md/v1/workers/sql-migration-linter/invoke \
  -H "Authorization: Bearer wk_live_testkey123" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "migration_sql": "CREATE INDEX idx_orders_customer_id ON orders(customer_id);",
    "database_engine": "postgresql"
  }
}'

3. Autonomous Agent (HTTP 402 with Base USDC)

curl -X POST https://gateway.worker.md/v1/workers/sql-migration-linter/invoke \
  -H "Authorization: X402-Tx 0x4a8f9c2d1e0b5a...txhash" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "migration_sql": "CREATE INDEX idx_orders_customer_id ON orders(customer_id);",
    "database_engine": "postgresql"
  }
}'

4. Python (FastAPI / LangGraph)

import httpx

async def invoke_sql_migration_linter() -> dict:
    payload = {
    "migration_sql": "CREATE INDEX idx_orders_customer_id ON orders(customer_id);",
    "database_engine": "postgresql"
}
    async with httpx.AsyncClient() as client:
        response = await client.post(
            "https://gateway.worker.md/v1/workers/sql-migration-linter/invoke",
            headers={"Authorization": "Bearer wk_live_testkey123"},
            json={"inputs": payload},
            timeout=25.0
        )
        response.raise_for_status()
        return response.json()["outputs"]

Evaluation Fixtures & Benchmark Data#

Audit fixtures used to evaluate this worker specification:

{
  "suite": "sql-migration-linter-benchmark",
  "version": "1.0.0",
  "target_accuracy": 1.0,
  "fixtures": [
    {
      "id": "non-concurrent-index-postgres",
      "description": "CREATE INDEX on production table without CONCURRENTLY",
      "input": {
        "migration_sql": "CREATE INDEX idx_orders_customer_id ON orders(customer_id);",
        "database_engine": "postgresql"
      },
      "expected": {
        "status": "warning",
        "lock_severity": "share_lock",
        "rule_id": "POSTGRES-NON-CONCURRENT-INDEX"
      }
    },
    {
      "id": "safe-concurrent-index",
      "description": "CREATE INDEX CONCURRENTLY with safety",
      "input": {
        "migration_sql": "CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_orders_customer_id ON orders(customer_id);",
        "database_engine": "postgresql"
      },
      "expected": {
        "status": "safe",
        "lock_severity": "none"
      }
    }
  ]
}

See also#

FAQ#

How do I invoke SQL Migration Linter in my own pipeline?

You can invoke the worker package directly using the local CLI ('npx worker-md run workers/sql-migration-linter/WORKER.md --input ...') or deploy it to a private container gateway.

How does an autonomous agent pay via crypto?

An autonomous agent receives an HTTP 402 Payment Required response from the gateway, transfers 0.01 USDC to 0x89D24A6b4CcB1B6fAA2625fE562bDD9a23260359 on Base, and provides the transaction authorization header to execute.

How are timeout and cost constraints enforced?

The WORKER.md file declares the target limits (< 8s (Target), $0.015 (Ceiling)). The runtime execution harness enforces them with active process timers and token quotas.