/agent-skills:dsql-migratefrom Agent Skills
Generate and apply Prisma migrations for Aurora DSQL. Handles DSQL-specific transformations (ASYNC indexes, one DDL per transaction, no FKs) and applies migrations to the correct environment schema (dev/preview/prod). INVOKE PROACTIVELY whenever: touching api/admin/migrate, running migrations after a deploy, seeing any DSQL error at runtime, or setting up a Vercel project that uses Aurora DSQL — even if the user's request was framed as a code task.
Ships in Agent Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Manages the full migration lifecycle for Aurora DSQL projects using Prisma 7 and the multi-schema pattern.
DSQL requires special SQL transformations that vanilla Prisma doesn't provide:
BEGIN; ... COMMIT;CREATE INDEX → CREATE INDEX ASYNCThe aurora-dsql-prisma migrate CLI handles this automatically.
Command:
npx aurora-dsql-prisma migrate prisma/schema.prisma -o prisma/migrations/001_init/migration.sql
This runs automatically in postinstall — you rarely need to run it manually unless:
Migrations are applied via POST /api/admin/migrate after deployment. Each environment (dev/preview/prod) maintains its own schema and migration history.
Every Vercel deployment resolves the active schema based on:
NODE_ENV === "development" → myapp_devVERCEL_ENV === "preview" → myapp_previewVERCEL_ENV === "production" → myapp_prodThe migration runner:
SET search_path TO <schema> before running any SQLCREATE SCHEMA IF NOT EXISTS)_prisma_migrations tracking table in that schema_prisma_migrationsThis means:
Edit prisma/schema.prisma:
model Todo {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
title String @db.VarChar(255)
completed Boolean @default(false)
+ priority Int @default(0)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
@@map("todos")
}
npx aurora-dsql-prisma migrate prisma/schema.prisma -o prisma/migrations/002_add_priority/migration.sql
The output will be DSQL-compatible SQL:
-- CreateColumn
BEGIN;
ALTER TABLE "todos" ADD COLUMN "priority" INTEGER NOT NULL DEFAULT 0;
COMMIT;
Update app/api/admin/migrate/route.ts:
const MIGRATIONS = [
{
name: "001_init",
filePath: path.join(process.cwd(), "prisma/migrations/001_init/migration.sql"),
},
+ {
+ name: "002_add_priority",
+ filePath: path.join(process.cwd(), "prisma/migrations/002_add_priority/migration.sql"),
+ },
];
git add prisma/schema.prisma prisma/migrations/002_add_priority app/api/admin/migrate/route.ts
git commit -m "Add priority field to todos"
git push
After deployment finishes:
Preview deployments are behind Vercel SSO protection. Plain
curlwill return an HTML login page, not JSON. Usevercel curlwhich handles authentication automatically. Note the--separator — curl flags go after it.
Preview (use vercel curl):
SECRET="your-migration-secret"
vercel curl /api/admin/migrate \
--deployment https://myapp-git-feature-branch.vercel.app \
-- --request POST \
--header "Content-Type: application/json" \
--header "x-migration-secret: $SECRET" \
--data '{"script":"002_add_priority"}'
Production (also use vercel curl — per-deployment *.vercel.app URLs are behind Vercel auth too):
vercel curl /api/admin/migrate \
--deployment https://myapp-abc123.vercel.app \
--cwd /path/to/main-repo \
-- --request POST \
--header "Content-Type: application/json" \
--header "x-migration-secret: $SECRET" \
--data '{"script":"002_add_priority"}'
Only a custom domain (e.g.
myapp.com) would be reachable via plaincurl. All*.vercel.appURLs requirevercel curl.
Response:
{
"message": "Migration completed successfully.\n\nUsing schema: myapp_prod\n✓ ...",
"schema": "myapp_prod"
}
Preview:
vercel curl /api/admin/migrate \
--deployment https://myapp-git-feature-branch.vercel.app \
-- --header "x-migration-secret: $SECRET"
Production:
vercel curl /api/admin/migrate \
--deployment https://myapp-abc123.vercel.app \
--cwd /path/to/main-repo \
-- --header "x-migration-secret: $SECRET"
To find the latest production deployment URL: vercel list --cwd /path/to/main-repo — it's the first result.
Response:
{
"schema": "myapp_prod",
"appliedMigrations": ["001_init", "002_add_priority"],
"manifest": [...]
}
Cause: No DATABASE_URL in prisma.config.ts — prisma migrate diff can't determine the SQL dialect.
Fix: Ensure prisma.config.ts has:
datasource: {
url: process.env.DATABASE_URL ?? "postgresql://localhost/prisma",
}
The ?? "postgresql://localhost/prisma" fallback is essential — it's only used for dialect detection, never for actual connections.
Symptom: Tables appear in myapp_dev when you expected myapp_prod.
Cause 1: PGSCHEMA environment variable is set, overriding automatic schema resolution.
Fix: Remove PGSCHEMA from Vercel project settings.
Cause 2: VERCEL_ENV is not set correctly during deployment.
Fix: Check the deployment logs — VERCEL_ENV should be preview or production, not development.
Symptom: Migration applied successfully (confirmed via /api/admin/migrate status), but local dev or E2E tests crash with The table 'public.X' does not exist in the current database.
Root cause: The migration runner targets getActiveSchema() (e.g. myapp_dev). But lib/prisma.ts may have two code paths — one for DATABASE_URL (local) and one for DSQL. If the local path creates PrismaPg(pool) without a { schema } option, Prisma queries public instead of myapp_dev. The tables never meet.
Fix — update lib/prisma.ts to pass the schema on the local path too:
import { getActiveSchema } from './schema'
// Before:
if (process.env.DATABASE_URL) {
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
const adapter = new PrismaPg(pool) // ← queries public
return new PrismaClient({ adapter })
}
// After:
if (process.env.DATABASE_URL) {
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
const adapter = new PrismaPg(pool, { schema: getActiveSchema() }) // ← same schema everywhere
return new PrismaClient({ adapter })
}
Do NOT work around this by manually applying DDL to public. That creates a silent schema split: local dev queries one place, DSQL queries another, and the two drift apart silently.
CREATE INDEX ASYNC IF NOT EXISTS syntax error on local PostgresSymptom: Migration applied via /api/admin/migrate shows ✗ Error: syntax error at or near "IF" for index creation lines, but table and column DDL succeeds.
Cause: Local Postgres doesn't support the ASYNC keyword (it's DSQL-specific). Postgres parses CREATE INDEX ASYNC IF NOT EXISTS idx ON ... as "create an index named ASYNC, then see unexpected IF".
This is safe to ignore for local dev. The table and column DDL still applied correctly. The ASYNC indexes are a DSQL performance optimization; regular Postgres doesn't need them and will use its own indexing.
If you need local indexes (e.g. for query performance testing), apply them separately without the ASYNC keyword:
podman exec <container> psql -U postgres -d <db> \
-c "SET search_path TO myapp_dev;" \
-c "CREATE INDEX IF NOT EXISTS idx_name ON table_name (column_name);"
Symptom: Running a migration against preview or production returns ✗ Error: unsupported mode. please use CREATE INDEX ASYNC. for every index creation.
Cause: The migration runner has logic to strip ASYNC from index statements for local Postgres compatibility, but it's running unconditionally — including on DSQL, which requires ASYNC.
Fix: Gate the strip on process.env.DATABASE_URL being set. That env var is only set in local dev (via worktree-bootstrap); on Vercel/DSQL it's absent.
// WRONG — unconditional strip breaks DSQL
const stmt = sql.replace(/\bINDEX ASYNC\b/gi, 'INDEX')
// RIGHT — only strip when running against local Postgres
const stmt = process.env.DATABASE_URL
? sql.replace(/\bINDEX ASYNC\b/gi, 'INDEX')
: sql
Watch for two execution paths. The migration route.ts often has both an inline POST handler loop and a runSqlScript() helper function. Both need this fix independently — it's easy to fix one and miss the other. Search for all occurrences of INDEX ASYNC in the file before committing.
Symptom: App throws column "xyz" does not exist at runtime. The table exists in the schema but was created from an older migration before the column was added.
Cause: A new migration that adds the column was never applied to this environment. Common when a DB was seeded from a stale full schema, or when an incremental migration was skipped.
Fix: Write the missing column as a migration (ADD COLUMN IF NOT EXISTS) and apply it via the API:
vercel curl /api/admin/migrate --deployment <URL> \
-- --request POST \
--header "x-migration-secret: $SECRET" \
--header "Content-Type: application/json" \
--data '{"script":"NNN-add-missing-column.sql"}'
Do NOT apply DDL directly to the database. Direct changes bypass the migration tracker, create environment drift (preview has it, prod doesn't), and won't be reproducible. Always create a migration file and run it through the API.
Symptom: Migration fails with "foreign key constraints are not supported".
Cause: relationMode = "prisma" is missing from schema.prisma.
Fix: Add to datasource block:
datasource db {
provider = "postgresql"
relationMode = "prisma" // Required for DSQL
}
Then regenerate the migration.
CREATE INDEX failsSymptom: Migration fails with "synchronous indexes not supported".
Cause: The aurora-dsql-prisma migrate tool didn't run, so indexes are missing the ASYNC keyword.
Fix: Run the migration generator manually:
npx aurora-dsql-prisma migrate prisma/schema.prisma -o prisma/migrations/XXX/migration.sql
Or ensure postinstall script is working correctly.
Symptom: Migration fails with "cannot execute multiple DDL statements".
Cause: Raw SQL contains multiple DDL statements not wrapped in separate transactions.
Fix: The aurora-dsql-prisma tool should handle this automatically. If you're writing raw SQL manually, wrap each statement:
BEGIN;
CREATE TABLE foo (...);
COMMIT;
BEGIN;
CREATE INDEX ASYNC idx_foo ON foo(bar);
COMMIT;
npx aurora-dsql-prisma migrate ...worktree-bootstrap skill for local DSQL fallback)_prisma_migrations tableFor breaking changes (dropping columns, renaming tables):
Many projects maintain both an authoritative full schema (e.g. 001-full-schema.sql) for fresh DB bootstrapping AND incremental migrations for patching existing DBs. Keep these facts in mind:
CREATE TABLE IF NOT EXISTS and CREATE INDEX ASYNC IF NOT EXISTS so it's safe to re-run on an existing DB.tasks.task_list_id where that column is added by task-lists.sql). If the full schema runs first, that index creation will fail with "column does not exist". This is non-fatal — the index will be created when the incremental runs.postinstall script runs aurora-dsql-prisma migrateBEGIN; ... COMMIT; around each DDL statementCREATE INDEX ASYNC (not CREATE INDEX)prisma.config.ts has a url fallback (for dialect detection)schema.prisma has relationMode = "prisma"VERCEL_ENV is set correctly in deploymentPGSCHEMA environment variable is setgetActiveSchema() returns the expected schema nameINDEX ASYNC stripping in migration runner is gated on DATABASE_URL being set, not unconditionalvercel curl --deployment <URL> for protected preview environments, not plain curlWhat SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (richardbowman/agent-skills) — no native marketplace selected
npx claudepluginhub p/richardbowman-agent-skills32 skills in this plugin
/backup-vercel-secretsBack up Vercel production and preview environment variables to 1Password as individual key/value fields. Use when the user wants to snapshot or archive their Vercel secrets for a project./brain-dumpInteractive knowledge extraction interviewer. Enters a structured interview mode to extract tacit knowledge from the user and saves a full transcript plus structured notes to the Obsidian vault./brainstormActive ideation partner. The assistant leads the session by proposing angles, surfacing frameworks, filling knowledge gaps, and challenging assumptions. Produces a structured Obsidian ideation doc and session transcript.Other plugins' skills for the same job