来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
37 lines
2.2 KiB
JavaScript
37 lines
2.2 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 });
|
|
|
|
async function q(label, sql) {
|
|
console.log(`\n--- ${label} ---`);
|
|
console.log(JSON.stringify((await pool.query(sql)).rows, null, 2));
|
|
}
|
|
|
|
async function main() {
|
|
await q('demo customers usage', `SELECT c.customer_code, c.company_name, p.username,
|
|
(SELECT count(*)::int FROM orders o WHERE o.customer_code=c.customer_code) AS order_count
|
|
FROM customers c
|
|
LEFT JOIN customer_portal_users cpu ON cpu.customer_code=c.customer_code
|
|
LEFT JOIN profiles p ON p.id=cpu.user_id
|
|
WHERE c.customer_code IN ('CUST001','CUST002') OR c.company_name LIKE '%(客户)%'`);
|
|
await q('exception tickets', `SELECT * FROM exception_tickets LIMIT 5`);
|
|
await q('E2E test profiles', `SELECT id, username FROM profiles WHERE id::text ~ '^(a0000000|b0000000)-'`);
|
|
await q('orphan purchase no order', `SELECT count(*)::int c FROM purchase_orders po WHERE po.order_code IS NOT NULL AND NOT EXISTS (SELECT 1 FROM orders o WHERE o.order_code=po.order_code)`);
|
|
await q('orphan prep no order', `SELECT count(*)::int c FROM supplier_preparations sp WHERE sp.order_code IS NOT NULL AND NOT EXISTS (SELECT 1 FROM orders o WHERE o.order_code=sp.order_code)`);
|
|
await q('inventory without inspection', `SELECT count(*)::int c FROM inventory i WHERE NOT EXISTS (SELECT 1 FROM inspections ins WHERE ins.id=i.source_id) AND i.source_type='inspection'`);
|
|
await q('BR001 business rows', `SELECT 'customers' t, count(*)::int c FROM customers WHERE branch_code='BR001'
|
|
UNION ALL SELECT 'orders', count(*)::int FROM orders WHERE branch_code='BR001'
|
|
UNION ALL SELECT 'categories', count(*)::int FROM categories WHERE branch_code='BR001'`);
|
|
await q('notifications count', `SELECT count(*)::int c FROM notifications`);
|
|
await q('operation_logs recent', `SELECT count(*)::int c FROM operation_logs WHERE created_at > NOW() - INTERVAL '30 days'`);
|
|
await pool.end();
|
|
}
|
|
|
|
main().catch((e) => { console.error(e); process.exit(1); });
|