Skip to content

Commit 134f2cb

Browse files
committed
feat: database migration drift detection in CI
1 parent a907150 commit 134f2cb

6 files changed

Lines changed: 907 additions & 615 deletions

File tree

.github/workflows/database.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,26 @@ jobs:
4646
working-directory: backend
4747
run: npm install
4848

49+
- name: Dump live schema for snapshot comparison
50+
run: supabase db dump --local --schema-only -f /tmp/live-schema.sql
51+
4952
- name: Run migration drift check against local database
5053
id: local-drift-check
51-
# Official Supabase demo service role key — only valid for localhost:54321
5254
env:
53-
SUPABASE_URL: http://localhost:54321
55+
SUPABASE_URL: http://127.0.0.1:54321
5456
SUPABASE_SERVICE_ROLE_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
57+
DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:54322/postgres
5558
run: |
56-
echo "🔍 Verifying migration state against local database..."
57-
node scripts/check-migration-drift.js --verify-db --env local --json > local-drift-result.json 2>&1 || true
59+
echo "🔍 Verifying migration history and schema against local database..."
60+
node scripts/check-migration-drift.js \
61+
--verify-db \
62+
--verify-schema \
63+
--compare-schema supabase/schema.snapshot.sql \
64+
--live-schema /tmp/live-schema.sql \
65+
--env local \
66+
--strict \
67+
--json > local-drift-result.json
5868
cat local-drift-result.json
59-
node -e "
60-
const r = JSON.parse(require('fs').readFileSync('local-drift-result.json', 'utf8'));
61-
if (!r.success) {
62-
console.error('❌ Local database drift detected:');
63-
(r.dbCheck?.issues || []).forEach(i => console.error(' [' + i.type + '] ' + i.message));
64-
process.exit(1);
65-
}
66-
console.log('✅ Local database migration state matches filesystem (' + (r.dbCheck?.appliedCount ?? '?') + ' applied)');
67-
"
6869
6970
- name: Run RLS Policy Audit
7071
env:

0 commit comments

Comments
 (0)