- T1 资金/库存/报价/自采 P1(BIZ-1/2/3/4/10/13/14) - T2 主系统反向事件墓碑/改派/孤儿处理(BIZ-6/8/9) - T3 选分公司 ticket、trust proxy、角色权限收口(SEC-2/3/4) - T4 缺列/RLS/tenant 名单/FK/迁移执行器(DATA-1..8) - T5 401 登出/分页/映射口径/blob/ZIP 中文名(FE-1..4/BIZ-15) - T6 测试脚本目标守卫/config fail-fast/容器配置(OPS-2..8) - T7 前后端测试与 lint 门禁清零 - T8 应付卡片按关联订单日(口径 A) - T9 存储对象全链路归属校验、敏感列禁写、审计 target_id 超长修复
59 lines
2.7 KiB
TypeScript
59 lines
2.7 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
||
import { join } from 'node:path';
|
||
import { describe, expect, it } from 'vitest';
|
||
|
||
/**
|
||
* DATA-7(2026-10-19 T4):租户核心 FK 收口契约。
|
||
* 真实库由只读查询验证(22/22/22、br001↔br002 差集空、有孤儿保持 NOT VALID)。
|
||
*/
|
||
|
||
const sql = readFileSync(
|
||
join(__dirname, '../../migrations/20261062_tenant_core_foreign_keys_drift.sql'),
|
||
'utf8'
|
||
);
|
||
|
||
const EXPECTED_NEW_FKS: Array<[string, string, string]> = [
|
||
['after_sale_returns', 'after_sale_id', 'after_sales'],
|
||
['assistant_messages', 'conversation_id', 'assistant_conversations'],
|
||
['assistant_turns', 'conversation_id', 'assistant_conversations'],
|
||
['bid_awards', 'quote_id', 'bid_quotes'],
|
||
['bid_awards', 'round_id', 'bid_rounds'],
|
||
['bid_invitations', 'round_id', 'bid_rounds'],
|
||
['bid_quotes', 'invitation_id', 'bid_invitations'],
|
||
['bid_quotes', 'round_id', 'bid_rounds'],
|
||
['bid_round_items', 'round_id', 'bid_rounds'],
|
||
['free_cost_invoice_links', 'cost_detail_id', 'cost_details'],
|
||
['free_cost_invoice_links', 'invoice_id', 'free_cost_invoices'],
|
||
['inspection_photo_archive_entries', 'archive_id', 'inspection_photo_archives'],
|
||
['invoice_statement_links', 'invoice_id', 'invoices'],
|
||
['parse_session_items', 'parse_session_id', 'parse_sessions'],
|
||
['processing_demand_items', 'task_id', 'processing_tasks'],
|
||
['processing_demand_picks', 'task_id', 'processing_tasks'],
|
||
['quality_report_prep_links', 'preparation_id', 'supplier_preparations'],
|
||
['quality_report_prep_links', 'quality_report_id', 'quality_reports'],
|
||
['self_purchase_stock_inbounds', 'sku_code', 'skus'],
|
||
];
|
||
|
||
describe('DATA-7:FK 迁移契约', () => {
|
||
it('19 条新 FK 全部以 NOT VALID 加入(子表/列/父表一致)', () => {
|
||
for (const [child, col, parent] of EXPECTED_NEW_FKS) {
|
||
expect(sql, `${child}.${col}->${parent}`).toContain(`('${child}','${col}','${parent}'`);
|
||
}
|
||
// 19 条走同一段动态 SQL('... %s NOT VALID');3 条原有 FK 是字面量,合计至少 4 处
|
||
expect(sql.match(/NOT VALID/g)?.length || 0).toBeGreaterThanOrEqual(4);
|
||
expect(sql).toContain("CASE WHEN v_on_delete IS NULL THEN '' ELSE ' ON DELETE ' || v_on_delete END");
|
||
});
|
||
|
||
it('保留条件 VALIDATE:孤儿=0 才 VALIDATE,否则 NOT VALID + 告警', () => {
|
||
expect(sql).toContain('VALIDATE CONSTRAINT');
|
||
expect(sql).toContain('NOT VALIDATED');
|
||
expect(sql).toContain('NOT c.convalidated');
|
||
});
|
||
|
||
it('对模板 + 已注册租户应用(幂等,不删数据)', () => {
|
||
expect(sql).toContain("ensure_tenant_core_foreign_keys('tenant_template')");
|
||
expect(sql).toContain('FROM public.tenant_schema_registry');
|
||
expect(sql).not.toMatch(/DELETE\s+FROM/i);
|
||
});
|
||
});
|