feat(db): add production migration chain

This commit is contained in:
2026-09-28 15:39:15 +08:00
parent 7a4486b1bc
commit 08bf8f9a5a
8 changed files with 631 additions and 5 deletions
@@ -0,0 +1,18 @@
-- Region: OVERSEAS
-- Schema: baiyue_lastlag_warehouse
-- Purpose: 移除已退役的库位 zone_code,并重建不含 zone_code 的查询索引。
-- Preconditions: 连接必须指向 baiyue_lastlag_warehouse;生产执行前必须单独授权 DROP COLUMN,并确认 zone_code 无外部读写依赖。
-- Postconditions: wh_location 不再有 zone_code,idx_location_query 为 (customer_id, warehouse_id, status, deleted)。
-- Safety: DROP COLUMN zone_code 是有意的破坏性结构变更;本文件只声明迁移,不执行生产授权或数据清理。
SET NAMES utf8mb4;
SET @ddl = IF(EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = 'wh_location' AND index_name = 'idx_location_query'),
'ALTER TABLE wh_location DROP INDEX idx_location_query', 'SELECT 1');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @ddl = IF(EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'wh_location' AND column_name = 'zone_code'),
'ALTER TABLE wh_location DROP COLUMN zone_code', 'SELECT 1');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @ddl = IF(NOT EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = 'wh_location' AND index_name = 'idx_location_query'),
'ALTER TABLE wh_location ADD KEY idx_location_query (customer_id, warehouse_id, status, deleted)', 'SELECT 1');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
@@ -0,0 +1,14 @@
-- Region: OVERSEAS
-- Schema: baiyue_lastleg
-- Purpose: 允许同一尾程订单建立多个换标申请,并保留订单查询索引。
-- Preconditions: 连接必须指向 baiyue_lastleg;执行前确认旧唯一索引不再是业务约束。
-- Postconditions: ll_relabel_application.lastleg_order_id 不再受唯一索引限制,普通查询索引存在。
SET NAMES utf8mb4;
SET @ddl = IF(EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = 'll_relabel_application' AND index_name = 'uk_ll_relabel_application_order'),
'ALTER TABLE ll_relabel_application DROP INDEX uk_ll_relabel_application_order', 'SELECT 1');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @ddl = IF(NOT EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = 'll_relabel_application' AND index_name = 'idx_ll_relabel_application_order'),
'ALTER TABLE ll_relabel_application ADD KEY idx_ll_relabel_application_order (lastleg_order_id)', 'SELECT 1');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;