fix(db): 113 迁移先删旧约束再归一销售事实渠道
This commit is contained in:
@@ -8,10 +8,14 @@ const migration = readFileSync(
|
||||
'utf8',
|
||||
)
|
||||
|
||||
test('113 迁移必须先归一销售事实旧口径,再收紧渠道约束', () => {
|
||||
test('113 迁移必须先删旧约束、再归一销售事实,最后加新约束', () => {
|
||||
const dropIndex = migration.indexOf(
|
||||
'DROP CONSTRAINT IF EXISTS chk_sales_daily_facts_fulfillment_mode',
|
||||
)
|
||||
const updateIndex = migration.indexOf('UPDATE sales_daily_facts')
|
||||
const constraintIndex = migration.indexOf('ADD CONSTRAINT chk_sales_daily_facts_fulfillment_mode')
|
||||
assert.ok(updateIndex > 0, '缺少 sales_daily_facts 旧口径归一')
|
||||
assert.ok(dropIndex > 0, '缺少旧渠道约束的删除')
|
||||
assert.ok(updateIndex > dropIndex, '必须先删旧约束再归一;否则 archived 会被旧约束拒绝')
|
||||
assert.ok(constraintIndex > updateIndex, '必须先归一数据,再加新约束')
|
||||
assert.ok(
|
||||
migration.includes("WHEN fulfillment_mode = 'legacy_platform' THEN 'archived'"),
|
||||
@@ -32,3 +36,10 @@ test('113 迁移必须先归一销售事实旧口径,再收紧渠道约束', (
|
||||
assert.ok(migration.includes(`'${channel}'`), `新约束必须允许 ${channel}`)
|
||||
}
|
||||
})
|
||||
|
||||
test('113 迁移的异常表旧行 scope_key 必须保证唯一', () => {
|
||||
assert.ok(
|
||||
migration.includes("'|legacy:' || id"),
|
||||
'旧异常行 scope_key 必须拼 id,避免同 reason + subject_id 撞唯一索引',
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user