/** * E2E 基础数据播种:插入少量客户档案(含各信用等级),供 e2e-full.mjs 使用。 * 幂等(ON CONFLICT DO NOTHING)。CI 与本地均可运行。 */ import { Client } from 'pg'; const URL = process.env.DATABASE_URL ?? 'postgresql://localhost:5432/riskagent'; const customers = [ { id: 'seed-cust-aaa', name: '某国有大行', creditRating: 'AAA', avgOverdueDays: 3, totalContractAmount: 8000000, assessmentCount: 0, notes: null }, { id: 'seed-cust-a', name: '某制造企业', creditRating: 'A', avgOverdueDays: 15, totalContractAmount: 2000000, assessmentCount: 0, notes: null }, { id: 'seed-cust-bbb', name: '某省电信公司', creditRating: 'BBB', avgOverdueDays: 45, totalContractAmount: 3000000, assessmentCount: 0, notes: null }, { id: 'seed-cust-b', name: '某互联网初创企业', creditRating: 'B', avgOverdueDays: 70, totalContractAmount: 500000, assessmentCount: 0, notes: null }, ]; const c = new Client({ connectionString: URL }); await c.connect(); for (const x of customers) { await c.query( `INSERT INTO customers(id, name, credit_rating, avg_overdue_days, total_contract_amount, assessment_count, notes, updated_at) VALUES($1,$2,$3,$4,$5,$6,$7,now()) ON CONFLICT(id) DO NOTHING`, [x.id, x.name, x.creditRating, x.avgOverdueDays, x.totalContractAmount, x.assessmentCount, x.notes], ); } await c.end(); console.log('已播种', customers.length, '个客户档案');