ci(db): automated database migration verification - #141
Conversation
Add a migrations job that runs against a fresh PostgreSQL service in CI: it generates the Prisma client, applies every pending migration, confirms the database is up to date, and drift-checks that the committed migrations fully rebuild the schema (in an ephemeral shadow database) compared to schema.prisma. Exposed locally via `npm run db:verify` (scripts/verify-migrations.sh), so a broken or ungenerated migration fails the pipeline before it reaches review. Closes ASTROIDX556#81 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@michealross Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Needs changes Missing executable permission on scripts/verify-migrations.sh script file.
Reviewed commit: |
The CI migration verification exposed pre-existing drift: schema.prisma had moved ahead of the committed 0_init migration (passkey challenges/credentials, webhook deliveries, policy override fields, api key IP allowlist, and the outbox_events table were never captured). Add a generated migration that brings the applied schema in line with schema.prisma, restoring zero drift. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
There was a problem hiding this comment.
Needs changes
Duplicate script entries exist in package.json and the verification script file is missing execution permissions and newline at EOF.
package.json:28: Duplicate "db:verify" script entry should be removed.scripts/verify-migrations.sh:59: Missing newline at end of file.
Reviewed commit: d9c828be4d0fcb6e34cea92547884a40fb3d7b5a.
|
Needs review Linked to The pull request includes a large unrequested migration file (prisma/migrations/20260830174000_sync_schema/migration.sql) which is out of scope for adding the automated database migration verification script and CI job. Reviewed commit: |
A merge left two identical db:verify entries in the scripts block. Drop the duplicate so the script is defined exactly once. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
MergeKeeper review Scope: in scope for linked issue The PR successfully adds an automated database migration verification script and CI pipeline job fulfilling issue #81. Reviewed commit: |
|
MergeKeeper merge status Status: blocked Reason: Next steps:
|
There was a problem hiding this comment.
Needs changes
Missing executable permission on scripts/verify-migrations.sh script file.
scripts/verify-migrations.sh:1: The verification script is executed via 'bash scripts/verify-migrations.sh', but it should also have executable permissions set or be handled properly.
Reviewed commit: 8c0abbea82680ba079a8a6152e151ebcd3ebb8b4.
Give scripts/verify-migrations.sh the executable bit and invoke it directly (via its shebang) instead of through `bash`, so the script is self-executing and works from any shell. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Merging main brought in schema changes (audit_logs.hash / previousHash) that were not captured in a migration, reintroducing drift. Add a new migration so migrations again fully reproduce schema.prisma. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
There was a problem hiding this comment.
Approved
The PR successfully adds an automated database migration verification script and CI pipeline job fulfilling issue #81.
Closes #81
Summary
Adds an automated script and CI job that verify the Prisma database migrations against a fresh PostgreSQL database, so broken or ungenerated migrations fail the pipeline before they reach review.
What changed
scripts/verify-migrations.sh(npm run db:verify) performs, in order:prisma generate— ensures the generated client is current.prisma migrate deploy— applies every pending migration toDATABASE_URL(fails if any migration SQL errors).prisma migrate status— confirms the database is fully migrated.SHADOW_DATABASE_URLis set): rebuilds the schema purely from the committed migrations in an ephemeral shadow database viaprisma migrate diff, and fails if the result differs fromprisma/schema.prisma. This catches schema edits that were never captured in a migration..github/workflows/ci.yml— newmigrationsjob that:postgres:16-alpineservice container,astroid_shadowdatabase,DATABASE_URL/SHADOW_DATABASE_URL,npm run db:verify.Locally
SHADOW_DATABASE_URLis optional — without it the drift check is skipped and only apply + status are verified.Validation
bash -n scripts/verify-migrations.sh— script syntax valid.ci.ymlparses cleanly (build, test, lint, typecheck, + migrations jobs).package.jsonJSON valid; no dependency changes (existingprismadevDependency only).