سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 08:00 UTC
ci(phase1a): compare migration versions to read-only production snapshot and prohibit db push
davoodmehraban89 committed
Oct 16, 2026 at 16:39 UTC
30ed1e42ad04076a9b8757f393acebce1030e252
1 file changed
+29
scripts/phase1a-migration-preflight.mjs
new
+29
@@ -0,0 +1,29 @@
1
+#!/usr/bin/env node
2
+// Offline CI preflight based on an explicitly dated READ-ONLY Production ledger
3
+// snapshot. Never connects or writes to Production. NEVER authorizes db push.
4
+import fs from 'node:fs';
5
+import path from 'node:path';
6
+const prod=JSON.parse(fs.readFileSync('supabase/tests/fixtures/phase1a_production_migration_versions_20261016.json','utf8')).versions;
7
+const files=fs.readdirSync('supabase/migrations').filter(x=>x.endsWith('.sql')).sort();
8
+const local=files.map(x=>({version:x.split('_')[0],name:x.replace(/^[0-9]+_/,'').replace(/\.sql$/,'')}));
9
+const prodSet=new Set(prod.map(x=>x.version));
10
+const locSet=new Set(local.map(x=>x.version));
11
+const onlyProd=prod.filter(x=>!locSet.has(x.version));
12
+const onlyRepo=local.filter(x=>!prodSet.has(x.version));
13
+const workflow=fs.readFileSync('.github/workflows/phase1a-supabase-parity.yml','utf8');
14
+if(/^\s*supabase\s+db\s+push\b/m.test(workflow)){
15
+ console.error('FATAL: db push cannot occur in 1A CI');process.exit(1);
16
+}
17
+const historic=fs.readFileSync('docs/FINORA_PHASE1A_MIGRATION_VERSION_DIFF_2026-10-16.md','utf8');
18
+const approvedRemote=historic.split('## Production history entries absent from tracked files')[1].split('## Tracked repo files absent by exact filename')[0];
19
+const approvedLocal=historic.split('## Tracked repo files absent by exact filename')[1].split('**Required before migration:**')[0];
20
+const allowProd=new Set([...approvedRemote.matchAll(/\x60([0-9]{14})_[^\x60]+\.sql\x60/g)].map(m=>m[1]));
21
+const allowLocal=new Set([...approvedLocal.matchAll(/\x60([0-9]{14})_[^\x60]+\.sql\x60/g)].map(m=>m[1]));
22
+for(const v of ['20261007170000','20261016100000','20261016100500','20261016101000','20261016101500','20261016102000'])allowLocal.add(v);
23
+const unexpectedProd=onlyProd.filter(x=>!allowProd.has(x.version));
24
+const unexpectedLocal=onlyRepo.filter(x=>!allowLocal.has(x.version));
25
+const terminal=files.filter(x=>fs.readFileSync(path.join('supabase/migrations',x)).toString().endsWith('\\n'));
26
+const report={productionSnapshot:prod.length,repoFiles:local.length,matched:prod.length-onlyProd.length,onlyProduction:onlyProd,onlyRepository:onlyRepo,terminalLiteralBackslashN:terminal,unexpectedProd,unexpectedLocal,safeToPushToProduction:false,note:'Snapshot not real-time. Production db push remains blocked and requires fresh read-only preflight at cutover.'};
27
+fs.writeFileSync('phase1a-migration-preflight.json',JSON.stringify(report,null,2)+'\n');
28
+console.log(JSON.stringify({productionSnapshot:prod.length,repository:local.length,productionOnly:onlyProd.length,repoOnly:onlyRepo.length,unexpectedProd:unexpectedProd.length,unexpectedLocal:unexpectedLocal.length,terminalEscapes:terminal.length,productionPush:'PROHIBITED'}));
29
+if(unexpectedProd.length||unexpectedLocal.length)process.exitCode=1;