Skip to content

@sbtools/plugin-migration-studio

npm

The flagship plugin. Provides a complete backend design platform for Supabase projects across five layers: Understand → Design → Generate → Validate → Apply. Every tool is available via both CLI (sbt studio-<tool>) and HTTP (POST /api/studio/<tool>), making the platform directly usable by AI agents.

Installation

bash
npm install @sbtools/plugin-migration-studio
json
{
  "plugins": [
    { "path": "@sbtools/plugin-migration-studio", "config": {} }
  ]
}

Starting the Server

bash
sbt migration-studio            # port 3335 (default)
sbt migration-studio --port N   # custom port
sbt migration-studio --restart  # force-restart if port in use

LLM / Agent Usage

Using Claude Desktop, Cursor, or VS Code? The @sbtools/mcp-server package exposes every tool below as a first-class MCP tool — no HTTP needed.

AI agents using the HTTP API can orient themselves in one call:

GET /api/studio/llm-context

Returns: intent graph summary, artifact freshness, full tool catalog with descriptions, migration count. Then the agent can call any tool:

POST /api/studio/introspect      → snapshot the DB
POST /api/studio/intent-init     → build intent graph
POST /api/studio/create-table    → generate migration SQL
POST /api/studio/release-gate    → validate before applying
POST /api/apply                  → apply if gate passes

Discover available tools and workflows:

GET /api/studio/catalog?audience=backend-dev&mode=managed&type=tools

Tool Catalog (21 tools)

Understand Layer

CLI CommandHTTP RouteProduces Artifact
studio-introspectPOST /api/studio/introspectstudio.schema.snapshot
studio-sql-parsePOST /api/studio/sql-parsestudio.sql.ast
studio-intent-syncPOST /api/studio/intent-syncstudio.intent.sync-report
studio-intent-initPOST /api/studio/intent-initstudio.intent.graph

Generate Layer (Scaffold Tools)

CLI CommandHTTP RouteWhat it generates
studio-create-tablePOST /api/studio/create-tableCREATE TABLE migration
studio-add-columnPOST /api/studio/add-columnALTER TABLE ... ADD COLUMN
studio-add-indexPOST /api/studio/add-indexCREATE INDEX
studio-add-constraintPOST /api/studio/add-constraintALTER TABLE ... ADD CONSTRAINT
studio-add-rls-policyPOST /api/studio/add-rls-policyCREATE POLICY
studio-add-functionPOST /api/studio/add-functionCREATE OR REPLACE FUNCTION
studio-create-rpcPOST /api/studio/create-rpcRPC function (schema: public)
studio-create-viewPOST /api/studio/create-viewCREATE OR REPLACE VIEW

Validate Layer

CLI CommandHTTP RouteProduces Artifact
studio-rls-check / studio-migration-lintPOST /api/studio/rls-checkstudio.rls.plan + studio.rls.report
studio-migration-lintPOST /api/studio/migration-lintstudio.migration.lint
studio-rpc-lintPOST /api/studio/rpc-lintstudio.rpc.plan
studio-migration-planPOST /api/studio/migration-planstudio.migration.plan
studio-release-gatePOST /api/studio/release-gatestudio.release.gate

Graph & Mapping

CLI CommandHTTP RouteDescription
studio-intent-patchPOST /api/studio/intent-graph/entityMutate entity managed-status
studio-endpoint-mapPOST /api/studio/endpoint-mapDerive PostgREST endpoints from intent graph
studio-greenfield-initPOST /api/studio/greenfield-initInit empty intent graph for new project

Workflow Catalog (4 workflows)

Workflows chain multiple tools with optional human checkpoints.

Workflow IDStepsUse Case
adopt-backendintrospect → sql-parse → intent-sync → intent-initBrownfield project adoption (2 checkpoints)
release-checkmigration-plan → rls-check → rpc-lint → release-gatePre-release validation
create-tablecreate-table → sql-parseTable + immediate AST update
add-rls-policyadd-rls-policy → rls-checkPolicy + immediate coverage check

Run the brownfield adoption workflow:

bash
sbt studio-adopt

Browse all workflows: GET /api/studio/catalog?type=workflows

Intent Graph

The intent graph (studio.intent.graph) is the central artifact. It assigns every DB entity a managedStatus:

StatusMeaning
managedFull confidence — schema matches SQL, safe to modify
assistedPartial match — LLM/human should review before modifying
opaqueUnknown origin — do not modify without explicit human sign-off
excludedIntentionally excluded from tracking

Read the current graph: GET /api/studio/intent-graph

Mutate an entity's status: POST /api/studio/intent-graph/entity

Release Gate

The release gate (studio-release-gate) aggregates evidence from all validation tools into a single { status: 'pass' | 'fail', reasons: [] } signal. POST /api/apply respects the gate — migrations are blocked if the gate has failed.

This is the recommended final step before any migration apply, especially for LLM-driven pipelines.

Migration Studio UI

The plugin also provides a CodeMirror 6 SQL editor UI accessible at http://localhost:3335 (or via the dashboard at /studio). Features:

  • Syntax highlighting, autocomplete (tables/columns from DB schema)
  • SQL analysis and dry-run validation
  • Save/apply migration files
  • Schema sidebar and migration list

HTTP API Reference

RouteDescription
GET /api/healthHealth check
GET /api/eventsSSE — live cache invalidation events
GET /api/schemaLive DB schema (tables, columns, policies, functions)
GET /api/templatesMigration template list
GET /api/migrationsMigration file list
POST /api/analyzeSQL analysis (parse + classify operations)
POST /api/validateSQL dry-run against live schema
POST /api/saveSave SQL to a migration file
POST /api/applyApply pending migrations (enforces release gate)
GET /api/studio/llm-contextFull project orientation for AI agents
GET /api/studio/intent-graphCurrent intent graph or null
GET /api/studio/catalogFilterable tool/workflow catalog
GET /api/studio/adopt/statusCurrent adoption workflow run state
POST /api/studio/adopt/startStart adoption workflow
POST /api/studio/adopt/resumeResume from checkpoint
POST /api/studio/<tool>Run any discovered tool (21 total)

Artifacts Produced

ArtifactDescription
studio.schema.snapshotLive DB schema as typed nodes
studio.sql.astSQL AST from migration files
studio.intent.sync-reportConfidence scores per entity (DB vs SQL)
studio.intent.graphTyped entity graph with managed/assisted/opaque status
studio.rls.planSuggested RLS policies for uncovered entities
studio.rls.reportRLS coverage analysis and gaps
studio.migration.lintRisk flags, naming violations, lock-safety
studio.rpc.planFunction security audit results
studio.migration.planOrdered change plan with change-class annotations
studio.release.gateAggregated pass/fail gate with blocking reasons
studio.apply.logApply history with timestamps and output
studio.workflow.runCurrent workflow run state (for resuming)

See Also