数据:增加测试批次模型与迁移契约

This commit is contained in:
焦龙言
2026-09-22 14:37:31 +08:00
parent 40c56c6b33
commit 17bfa2c5fe
12 changed files with 1278 additions and 32 deletions
@@ -0,0 +1,137 @@
-- 测试数据批次隔离:MySQL 增量补丁
-- 本补丁仅增加可空归属字段,不回填既有数据。
CREATE TABLE biz_test_batch (
batch_id BIGINT NOT NULL AUTO_INCREMENT COMMENT '测试数据批次ID',
batch_code VARCHAR(64) NOT NULL COMMENT '批次编码',
batch_name VARCHAR(100) NOT NULL COMMENT '批次名称',
status VARCHAR(16) NOT NULL DEFAULT 'ACTIVE' COMMENT '批次状态',
create_by VARCHAR(64) NOT NULL DEFAULT '' COMMENT '创建者',
create_time DATETIME NOT NULL COMMENT '创建时间',
update_by VARCHAR(64) NOT NULL DEFAULT '' COMMENT '更新者',
update_time DATETIME NOT NULL COMMENT '更新时间',
closed_by BIGINT NULL COMMENT '关闭人ID',
closed_at DATETIME NULL COMMENT '关闭时间',
purged_by BIGINT NULL COMMENT '清理人ID',
purged_at DATETIME NULL COMMENT '清理时间',
purge_summary TEXT NULL COMMENT '清理摘要JSON',
preview_action VARCHAR(16) NULL COMMENT '预览动作',
preview_token_hash CHAR(64) NULL COMMENT '预览令牌摘要',
preview_scope_hash CHAR(64) NULL COMMENT '预览范围摘要',
preview_expires_at DATETIME NULL COMMENT '预览过期时间',
remark VARCHAR(500) NULL COMMENT '备注',
PRIMARY KEY (batch_id),
CONSTRAINT uq_biz_test_batch_code UNIQUE (batch_code),
CONSTRAINT ck_biz_test_batch_status CHECK (status IN ('ACTIVE', 'CLOSED', 'PURGED')),
CONSTRAINT ck_biz_test_batch_preview_action CHECK (
preview_action IS NULL OR preview_action IN ('ADOPT', 'PURGE')
),
CONSTRAINT fk_biz_test_batch_closed_by FOREIGN KEY (closed_by) REFERENCES sys_user (user_id),
CONSTRAINT fk_biz_test_batch_purged_by FOREIGN KEY (purged_by) REFERENCES sys_user (user_id)
) ENGINE=InnoDB COMMENT='测试数据批次';
CREATE TABLE biz_test_batch_user (
batch_id BIGINT NOT NULL COMMENT '测试数据批次ID',
user_id BIGINT NOT NULL COMMENT '用户ID',
create_by VARCHAR(64) NOT NULL DEFAULT '' COMMENT '创建者',
create_time DATETIME NOT NULL COMMENT '创建时间',
PRIMARY KEY (batch_id, user_id),
CONSTRAINT fk_biz_test_batch_user_batch FOREIGN KEY (batch_id) REFERENCES biz_test_batch (batch_id),
CONSTRAINT fk_biz_test_batch_user_user FOREIGN KEY (user_id) REFERENCES sys_user (user_id)
) ENGINE=InnoDB COMMENT='测试数据批次与用户关联';
ALTER TABLE biz_strain
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_strain_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_strain_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_customer
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_customer_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_customer_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_customer_site
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_customer_site_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_customer_site_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_production_line
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_production_line_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_production_line_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_warehouse
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_warehouse_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_warehouse_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_pallet
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_pallet_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_pallet_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_inbound_order
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_inbound_order_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_inbound_order_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_inbound_item
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_inbound_item_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_inbound_item_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_filling_record
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_filling_record_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_filling_record_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_shipment_order
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_shipment_order_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_shipment_order_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_shipment_item
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_shipment_item_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_shipment_item_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_usage_record
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_usage_record_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_usage_record_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_return_order
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_return_order_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_return_order_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_return_item
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_return_item_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_return_item_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_pallet_inventory
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_pallet_inventory_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_pallet_inventory_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);
ALTER TABLE biz_pallet_event
ADD COLUMN test_batch_id BIGINT NULL COMMENT '测试数据批次ID;NULL表示正式数据',
ADD INDEX idx_biz_pallet_event_test_batch_id (test_batch_id),
ADD CONSTRAINT fk_biz_pallet_event_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);