Quickstart
You need an API key to authenticate requests. All examples use the X-API-Key header.
-
Register a database connection
Send a
POSTrequest to register your database. Save theidfrom the response — you will use it in every subsequent call.Terminal window curl -X POST https://api.autodb.app/api/v1/connections \-H "Content-Type: application/json" \-H "X-API-Key: YOUR_API_KEY" \-d '{"name": "Production Analytics DB","db_type": "supabase","connection_string": "postgresql://app_user:***@db.example.supabase.co:5432/analytics"}'Response:
{"success": true,"data": {"id": "550e8400-e29b-41d4-a716-446655440000","name": "Production Analytics DB","db_type": "supabase","host": "db.example.supabase.co","port": 5432,"database_name": "analytics","is_active": true,"created_at": "2024-01-15T09:30:00Z","last_introspected_at": null},"error": null}Note that
last_introspected_atisnull— AutoDB has not yet scanned this database’s schema.Introspect your schema
Before analyzing migrations, AutoDB needs a snapshot of your current schema. Trigger an introspection using the
connection_idfrom above:Terminal window curl -X POST https://api.autodb.app/api/v1/connections/550e8400-e29b-41d4-a716-446655440000/introspect \-H "Content-Type: application/json" \-H "X-API-Key: YOUR_API_KEY"Response:
{"success": true,"data": {"connection_id": "550e8400-e29b-41d4-a716-446655440000","table_count": 12,"tables": ["customers","order_items","orders","products"],"snapshot_id": "660e8400-e29b-41d4-a716-446655440001","introspected_at": "2024-01-15T10:00:00Z"},"error": null}AutoDB discovered 12 tables and created a schema snapshot. You are now ready to analyze migrations against this schema.
-
Submit a migration for analysis
Submit your SQL migration to get a risk assessment, blast radius analysis, and rollback plan.
Terminal window curl -X POST https://api.autodb.app/api/v1/connections/550e8400-e29b-41d4-a716-446655440000/migrations/analyze \-H "Content-Type: application/json" \-H "X-API-Key: YOUR_API_KEY" \-d '{"sql": "ALTER TABLE orders ADD COLUMN priority VARCHAR(20) DEFAULT '\''normal'\'';\nCREATE INDEX CONCURRENTLY idx_orders_priority ON orders(priority);"}'Response (key fields shown):
{"success": true,"data": {"risk_score": 35,"risk_category": "medium","total_statements": 1,"affected_tables": [{"table": "orders","impact": "direct","cascade_path": null},{"table": "order_items","impact": "cascade","cascade_path": ["orders", "order_items"]}// ...],"sandbox_result": {"passed": true,"migration_applied": true,"tables_created": 8,"duration_ms": 4500// ...},"rollback_plan": {"has_irreversible": false,"combined_script": "BEGIN;\nALTER TABLE orders DROP COLUMN priority;\nCOMMIT;"// ...},"approval_token": "eyJzcWwiOi4uLn0.a1b2c3d4"// ...},"error": null} -
Review the risk report
The analysis response contains everything you need to decide whether to proceed with the migration.
Risk score and category
The
risk_score(0—100) andrisk_categorysummarize overall migration risk. The score combines lock severity and duration, destructive operation penalties, and FK cascade blast radius:Category Score Range Meaning low0—24 Short locks, no data loss risk, limited blast radius medium25—49 Moderate lock impact or FK cascade depth high50—74 Destructive operations or wide FK blast radius critical75—100 Destructive changes with extensive cascade impact In our example, a
risk_scoreof 35 (medium) indicates moderate lock impact from the schema change without destructive operations.Sandbox validation
The
sandbox_resultfield shows what happened when AutoDB ran your migration in an ephemeral Postgres clone:passed: true— the migration applied successfully without errorsmigration_applied: true— all statements executedtables_created: 8— the sandbox seeded 8 tables from your schema snapshotduration_ms: 4500— total sandbox execution time
If
passedisfalse, the migration has a syntax error or violates a constraint. Fix it before proceeding.Affected tables
Each entry in
affected_tablesshows which tables the migration touches:direct— the statement explicitly modifies this table (e.g.,ALTER TABLE orders)cascade— the table is impacted through foreign key relationships (e.g.,order_itemsdepends onordersvia FK)
The
cascade_pathfield traces the FK chain from the directly affected table to the cascade target.Rollback plan
has_irreversible: false— every statement in this migration can be automatically reversedcombined_script— a transaction-wrapped SQL script that undoes the entire migration
If
has_irreversibleistrue, at least one statement cannot be automatically rolled back (e.g.,DROP COLUMNwith data loss). Review the per-statement rollback steps for details.Approval token
The
approval_tokenis an HMAC-signed token that authorizes execution of this specific migration. To apply the migration to your production database, submit it toPOST /api/v1/migrations/executealong with the original SQL and connection ID.
Next steps
Section titled “Next steps”Ready to execute? See the Migration Execution reference for the approval token flow.