سامانه صدور فاکتور و حسابداری
test: compare 1069 production schema fingerprints to isolated Supabase CLI reconstruction
davoodmehraban89 committed
Oct 16, 2026 at 13:02 UTC
ed17d4732dc1b6d92c51761588b4939767117744
1 file changed
+43
scripts/phase1a-schema-diff.mjs
new
+43
@@ -0,0 +1,43 @@
1
+#!/usr/bin/env node
2
+// Phase 1A: hash-only, read-only production versus locally rebuilt Supabase schema.
3
+import fs from 'node:fs';
4
+const [prodPath,localPath] = process.argv.slice(2);
5
+if (!prodPath || !localPath) throw Error('Usage: node scripts/phase1a-schema-diff.mjs <prod.json> <local.json>');
6
+const prod = JSON.parse(fs.readFileSync(prodPath,'utf8'));
7
+const localRaw = JSON.parse(fs.readFileSync(localPath,'utf8'));
8
+const local = Array.isArray(localRaw) ? localRaw : localRaw.objects;
9
+if (!Array.isArray(prod.objects) || !Array.isArray(local)) throw Error('Invalid catalog payloads');
10
+function unique(xs) {
11
+ const out=new Map();
12
+ for (const x of xs) {
13
+ if (!x.kind || !x.key || !x.hash) throw Error('Malformed fingerprint');
14
+ const k=x.kind+'|'+x.key;
15
+ if(out.has(k)) throw Error('Duplicate catalog object '+k);
16
+ out.set(k,x.hash);
17
+ }
18
+ return out;
19
+}
20
+const live=unique(prod.objects),rebuilt=unique(local);
21
+const onlyLive=[],onlyLocal=[],definitionDrift=[],same=[];
22
+for(const [key,hash] of live) {
23
+ if(!rebuilt.has(key))onlyLive.push(key);
24
+ else if(hash!==rebuilt.get(key))definitionDrift.push(key);
25
+ else same.push(key);
26
+}
27
+for(const key of rebuilt.keys())if(!live.has(key))onlyLocal.push(key);
28
+const sort=a=>a.sort((x,y)=>x.localeCompare(y,'en'));
29
+const result={
30
+ baseline:prod.baseline_repo_sha,prodCount:live.size,localCount:rebuilt.size,
31
+ A_numberingOnly:'Migration-name equivalence must be established separately with source manifest and live history; object hashes cannot prove numbered migration equivalence',
32
+ B_productionOnly:sort(onlyLive),
33
+ C_repositoryOnly:sort(onlyLocal),
34
+ D_sameIdentityDifferentDefinition:sort(definitionDrift),
35
+ sameIdentitySameDefinition:same.length,
36
+ parityVerified:onlyLive.length===0&&onlyLocal.length===0&&definitionDrift.length===0
37
+};
38
+fs.writeFileSync('phase1a-schema-diff.json',JSON.stringify(result,null,2)+'\n');
39
+console.log(JSON.stringify({prodCount:result.prodCount,localCount:result.localCount,prodOnly:onlyLive.length,repoOnly:onlyLocal.length,changed:definitionDrift.length,matching:same.length,parityVerified:result.parityVerified},null,2));
40
+for(const label of ['B_productionOnly','C_repositoryOnly','D_sameIdentityDifferentDefinition']) {
41
+ console.log('\n'+label+'\n'+result[label].slice(0,100).join('\n'));
42
+}
43
+if(!result.parityVerified)process.exitCode=1;