chore(db): 成本中心迁移重编号到 main 之后(103–106),check:sql 允许纯重编号

This commit is contained in:
yml2213
2026-10-22 12:42:59 +08:00
parent 3e73289e31
commit 8f3babdabe
8 changed files with 26 additions and 10 deletions
+16
View File
@@ -118,6 +118,7 @@ try {
.flatMap((output) => output.split('\n'))
.map((line) => line.trim().split(/\s+/))
.filter(([status, file]) => status && file?.endsWith('.sql') && status !== 'A')
.filter(([status, file, renamedTo]) => !isMigrationRenumber(status, file, renamedTo))
.map(([status, file]) => `${status} ${file}`)
.filter((change) => !allowedHistoricalMigrationChanges.has(change))
if (changedHistoricalMigrations.length > 0) {
@@ -127,6 +128,21 @@ try {
failures.push(`历史迁移完整性检查失败: ${error instanceof Error ? error.message : String(error)}`)
}
// 分支合流后把尚未上线的迁移顺延到主线版本号之后时,只允许改序号前缀,
// 文件名主体必须完全一致(例:102_product_catalog.sql -> 103_product_catalog.sql)。
function isMigrationRenumber(
status: string | undefined,
renamedFrom: string | undefined,
renamedTo: string | undefined,
) {
if (!status?.startsWith('R') || !renamedFrom || !renamedTo) return false
return stripMigrationPrefix(renamedFrom) === stripMigrationPrefix(renamedTo)
}
function stripMigrationPrefix(filePath: string) {
return path.basename(filePath).replace(/^\d{3}_/, '')
}
for (const check of checks) {
if (!fs.existsSync(check.file)) {
failures.push(`${check.name}: 文件不存在 ${check.file}`)
@@ -1,4 +1,4 @@
-- 102_product_catalog.sql —— 标准商品主数据 + 渠道 SKU 映射。
-- 103_product_catalog.sql —— 标准商品主数据 + 渠道 SKU 映射。
--
-- 目标:把「平台原始 SKU / 商品名」归一到内部标准商品,后续成本、销量、
-- 店铺日报和订单毛利都只认 canonical_product_id。
@@ -1,4 +1,4 @@
-- 103_cost_center.sql —— 成本项目、成本版本、成本快照与成本异常。
-- 104_cost_center.sql —— 成本项目、成本版本、成本快照与成本异常。
--
-- 目标:所有成本金额只在 cost_versions 维护;订单项/工单/人工单只保存
-- cost_snapshot_id 或快照行,历史成本永不回写。
@@ -1,7 +1,7 @@
-- 104_cost_center_bootstrap_fix.sql
-- 105_cost_center_bootstrap_fix.sql
--
-- 背景:
-- 102_product_catalog 已执行,里面把 normalized_quantity 直接用 quantity 填充。
-- 103_product_catalog 已执行,里面把 normalized_quantity 直接用 quantity 填充。
-- quantity 长期几乎恒为 1,会让「5个」类 SKU 的归一数量永远无法再通过解析器修正。
--
-- 处理:
@@ -1,4 +1,4 @@
-- 105_product_mapping_match_keys.sql —— 渠道商品映射支持 SKU 名称/系列消歧。
-- 106_product_mapping_match_keys.sql —— 渠道商品映射支持 SKU 名称/系列消歧。
--
-- 背景:91 的 sku_code 会在同一店铺内被多个商品复用,单靠
-- provider + shop_id + platform_sku_code 无法唯一确定标准商品。
@@ -5,8 +5,8 @@
-- 依赖:本文引用 product_catalog / cost_items / cost_snapshots / manual_expenses,
-- 必须**在** `2026-10-17-成本中心与销售事实-DDL草案.sql` **之后**应用;
-- `manual_expenses` 已由迁移 100 创建(客服备用金支出)。
-- 当前已使用迁移 100/101;成本中心草案拆为 102–104,本文建议顺延为
-- `105_manual_cases.sql`、`106_manual_expenses.sql`,接入时按实际最大号调整并先跑 `npm run check:sql`。
-- 当前已使用迁移至 106(成本中心落在 103–106);本文建议顺延为
-- `107_manual_cases.sql`、`108_manual_expenses.sql`,接入时按实际最大号调整并先跑 `npm run check:sql`。
-- 基线:main @ 7542d547;依据:2026-10-17 业务口径确认 + 2026-10-18 备用金落地复核。
--
-- 重要命名边界:
@@ -1,8 +1,8 @@
-- ============================================================================
-- 通用成本中心 + 标准商品 + 销售事实(建表草案)
-- ----------------------------------------------------------------------------
-- 状态:部分落地。商品主数据 + 渠道映射 + 成本中心已接入 `102_product_catalog.sql`、
-- `103_cost_center.sql`、`104_cost_center_bootstrap_fix.sql`;本文件仅保留设计追溯。
-- 状态:部分落地。商品主数据 + 渠道映射 + 成本中心已接入 `103_product_catalog.sql`、
-- `104_cost_center.sql`、`105_cost_center_bootstrap_fix.sql`;本文件仅保留设计追溯。
-- 尚未实施的 `sales_daily_facts` 等后续内容,接入时从新迁移号继续,并先跑 `npm run check:sql`。
-- 基线:main @ 7542d547;数据依据:本地只读克隆(生产快照,orders 316,597,数据截至 2026-10-14)。
-- 金额单位:分(BIGINT)。本文件所有 *_fen 列均为分。
@@ -2,7 +2,7 @@
-- 载体判定与人工块量化(只读量化 + 回填草案)
-- ----------------------------------------------------------------------------
-- 状态:草案(DRAFT)。**未接入** apps/backend/src/db/migrations。
-- 当前已使用迁移 100/101;接入时按当前最大迁移号顺延,不占用 100/101,并先跑 `npm run check:sql`。
-- 当前已使用迁移至 106;接入时按当前最大迁移号顺延,并先跑 `npm run check:sql`。
-- 基线:main @ 7542d547;数据来源 = 本地只读克隆(生产快照,orders 316,597,数据截至 2026-10-14 14:52)
-- 金额单位:分(BIGINT)。orders.total_amount / work_orders.reward_amount / source_order_amount_fen 均为分。
-- 口径基准:§1 所有查询以「已支付订单项」为单位;人工块 = 既无 fulfillment_tasks 也无 work_orders。