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

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,139 @@
-- 测试数据批次隔离:PostgreSQL 增量补丁
-- 本补丁仅增加可空归属字段,不回填既有数据。
CREATE TABLE biz_test_batch (
batch_id BIGSERIAL NOT NULL,
batch_code VARCHAR(64) NOT NULL,
batch_name VARCHAR(100) NOT NULL,
status VARCHAR(16) NOT NULL DEFAULT 'ACTIVE',
create_by VARCHAR(64) NOT NULL DEFAULT '',
create_time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
update_by VARCHAR(64) NOT NULL DEFAULT '',
update_time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
closed_by BIGINT NULL,
closed_at TIMESTAMP WITHOUT TIME ZONE NULL,
purged_by BIGINT NULL,
purged_at TIMESTAMP WITHOUT TIME ZONE NULL,
purge_summary TEXT NULL,
preview_action VARCHAR(16) NULL,
preview_token_hash CHAR(64) NULL,
preview_scope_hash CHAR(64) NULL,
preview_expires_at TIMESTAMP WITHOUT TIME ZONE NULL,
remark VARCHAR(500) NULL,
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)
);
COMMENT ON TABLE biz_test_batch IS '测试数据批次';
CREATE TABLE biz_test_batch_user (
batch_id BIGINT NOT NULL,
user_id BIGINT NOT NULL,
create_by VARCHAR(64) NOT NULL DEFAULT '',
create_time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
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)
);
COMMENT ON TABLE biz_test_batch_user IS '测试数据批次与用户关联';
ALTER TABLE biz_strain ADD COLUMN test_batch_id BIGINT NULL;
COMMENT ON COLUMN biz_strain.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_strain_test_batch_id ON biz_strain (test_batch_id);
ALTER TABLE biz_strain 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 ON COLUMN biz_customer.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_customer_test_batch_id ON biz_customer (test_batch_id);
ALTER TABLE biz_customer 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 ON COLUMN biz_customer_site.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_customer_site_test_batch_id ON biz_customer_site (test_batch_id);
ALTER TABLE biz_customer_site 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 ON COLUMN biz_production_line.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_production_line_test_batch_id ON biz_production_line (test_batch_id);
ALTER TABLE biz_production_line 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 ON COLUMN biz_warehouse.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_warehouse_test_batch_id ON biz_warehouse (test_batch_id);
ALTER TABLE biz_warehouse 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 ON COLUMN biz_pallet.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_pallet_test_batch_id ON biz_pallet (test_batch_id);
ALTER TABLE biz_pallet 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 ON COLUMN biz_inbound_order.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_inbound_order_test_batch_id ON biz_inbound_order (test_batch_id);
ALTER TABLE biz_inbound_order 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 ON COLUMN biz_inbound_item.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_inbound_item_test_batch_id ON biz_inbound_item (test_batch_id);
ALTER TABLE biz_inbound_item 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 ON COLUMN biz_filling_record.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_filling_record_test_batch_id ON biz_filling_record (test_batch_id);
ALTER TABLE biz_filling_record 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 ON COLUMN biz_shipment_order.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_shipment_order_test_batch_id ON biz_shipment_order (test_batch_id);
ALTER TABLE biz_shipment_order 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 ON COLUMN biz_shipment_item.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_shipment_item_test_batch_id ON biz_shipment_item (test_batch_id);
ALTER TABLE biz_shipment_item 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 ON COLUMN biz_usage_record.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_usage_record_test_batch_id ON biz_usage_record (test_batch_id);
ALTER TABLE biz_usage_record 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 ON COLUMN biz_return_order.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_return_order_test_batch_id ON biz_return_order (test_batch_id);
ALTER TABLE biz_return_order 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 ON COLUMN biz_return_item.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_return_item_test_batch_id ON biz_return_item (test_batch_id);
ALTER TABLE biz_return_item 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 ON COLUMN biz_pallet_inventory.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_pallet_inventory_test_batch_id ON biz_pallet_inventory (test_batch_id);
ALTER TABLE biz_pallet_inventory 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 ON COLUMN biz_pallet_event.test_batch_id IS '测试数据批次ID;NULL表示正式数据';
CREATE INDEX idx_biz_pallet_event_test_batch_id ON biz_pallet_event (test_batch_id);
ALTER TABLE biz_pallet_event ADD CONSTRAINT fk_biz_pallet_event_test_batch_id
FOREIGN KEY (test_batch_id) REFERENCES biz_test_batch (batch_id);