From b79d136925d846dc07e5fd4a740c5ed303e9ff83 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Fri, 4 Sep 2026 14:04:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/sql/头程数据库统一增量-MySQL8.sql | 20 +++++++++++++++---- .../resources/db/phase2-inbound-schema.sql | 2 +- .../PdaSplitSettlementSqlContractTest.java | 15 ++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/deploy/sql/头程数据库统一增量-MySQL8.sql b/deploy/sql/头程数据库统一增量-MySQL8.sql index 5c72c4995..5f35a3b51 100644 --- a/deploy/sql/头程数据库统一增量-MySQL8.sql +++ b/deploy/sql/头程数据库统一增量-MySQL8.sql @@ -3162,7 +3162,7 @@ CREATE TABLE IF NOT EXISTS fl_inbound_pallet_allocation ( updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间', PRIMARY KEY (id), UNIQUE KEY uk_pallet_allocation_no (tenant_id, inbound_id, allocation_no), - UNIQUE KEY uk_pallet_allocation_slot (tenant_id, block_id, slot_no), + UNIQUE KEY uk_pallet_allocation_slot (tenant_id, inbound_id, block_id, slot_no), UNIQUE KEY uk_pallet_allocation_weight (tenant_id, weight_result_id), KEY idx_allocation_location (tenant_id, warehouse_id, location_id, allocation_status), KEY idx_allocation_reservation (reservation_id), @@ -10248,9 +10248,16 @@ SET @sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema=DATABASE() AND table_name='fl_inbound_pallet_allocation' AND column_name='reservation_no') > 0, 'ALTER TABLE fl_inbound_pallet_allocation DROP COLUMN reservation_no', 'SELECT 1'); PREPARE statement FROM @sql; EXECUTE statement; DEALLOCATE PREPARE statement; -SET @sql = IF((SELECT COUNT(*) FROM information_schema.statistics - WHERE table_schema=DATABASE() AND table_name='fl_inbound_pallet_allocation' AND index_name='uk_pallet_allocation_slot') = 0, - 'ALTER TABLE fl_inbound_pallet_allocation ADD UNIQUE KEY uk_pallet_allocation_slot (tenant_id,block_id,slot_no)', 'SELECT 1'); +SET @sql = IF((SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index) + FROM information_schema.statistics + WHERE table_schema=DATABASE() AND table_name='fl_inbound_pallet_allocation' + AND index_name='uk_pallet_allocation_slot') <> 'tenant_id,inbound_id,block_id,slot_no', + 'ALTER TABLE fl_inbound_pallet_allocation DROP INDEX uk_pallet_allocation_slot, ADD UNIQUE KEY uk_pallet_allocation_slot (tenant_id,inbound_id,block_id,slot_no)', + IF((SELECT COUNT(*) FROM information_schema.statistics + WHERE table_schema=DATABASE() AND table_name='fl_inbound_pallet_allocation' + AND index_name='uk_pallet_allocation_slot') = 0, + 'ALTER TABLE fl_inbound_pallet_allocation ADD UNIQUE KEY uk_pallet_allocation_slot (tenant_id,inbound_id,block_id,slot_no)', + 'SELECT 1')); PREPARE statement FROM @sql; EXECUTE statement; DEALLOCATE PREPARE statement; SET @sql = IF((SELECT COUNT(*) FROM information_schema.statistics WHERE table_schema=DATABASE() AND table_name='fl_inbound_pallet_allocation' AND index_name='uk_pallet_allocation_weight') = 0, @@ -15005,6 +15012,11 @@ BEGIN AND table_name = 'fl_inbound_pallet_allocation' AND column_name IN ('pallet_id','pallet_code','pallet_capacity_cbm') AND is_nullable = 'YES') <> 3 + OR (SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index) + FROM information_schema.statistics + WHERE table_schema = 'baiyue_firstleg' + AND table_name = 'fl_inbound_pallet_allocation' + AND index_name = 'uk_pallet_allocation_slot') <> 'tenant_id,inbound_id,block_id,slot_no' OR (SELECT COUNT(DISTINCT index_name) FROM information_schema.statistics WHERE table_schema = 'baiyue_firstleg' AND table_name = 'fl_inbound_pallet_allocation' diff --git a/firstleg/src/main/resources/db/phase2-inbound-schema.sql b/firstleg/src/main/resources/db/phase2-inbound-schema.sql index faed9ff13..53320af37 100644 --- a/firstleg/src/main/resources/db/phase2-inbound-schema.sql +++ b/firstleg/src/main/resources/db/phase2-inbound-schema.sql @@ -735,7 +735,7 @@ CREATE TABLE IF NOT EXISTS fl_inbound_pallet_allocation ( updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间', PRIMARY KEY (id), UNIQUE KEY uk_pallet_allocation_no (tenant_id, inbound_id, allocation_no), - UNIQUE KEY uk_pallet_allocation_slot (tenant_id, block_id, slot_no), + UNIQUE KEY uk_pallet_allocation_slot (tenant_id, inbound_id, block_id, slot_no), UNIQUE KEY uk_pallet_allocation_weight (tenant_id, weight_result_id), KEY idx_allocation_location (tenant_id, warehouse_id, location_id, allocation_status), KEY idx_allocation_reservation (reservation_id), diff --git a/firstleg/src/test/java/com/baiyue/firstleg/repository/PdaSplitSettlementSqlContractTest.java b/firstleg/src/test/java/com/baiyue/firstleg/repository/PdaSplitSettlementSqlContractTest.java index 08e2d4f21..f6b1b3f0b 100644 --- a/firstleg/src/test/java/com/baiyue/firstleg/repository/PdaSplitSettlementSqlContractTest.java +++ b/firstleg/src/test/java/com/baiyue/firstleg/repository/PdaSplitSettlementSqlContractTest.java @@ -175,4 +175,19 @@ class PdaSplitSettlementSqlContractTest { .contains("block_id=#{blockId}") .contains("allocation_status='CONFIRMED'"); } + + @Test + void allowsTransferredSourceAndRemainderChildToKeepTheSameBlockSlotIdentity() throws Exception { + String moduleSql = new ClassPathResource("db/phase2-inbound-schema.sql") + .getContentAsString(StandardCharsets.UTF_8); + String unifiedSql = Files.readString(Path.of("..", "deploy", "sql", "头程数据库统一增量-MySQL8.sql"), + StandardCharsets.UTF_8); + + assertThat(moduleSql) + .contains("UNIQUE KEY uk_pallet_allocation_slot (tenant_id, inbound_id, block_id, slot_no)") + .doesNotContain("UNIQUE KEY uk_pallet_allocation_slot (tenant_id, block_id, slot_no)"); + assertThat(unifiedSql) + .contains("'tenant_id,inbound_id,block_id,slot_no'") + .contains("ADD UNIQUE KEY uk_pallet_allocation_slot (tenant_id,inbound_id,block_id,slot_no)"); + } }