Files
SupplierSystem/scripts/_scan-sql-tables-vs-business.cjs
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库: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 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

76 lines
2.5 KiB
JavaScript

#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
function walk(d, acc = []) {
for (const e of fs.readdirSync(d, { withFileTypes: true })) {
const p = path.join(d, e.name);
if (e.isDirectory()) {
if (['node_modules', 'dist'].includes(e.name)) continue;
walk(p, acc);
} else if (/\.(ts|js)$/.test(e.name)) acc.push(p);
}
return acc;
}
const STOP = new Set([
'select', 'set', 'values', 'as', 'on', 'where', 'and', 'or', 'left', 'right',
'inner', 'outer', 'cross', 'lateral', 'true', 'false', 'null', 'now', 'case',
'when', 'then', 'else', 'end', 'limit', 'offset', 'group', 'order', 'having',
'union', 'all', 'distinct', 'insert', 'update', 'delete', 'returning',
'conflict', 'excluded', 'do', 'nothing', 'with', 'recursive', 'only',
'schema', 'information_schema', 'pg_catalog', 'auth', 'public', 'legacy_public',
'tenant_template', 'generate_series', 'unnest', 'coalesce', 'greatest', 'least',
'exists', 'any', 'some', 'in', 'not', 'is', 'between', 'like', 'ilike',
'current_date', 'current_timestamp', 'localtimestamp', 'interval', 'text',
'uuid', 'jsonb', 'json', 'boolean', 'integer', 'numeric', 'varchar',
]);
const files = walk(path.join(__dirname, '..', 'server', 'src'));
const tables = new Set();
const re =
/\b(?:FROM|INTO|UPDATE|JOIN|TABLE)\s+(?:ONLY\s+)?(?:public\.|legacy_public\.)?([a-z][a-z0-9_]*)\b/gi;
for (const f of files) {
const text = fs.readFileSync(f, 'utf8');
let m;
while ((m = re.exec(text))) {
const name = m[1].toLowerCase();
if (STOP.has(name)) continue;
if (name.startsWith('pg_')) continue;
if (name.startsWith('tenant_')) continue;
tables.add(name);
}
}
const businessListMatch = fs
.readFileSync(
path.join(__dirname, '..', 'migrations', '20260776_tenant_missing_link_tables.sql'),
'utf8'
)
.match(/SELECT ARRAY\[([\s\S]*?)\]::text\[\]/);
const business = new Set();
if (businessListMatch) {
for (const m of businessListMatch[1].matchAll(/'([a-z0-9_]+)'/g)) business.add(m[1]);
}
const platform = new Set([
'branches',
'profiles',
'user_roles',
'permissions',
'role_permissions',
'role_definitions',
'schema_migrations',
'tenant_schema_registry',
'system_configs',
]);
const usedNotInBusiness = [...tables]
.filter((t) => !business.has(t) && !platform.has(t))
.sort();
console.log('=== server/src SQL tables NOT in tenant_business_tables (excl platform) ===');
for (const t of usedNotInBusiness) console.log(t);
console.log('count', usedNotInBusiness.length);