来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
// 阶段 5:确认 public 无业务表(除平台 + system_configs),legacy_public 与 tenant 可读
|
|
import 'dotenv/config';
|
|
import pg from 'pg';
|
|
|
|
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
|
|
|
|
function assert(cond, msg) {
|
|
if (!cond) throw new Error(msg);
|
|
}
|
|
|
|
const BUSINESS_SAMPLE = ['orders', 'product_catalog', 'customers', 'suppliers', 'skus', 'categories'];
|
|
|
|
const client = await pool.connect();
|
|
try {
|
|
const bizInPublic = await client.query(
|
|
`SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema = 'public'
|
|
AND table_name = ANY($1::text[])
|
|
ORDER BY 1`,
|
|
[BUSINESS_SAMPLE]
|
|
);
|
|
assert(bizInPublic.rowCount === 0, `public still has business tables: ${bizInPublic.rows.map((r) => r.table_name).join(',')}`);
|
|
|
|
const legacy = await client.query(
|
|
`SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema = 'legacy_public'
|
|
AND table_name = ANY($1::text[])
|
|
ORDER BY 1`,
|
|
[BUSINESS_SAMPLE]
|
|
);
|
|
assert((legacy.rowCount || 0) > 0, 'legacy_public missing sample business tables');
|
|
|
|
const sys = await client.query(
|
|
`SELECT COUNT(*)::int AS n FROM public.system_configs WHERE branch_code IS NOT NULL`
|
|
);
|
|
assert(Number(sys.rows[0].n) === 0, 'public.system_configs still has branch rows');
|
|
|
|
const reg = await client.query(
|
|
`SELECT branch_code, schema_name, status FROM public.tenant_schema_registry WHERE status = 'active'`
|
|
);
|
|
assert((reg.rowCount || 0) > 0, 'no active tenants');
|
|
|
|
for (const row of reg.rows) {
|
|
const cnt = await client.query(`SELECT COUNT(*)::int AS n FROM ${row.schema_name}.orders`);
|
|
console.log(`OK ${row.branch_code} orders=${cnt.rows[0].n}`);
|
|
}
|
|
|
|
const legacyOrders = await client.query(`SELECT COUNT(*)::int AS n FROM legacy_public.orders`);
|
|
console.log(`legacy_public.orders=${legacyOrders.rows[0].n}`);
|
|
console.log(`legacy tables sample: ${legacy.rows.map((r) => r.table_name).join(',')}`);
|
|
console.log('verify-legacy-public-archive: OK');
|
|
} finally {
|
|
client.release();
|
|
await pool.end();
|
|
}
|