优化
This commit is contained in:
@@ -6,6 +6,59 @@ import { fileURLToPath } from 'node:url'
|
||||
import { buildPlan, loadScopes } from '../deploy/sql/scripts/db-migrations.mjs'
|
||||
|
||||
const repositoryRoot = path.resolve(fileURLToPath(new URL('..', import.meta.url)))
|
||||
|
||||
const overseasFeeStructurePath = 'deploy/sql/overseas-fees-storage-rent-structure-add.sql'
|
||||
const readSql = relative => readFile(path.join(repositoryRoot, relative), 'utf8')
|
||||
const withoutSqlComments = source => source.replace(/^\s*--.*$/gm, '')
|
||||
|
||||
test('海外费用结构补齐只修改已核准的表字段,不包含业务数据写入', async () => {
|
||||
const source = withoutSqlComments(await readSql(overseasFeeStructurePath))
|
||||
assert.match(source, /USE baiyue_lastleg;/)
|
||||
assert.doesNotMatch(source, /\b(?:INSERT|UPDATE|DELETE|REPLACE|TRUNCATE)\b/i)
|
||||
assert.doesNotMatch(source, /\bDROP\s+(?:TABLE|DATABASE|COLUMN|INDEX)\b/i)
|
||||
assert.deepEqual([...source.matchAll(/^\s*ALTER TABLE\s+(\w+)/gim)].map(match => match[1]), ['ll_finance_fee_source'])
|
||||
assert.deepEqual([...source.matchAll(/^\s*CREATE TABLE\s+(\w+)/gim)].map(match => match[1]), ['ll_storage_rent_inbound'])
|
||||
assert.match(source, /ADD COLUMN reviewer_name VARCHAR\(255\) NULL COMMENT '审核人名称快照' AFTER reviewer_id;/)
|
||||
})
|
||||
|
||||
test('海外费用计租实收表与两份正式基线完全一致', async () => {
|
||||
const files = [overseasFeeStructurePath, 'lastleg-service/src/main/resources/db/lastleg.sql', 'deploy/sql/海外区域统一增量-MySQL8.sql']
|
||||
const definitions = await Promise.all(files.map(async file => {
|
||||
const source = await readSql(file)
|
||||
const definition = source.match(/CREATE TABLE(?: IF NOT EXISTS)? ll_storage_rent_inbound\s*\([\s\S]*?\) ENGINE=[^;]+;/)?.[0]
|
||||
assert.ok(definition, file)
|
||||
assert.ok(/reviewer_name\s+VARCHAR\(255\)\s+(?:COLLATE\s+\w+\s+)?(?:DEFAULT\s+)?NULL\s+COMMENT '审核人名称快照'/i.test(source), `${file} 审核人名称须为可空 VARCHAR(255)`)
|
||||
return definition.replace(' IF NOT EXISTS', '').replace(/\s+/g, ' ').toLowerCase()
|
||||
}))
|
||||
assert.equal(definitions[0], definitions[1])
|
||||
assert.equal(definitions[0], definitions[2])
|
||||
})
|
||||
|
||||
test('海外费用结构补齐先检查同名结构再修改,支持匹配结构重跑', async () => {
|
||||
const source = withoutSqlComments(await readSql(overseasFeeStructurePath))
|
||||
const firstDdl = source.indexOf('ALTER TABLE ll_finance_fee_source')
|
||||
assert.ok(firstDdl > 0)
|
||||
const guards = source.slice(0, firstDdl)
|
||||
for (const marker of ["DATABASE()<>'baiyue_lastleg'", 'reviewer_exists>0', 'inbound_exists>0', "TABLE_COLLATION='utf8mb4_unicode_ci'", "COLUMN_TYPE='decimal(24,12)'", "COLUMN_TYPE='datetime(3)'", "INDEX_NAME='PRIMARY'", "INDEX_NAME='idx_storage_rent_inbound_lot'"]) {
|
||||
assert.ok(guards.includes(marker), marker)
|
||||
}
|
||||
assert.match(guards, /SIGNAL SQLSTATE '45000'/)
|
||||
assert.match(source, /IF reviewer_exists=0 THEN\s+ALTER TABLE/)
|
||||
assert.match(source, /IF inbound_exists=0 THEN\s+CREATE TABLE/)
|
||||
assert.match(source, /CALL overseas_fee_rent_structure_add_20261026\(\);[\s\S]+SHOW CREATE TABLE ll_storage_rent_inbound;[\s\S]+'TABLE_COLUMN_READY'/)
|
||||
})
|
||||
|
||||
test('海外费用免费仓租修复只放行自动应收双零,保留其他费用及汇率边界', async () => {
|
||||
const repair = await readSql('deploy/sql/overseas-storage-rent-zero-fee-repair.sql')
|
||||
const normalized = repair.replaceAll("''", "'")
|
||||
const autoZero = "amount=0 AND original_amount=0 AND created_by='STORAGE_RENT' AND fee_item_code='FEE_TYPE_077' AND direction='RECEIVABLE'"
|
||||
assert.ok(normalized.includes(`CHECK(amount>0 OR (${autoZero}))`))
|
||||
assert.ok(normalized.includes(`CHECK((exchange_rate IS NOT NULL AND exchange_rate>0) OR (exchange_rate IS NULL AND ${autoZero}))`))
|
||||
assert.match(repair, /SELECT COLUMN_TYPE,COLUMN_COMMENT,COLUMN_DEFAULT INTO rate_type,rate_comment,rate_default/)
|
||||
assert.match(repair, /rate_default IS NOT NULL AND rate_default NOT REGEXP/)
|
||||
assert.doesNotMatch(withoutSqlComments(repair), /^\s*(?:INSERT|UPDATE|DELETE|REPLACE|TRUNCATE)\b/im)
|
||||
})
|
||||
|
||||
const migrations = {
|
||||
iam: 'deploy/sql/migrations/cn/baiyue_iam/V1__align_schema_baseline.sql',
|
||||
iamForwardFix: 'deploy/sql/migrations/cn/baiyue_iam/V3__align_domestic_pda_mojia_sailing_permissions.sql',
|
||||
|
||||
Reference in New Issue
Block a user