This commit is contained in:
2026-09-03 15:35:26 +08:00
parent 6eff5a4b9b
commit 36d35276b7
10 changed files with 307 additions and 123 deletions
@@ -2541,6 +2541,7 @@ CREATE TABLE IF NOT EXISTS fl_inbound_order (
KEY idx_inbound_arrival (tenant_id, expected_arrival_at),
KEY idx_inbound_destination (tenant_id, destination_code, created_at),
KEY idx_inbound_channel (tenant_id, channel_code, created_at),
KEY idx_inbound_smart_loading (warehouse_id, process_status, channel_code, expected_arrival_at, id),
CONSTRAINT fk_inbound_task FOREIGN KEY (task_id) REFERENCES fl_fulfillment_task (id)
) ENGINE=InnoDB COMMENT='二期头程入库单聚合根和列表查询快照';
@@ -2721,6 +2722,7 @@ CREATE TABLE IF NOT EXISTS fl_inbound_measurement (
PRIMARY KEY (id),
UNIQUE KEY uk_measure_external_event (tenant_id, source_code, external_event_no),
KEY idx_measure_inbound_time (tenant_id, inbound_id, created_at),
KEY idx_measure_inbound_status_id (tenant_id, inbound_id, status, id),
CONSTRAINT fk_measure_inbound FOREIGN KEY (inbound_id) REFERENCES fl_inbound_order (id)
) ENGINE=InnoDB COMMENT='入库长宽高测量批次和第三方原始数据';
@@ -2763,6 +2765,7 @@ CREATE TABLE IF NOT EXISTS fl_inbound_measurement_item (
UNIQUE KEY uk_measure_item_no (tenant_id, measurement_id, item_no),
UNIQUE KEY uk_measure_external_detail (tenant_id, inbound_detail_id, external_detail_no),
UNIQUE KEY uk_measure_box_code (tenant_id, box_code),
KEY idx_measure_item_candidate (tenant_id, measurement_id, inbound_detail_id),
CONSTRAINT fk_measure_item_batch FOREIGN KEY (measurement_id) REFERENCES fl_inbound_measurement (id)
) ENGINE=InnoDB COMMENT='入库长宽高和箱数测量明细';
@@ -5136,6 +5139,7 @@ CREATE TABLE IF NOT EXISTS fl_loading_plan_item (
KEY idx_loading_item_plan (loading_plan_id, deleted, load_sequence, id),
KEY idx_loading_item_account (account_id, created_at, id),
KEY idx_loading_item_inbound (account_id, inbound_id, deleted),
KEY idx_loading_item_candidate (account_id, inbound_id, inbound_detail_id, deleted),
KEY idx_loading_item_order (account_id, order_id, deleted),
CONSTRAINT fk_loading_item_plan FOREIGN KEY (loading_plan_id) REFERENCES fl_loading_plan (id),
CONSTRAINT chk_loading_item_account CHECK (account_id > 0),
@@ -8455,6 +8459,7 @@ CREATE TABLE IF NOT EXISTS fl_inbound_split_item (
UNIQUE KEY uk_inbound_split_batch_line (tenant_id, split_batch_id, line_no),
UNIQUE KEY uk_inbound_split_batch_source_child (tenant_id, split_batch_id, source_measurement_item_id, child_inbound_id),
KEY idx_inbound_split_detail (tenant_id, source_inbound_detail_id, created_at),
KEY idx_inbound_split_candidate (tenant_id, parent_inbound_id, source_inbound_detail_id),
CONSTRAINT chk_inbound_split_item_package CHECK (package_count > 0),
CONSTRAINT fk_inbound_split_item_batch FOREIGN KEY (split_batch_id) REFERENCES fl_inbound_split_batch (id),
CONSTRAINT fk_inbound_split_item_parent FOREIGN KEY (parent_inbound_id) REFERENCES fl_inbound_order (id),
@@ -16756,6 +16761,40 @@ DROP PROCEDURE IF EXISTS queue_table_comment;
DROP TEMPORARY TABLE IF EXISTS tmp_column_comment_target;
DROP TEMPORARY TABLE IF EXISTS tmp_table_comment_target;
DROP PROCEDURE IF EXISTS baiyue_firstleg.ensure_smart_loading_candidate_indexes;
DELIMITER $$
CREATE PROCEDURE baiyue_firstleg.ensure_smart_loading_candidate_indexes()
BEGIN
IF NOT EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema='baiyue_firstleg'
AND table_name='fl_inbound_order' AND index_name='idx_inbound_smart_loading') THEN
ALTER TABLE baiyue_firstleg.fl_inbound_order
ADD KEY idx_inbound_smart_loading (warehouse_id,process_status,channel_code,expected_arrival_at,id);
END IF;
IF NOT EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema='baiyue_firstleg'
AND table_name='fl_inbound_measurement' AND index_name='idx_measure_inbound_status_id') THEN
ALTER TABLE baiyue_firstleg.fl_inbound_measurement
ADD KEY idx_measure_inbound_status_id (tenant_id,inbound_id,status,id);
END IF;
IF NOT EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema='baiyue_firstleg'
AND table_name='fl_inbound_measurement_item' AND index_name='idx_measure_item_candidate') THEN
ALTER TABLE baiyue_firstleg.fl_inbound_measurement_item
ADD KEY idx_measure_item_candidate (tenant_id,measurement_id,inbound_detail_id);
END IF;
IF NOT EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema='baiyue_firstleg'
AND table_name='fl_loading_plan_item' AND index_name='idx_loading_item_candidate') THEN
ALTER TABLE baiyue_firstleg.fl_loading_plan_item
ADD KEY idx_loading_item_candidate (account_id,inbound_id,inbound_detail_id,deleted);
END IF;
IF NOT EXISTS (SELECT 1 FROM information_schema.statistics WHERE table_schema='baiyue_firstleg'
AND table_name='fl_inbound_split_item' AND index_name='idx_inbound_split_candidate') THEN
ALTER TABLE baiyue_firstleg.fl_inbound_split_item
ADD KEY idx_inbound_split_candidate (tenant_id,parent_inbound_id,source_inbound_detail_id);
END IF;
END$$
DELIMITER ;
CALL baiyue_firstleg.ensure_smart_loading_candidate_indexes();
DROP PROCEDURE IF EXISTS baiyue_firstleg.ensure_smart_loading_candidate_indexes;
CALL baiyue_firstleg.assert_unified_final_schema();
DROP PROCEDURE IF EXISTS baiyue_firstleg.assert_unified_final_schema;
SELECT 'PASS' AS migration_status,