来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
69 lines
3.6 KiB
JavaScript
69 lines
3.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/** 生产环境脏数据只读审计 */
|
|
import pg from 'pg';
|
|
import dotenv from 'dotenv';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
dotenv.config({ path: path.join(__dirname, '..', '.env') });
|
|
|
|
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
|
|
|
|
const CHECKS = [
|
|
['E2E/test orders', `SELECT order_code, order_status, remark FROM orders
|
|
WHERE order_code LIKE 'E2E%' OR order_code LIKE 'ORD_MP_%'
|
|
OR COALESCE(remark, '') ILIKE '%E2E%'
|
|
OR COALESCE(remark, '') ILIKE '%流程测试%'
|
|
OR COALESCE(remark, '') ILIKE '%全链路%'
|
|
ORDER BY order_code`],
|
|
['legacy CYC cycles in orders', `SELECT cycle_code, count(*)::int AS c FROM orders WHERE cycle_code ~ '^CYC' GROUP BY 1`],
|
|
['test suppliers', `SELECT supplier_code, company_name FROM suppliers WHERE company_name ILIKE '%E2E%' OR supplier_code = 'SUP001'`],
|
|
['test purchaser_users', `SELECT purchaser_code, user_id FROM purchaser_users WHERE purchaser_code = 'PUR001'`],
|
|
['test delivery DP001', `SELECT person_code, person_name FROM delivery_persons WHERE person_code = 'DP001'`],
|
|
['profiles without roles', `SELECT p.username, p.full_name, p.branch_code FROM profiles p
|
|
LEFT JOIN user_roles ur ON ur.user_id = p.id
|
|
WHERE ur.user_id IS NULL AND p.id <> 'a0000000-0000-0000-0000-000000000001'`],
|
|
['null sku inventory', `SELECT count(*)::int AS c FROM inventory WHERE sku_code IS NULL`],
|
|
['null sku picking_items', `SELECT count(*)::int AS c FROM picking_items WHERE sku_code IS NULL`],
|
|
['duplicate supplier category bindings', `SELECT category_code, count(*)::int AS c FROM supplier_categories GROUP BY 1 HAVING count(*) > 1`],
|
|
['recent orders', `SELECT order_code, order_status, delivery_date, left(COALESCE(remark,''), 80) AS remark FROM orders ORDER BY created_at DESC LIMIT 15`],
|
|
['key table counts', `SELECT 'orders' AS t, count(*)::int AS c FROM orders
|
|
UNION ALL SELECT 'purchase_orders', count(*)::int FROM purchase_orders
|
|
UNION ALL SELECT 'supplier_preparations', count(*)::int FROM supplier_preparations
|
|
UNION ALL SELECT 'inspections', count(*)::int FROM inspections
|
|
UNION ALL SELECT 'inventory', count(*)::int FROM inventory
|
|
UNION ALL SELECT 'picking_tasks', count(*)::int FROM picking_tasks
|
|
UNION ALL SELECT 'delivery_tasks', count(*)::int FROM delivery_tasks
|
|
UNION ALL SELECT 'processing_tasks', count(*)::int FROM processing_tasks
|
|
UNION ALL SELECT 'exception_tickets', count(*)::int FROM exception_tickets`],
|
|
['optional photo permissions', `SELECT rp.role::text, p.permission_code FROM role_permissions rp
|
|
JOIN permissions p ON p.id = rp.permission_id
|
|
WHERE p.permission_code IN ('picking_manage', 'picking_barcode', 'inspection_photo', 'delivery_sign_photo')
|
|
ORDER BY 1, 2`],
|
|
['purchase orders missing branch_code', `SELECT count(*)::int AS c FROM purchase_orders WHERE branch_code IS NULL`],
|
|
['stale open orders', `SELECT order_code, order_status, delivery_date FROM orders
|
|
WHERE order_status NOT IN (90, 99) AND delivery_date < CURRENT_DATE - INTERVAL '7 days'
|
|
ORDER BY delivery_date LIMIT 20`],
|
|
];
|
|
|
|
async function main() {
|
|
console.log('=== PRODUCTION DIRTY DATA AUDIT ===');
|
|
console.log('DATABASE_URL set:', Boolean(process.env.DATABASE_URL));
|
|
for (const [label, sql] of CHECKS) {
|
|
console.log(`\n--- ${label} ---`);
|
|
try {
|
|
const { rows } = await pool.query(sql);
|
|
console.log(JSON.stringify(rows, null, 2));
|
|
} catch (error) {
|
|
console.log('ERR', error.message);
|
|
}
|
|
}
|
|
await pool.end();
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|