Skip to content

feat(aws/rds): apply SQL migrations on Aurora over the Data API - #2125

Open
xofromthemoon wants to merge 4 commits into
alchemy-run:mainfrom
xofromthemoon:cursor/aws-database-migrations
Open

xofromthemoon wants to merge 4 commits into
alchemy-run:mainfrom
xofromthemoon:cursor/aws-database-migrations

Conversation

@xofromthemoon

@xofromthemoon xofromthemoon commented Oct 7, 2026 •

Copy link
Copy Markdown

AWS.RDS.Aurora now applies SQL migrations on deploy over the RDS Data API, so the deploying machine needs no VPC access or database socket.

const db = yield* AWS.RDS.Aurora("AppDb", {
  subnetIds,
  securityGroupIds,
  migrations: "./migrations", // or a Drizzle.Schema, or { dir, table }
});

Migrations run from the writer DBInstance: once the instance is available, its reconcile applies them over the cluster's Data API. A hand-built cluster declares them on its writer:

const writer = yield* AWS.RDS.DBInstance("Writer", {
  dbClusterIdentifier: cluster.dbClusterIdentifier,
  dbInstanceClass: "db.serverless",
  engine: "aurora-postgresql",
  migrations: "./migrations",
  // migrationsSecretArn defaults to the cluster's RDS-managed master secret
});

It uses the shared migrations pipeline: bookkeeping in __alchemy_migrations, one-way adoption of drizzle-kit/Prisma history, and rejection of rewritten history. Each migration and its bookkeeping row commit in one Data API transaction. Deleting or replacing the instance never touches the database, and a replacement writer finds the existing bookkeeping and applies nothing twice.

The Data API runs one statement per call, so put each statement in its own file or separate them with --> statement-breakpoint (drizzle-kit's default). Declare migrations on one instance per cluster. Aurora rejects migrations combined with dataApi: false. Calls retry DatabaseResumingException while an auto-paused Serverless v2 writer wakes up.

The live test is gated behind AWS_TEST_RDS_DBINSTANCE, because creating and deleting the cluster and writer takes about 15 minutes.

…lpers

- Use an identity id column for every Postgres bookkeeping table; drop SqlExecutor.idColumn
- DSQL batch commits each DDL alone and groups consecutive DML in one transaction
- Add shared connectPgClient/withPgClient/stripSslQueryParams; move Neon, Fly, PlanetScale onto them
- Extract dsqlConnectionInfo shared by ConnectHttp and DSQL migrations
- DBClusterMigrations: update instead of replace, typed resume retries, rollback on commit failure
- Aurora: order migrations after the writer via Output.all; reject migrations with dataApi: false
…-migrations

# Conflicts:
#	packages/alchemy/src/AWS/DSQL/Cluster.ts
#	packages/alchemy/src/AWS/DSQL/Migrations.ts
#	packages/alchemy/src/AWS/RDS/Aurora.ts
#	packages/alchemy/src/Fly/PostgresMigrations.ts
#	packages/alchemy/src/Neon/Migrations.ts
#	packages/alchemy/src/Planetscale/Postgres/PostgresMigrations.ts
#	packages/alchemy/src/SQL/Migrations/AlchemyFormat.ts
#	packages/alchemy/test/AWS/DSQL/Cluster.test.ts
@xofromthemoon xofromthemoon changed the title feat(aws): apply SQL migrations on DSQL Cluster and Aurora feat(aws/rds): apply SQL migrations on Aurora over the Data API Oct 9, 2026
Replace the AWS.RDS.DBClusterMigrations resource with a migrations prop on
DBInstance, applied over the cluster's Data API at the end of reconcile once
the instance is available. Aurora passes migrations to its writer only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant