数据:增加测试批次模型与迁移契约
This commit is contained in:
@@ -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);
|
||||
@@ -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);
|
||||
@@ -19,6 +19,8 @@ drop table if exists biz_customer_site;
|
||||
drop table if exists biz_customer;
|
||||
drop table if exists biz_warehouse;
|
||||
drop table if exists biz_strain;
|
||||
drop table if exists biz_test_batch_user;
|
||||
drop table if exists biz_test_batch;
|
||||
|
||||
-- ----------------------------
|
||||
-- 1、部门表
|
||||
@@ -1076,8 +1078,48 @@ $$ IMMUTABLE STRICT LANGUAGE PLPGSQL;
|
||||
-- ----------------------------
|
||||
-- 20、托盘流转业务表
|
||||
-- ----------------------------
|
||||
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,
|
||||
closed_at timestamp without time zone,
|
||||
purged_by bigint,
|
||||
purged_at timestamp without time zone,
|
||||
purge_summary text,
|
||||
preview_action varchar(16),
|
||||
preview_token_hash char(64),
|
||||
preview_scope_hash char(64),
|
||||
preview_expires_at timestamp without time zone,
|
||||
remark varchar(500),
|
||||
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 '测试数据批次与用户关联';
|
||||
|
||||
create table biz_strain (
|
||||
strain_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
strain_code varchar(64) not null,
|
||||
strain_name varchar(100) not null,
|
||||
status char(1) not null default '0',
|
||||
@@ -1088,11 +1130,13 @@ create table biz_strain (
|
||||
remark varchar(500) default null,
|
||||
primary key (strain_id),
|
||||
constraint uq_biz_strain_code unique (strain_code),
|
||||
constraint fk_biz_strain_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id),
|
||||
constraint ck_biz_strain_status check (status in ('0', '1'))
|
||||
);
|
||||
|
||||
create table biz_warehouse (
|
||||
warehouse_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
warehouse_code varchar(64) not null,
|
||||
warehouse_name varchar(100) not null,
|
||||
address varchar(500),
|
||||
@@ -1104,11 +1148,13 @@ create table biz_warehouse (
|
||||
remark varchar(500) default null,
|
||||
primary key (warehouse_id),
|
||||
constraint uq_biz_warehouse_code unique (warehouse_code),
|
||||
constraint fk_biz_warehouse_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id),
|
||||
constraint ck_biz_warehouse_status check (status in ('0', '1'))
|
||||
);
|
||||
|
||||
create table biz_customer (
|
||||
customer_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
customer_code varchar(64) not null,
|
||||
customer_name varchar(100) not null,
|
||||
status char(1) not null default '0',
|
||||
@@ -1119,11 +1165,13 @@ create table biz_customer (
|
||||
remark varchar(500) default null,
|
||||
primary key (customer_id),
|
||||
constraint uq_biz_customer_code unique (customer_code),
|
||||
constraint fk_biz_customer_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id),
|
||||
constraint ck_biz_customer_status check (status in ('0', '1'))
|
||||
);
|
||||
|
||||
create table biz_customer_site (
|
||||
site_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
customer_id bigint not null,
|
||||
site_code varchar(64) not null,
|
||||
site_name varchar(100) not null,
|
||||
@@ -1136,12 +1184,14 @@ create table biz_customer_site (
|
||||
remark varchar(500) default null,
|
||||
primary key (site_id),
|
||||
constraint uq_biz_customer_site_customer_code unique (customer_id, site_code),
|
||||
constraint fk_biz_customer_site_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id),
|
||||
constraint ck_biz_customer_site_status check (status in ('0', '1')),
|
||||
constraint fk_biz_customer_site_customer foreign key (customer_id) references biz_customer(customer_id)
|
||||
);
|
||||
|
||||
create table biz_production_line (
|
||||
line_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
site_id bigint not null,
|
||||
line_code varchar(64) not null,
|
||||
line_name varchar(100) not null,
|
||||
@@ -1153,12 +1203,14 @@ create table biz_production_line (
|
||||
remark varchar(500) default null,
|
||||
primary key (line_id),
|
||||
constraint uq_biz_production_line_site_code unique (site_id, line_code),
|
||||
constraint fk_biz_production_line_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id),
|
||||
constraint ck_biz_production_line_status check (status in ('0', '1')),
|
||||
constraint fk_biz_production_line_site foreign key (site_id) references biz_customer_site(site_id)
|
||||
);
|
||||
|
||||
create table biz_pallet (
|
||||
pallet_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
pallet_code varchar(64) not null,
|
||||
qr_token varchar(128) not null,
|
||||
capacity_packages integer not null,
|
||||
@@ -1171,6 +1223,7 @@ create table biz_pallet (
|
||||
primary key (pallet_id),
|
||||
constraint uq_biz_pallet_code unique (pallet_code),
|
||||
constraint uq_biz_pallet_qr_token unique (qr_token),
|
||||
constraint fk_biz_pallet_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id),
|
||||
constraint ck_biz_pallet_capacity_packages check (capacity_packages > 0),
|
||||
constraint ck_biz_pallet_asset_status check (asset_status in ('0', '1'))
|
||||
);
|
||||
@@ -1197,6 +1250,7 @@ create table biz_user_site (
|
||||
|
||||
create table biz_inbound_order (
|
||||
inbound_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
inbound_no varchar(64) not null,
|
||||
warehouse_id bigint not null,
|
||||
status varchar(32) not null default 'DRAFT',
|
||||
@@ -1213,12 +1267,14 @@ create table biz_inbound_order (
|
||||
constraint uq_biz_inbound_order_no unique (inbound_no),
|
||||
constraint uq_biz_inbound_order_warehouse_confirm_idempotency unique (warehouse_id, confirm_idempotency_key),
|
||||
constraint ck_biz_inbound_order_status check (status in ('DRAFT', 'CONFIRMED')),
|
||||
constraint fk_biz_inbound_order_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id),
|
||||
constraint fk_biz_inbound_order_warehouse foreign key (warehouse_id) references biz_warehouse(warehouse_id),
|
||||
constraint fk_biz_inbound_order_confirmer foreign key (confirmed_by) references sys_user(user_id)
|
||||
);
|
||||
|
||||
create table biz_inbound_item (
|
||||
inbound_item_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
inbound_id bigint not null,
|
||||
pallet_id bigint not null,
|
||||
create_by varchar(64) default '',
|
||||
@@ -1226,11 +1282,13 @@ create table biz_inbound_item (
|
||||
primary key (inbound_item_id),
|
||||
constraint uq_biz_inbound_item_order_pallet unique (inbound_id, pallet_id),
|
||||
constraint fk_biz_inbound_item_order foreign key (inbound_id) references biz_inbound_order(inbound_id),
|
||||
constraint fk_biz_inbound_item_pallet foreign key (pallet_id) references biz_pallet(pallet_id)
|
||||
constraint fk_biz_inbound_item_pallet foreign key (pallet_id) references biz_pallet(pallet_id),
|
||||
constraint fk_biz_inbound_item_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id)
|
||||
);
|
||||
|
||||
create table biz_filling_record (
|
||||
filling_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
filling_no varchar(64) not null,
|
||||
pallet_id bigint not null,
|
||||
warehouse_id bigint not null,
|
||||
@@ -1260,11 +1318,13 @@ create table biz_filling_record (
|
||||
constraint fk_biz_filling_record_pallet foreign key (pallet_id) references biz_pallet(pallet_id),
|
||||
constraint fk_biz_filling_record_warehouse foreign key (warehouse_id) references biz_warehouse(warehouse_id),
|
||||
constraint fk_biz_filling_record_strain foreign key (strain_id) references biz_strain(strain_id),
|
||||
constraint fk_biz_filling_record_operator foreign key (operator_id) references sys_user(user_id)
|
||||
constraint fk_biz_filling_record_operator foreign key (operator_id) references sys_user(user_id),
|
||||
constraint fk_biz_filling_record_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id)
|
||||
);
|
||||
|
||||
create table biz_shipment_order (
|
||||
shipment_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
shipment_no varchar(64) not null,
|
||||
source_warehouse_id bigint not null,
|
||||
target_site_id bigint not null,
|
||||
@@ -1284,11 +1344,13 @@ create table biz_shipment_order (
|
||||
constraint ck_biz_shipment_order_status check (status in ('DRAFT', 'CONFIRMED')),
|
||||
constraint fk_biz_shipment_order_warehouse foreign key (source_warehouse_id) references biz_warehouse(warehouse_id),
|
||||
constraint fk_biz_shipment_order_site foreign key (target_site_id) references biz_customer_site(site_id),
|
||||
constraint fk_biz_shipment_order_confirmer foreign key (confirmed_by) references sys_user(user_id)
|
||||
constraint fk_biz_shipment_order_confirmer foreign key (confirmed_by) references sys_user(user_id),
|
||||
constraint fk_biz_shipment_order_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id)
|
||||
);
|
||||
|
||||
create table biz_shipment_item (
|
||||
shipment_item_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
shipment_id bigint not null,
|
||||
pallet_id bigint not null,
|
||||
active_filling_id bigint,
|
||||
@@ -1300,11 +1362,13 @@ create table biz_shipment_item (
|
||||
constraint ck_biz_shipment_item_package_qty check (package_qty is null or package_qty > 0),
|
||||
constraint fk_biz_shipment_item_order foreign key (shipment_id) references biz_shipment_order(shipment_id),
|
||||
constraint fk_biz_shipment_item_pallet foreign key (pallet_id) references biz_pallet(pallet_id),
|
||||
constraint fk_biz_shipment_item_filling foreign key (active_filling_id) references biz_filling_record(filling_id)
|
||||
constraint fk_biz_shipment_item_filling foreign key (active_filling_id) references biz_filling_record(filling_id),
|
||||
constraint fk_biz_shipment_item_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id)
|
||||
);
|
||||
|
||||
create table biz_usage_record (
|
||||
usage_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
usage_no varchar(64) not null,
|
||||
pallet_id bigint not null,
|
||||
active_filling_id bigint not null,
|
||||
@@ -1325,11 +1389,13 @@ create table biz_usage_record (
|
||||
constraint fk_biz_usage_record_filling foreign key (active_filling_id) references biz_filling_record(filling_id),
|
||||
constraint fk_biz_usage_record_site foreign key (site_id) references biz_customer_site(site_id),
|
||||
constraint fk_biz_usage_record_line foreign key (line_id) references biz_production_line(line_id),
|
||||
constraint fk_biz_usage_record_operator foreign key (operator_id) references sys_user(user_id)
|
||||
constraint fk_biz_usage_record_operator foreign key (operator_id) references sys_user(user_id),
|
||||
constraint fk_biz_usage_record_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id)
|
||||
);
|
||||
|
||||
create table biz_return_order (
|
||||
return_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
return_no varchar(64) not null,
|
||||
source_site_id bigint not null,
|
||||
target_warehouse_id bigint not null,
|
||||
@@ -1355,11 +1421,13 @@ create table biz_return_order (
|
||||
constraint fk_biz_return_order_site foreign key (source_site_id) references biz_customer_site(site_id),
|
||||
constraint fk_biz_return_order_warehouse foreign key (target_warehouse_id) references biz_warehouse(warehouse_id),
|
||||
constraint fk_biz_return_order_requester foreign key (requested_by) references sys_user(user_id),
|
||||
constraint fk_biz_return_order_confirmer foreign key (confirmed_by) references sys_user(user_id)
|
||||
constraint fk_biz_return_order_confirmer foreign key (confirmed_by) references sys_user(user_id),
|
||||
constraint fk_biz_return_order_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id)
|
||||
);
|
||||
|
||||
create table biz_return_item (
|
||||
return_item_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
return_id bigint not null,
|
||||
pallet_id bigint not null,
|
||||
active_filling_id_snapshot bigint,
|
||||
@@ -1371,11 +1439,13 @@ create table biz_return_item (
|
||||
constraint ck_biz_return_item_remaining_packages_snapshot check (remaining_packages_snapshot >= 0),
|
||||
constraint fk_biz_return_item_order foreign key (return_id) references biz_return_order(return_id),
|
||||
constraint fk_biz_return_item_pallet foreign key (pallet_id) references biz_pallet(pallet_id),
|
||||
constraint fk_biz_return_item_filling foreign key (active_filling_id_snapshot) references biz_filling_record(filling_id)
|
||||
constraint fk_biz_return_item_filling foreign key (active_filling_id_snapshot) references biz_filling_record(filling_id),
|
||||
constraint fk_biz_return_item_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id)
|
||||
);
|
||||
|
||||
create table biz_pallet_event (
|
||||
event_id bigserial not null,
|
||||
test_batch_id bigint null,
|
||||
pallet_id bigint not null,
|
||||
event_seq integer not null,
|
||||
event_type varchar(32) not null,
|
||||
@@ -1411,11 +1481,13 @@ create table biz_pallet_event (
|
||||
constraint fk_biz_pallet_event_after_warehouse foreign key (after_warehouse_id) references biz_warehouse(warehouse_id),
|
||||
constraint fk_biz_pallet_event_after_site foreign key (after_site_id) references biz_customer_site(site_id),
|
||||
constraint fk_biz_pallet_event_after_line foreign key (after_line_id) references biz_production_line(line_id),
|
||||
constraint fk_biz_pallet_event_operator foreign key (operator_id) references sys_user(user_id)
|
||||
constraint fk_biz_pallet_event_operator foreign key (operator_id) references sys_user(user_id),
|
||||
constraint fk_biz_pallet_event_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id)
|
||||
);
|
||||
|
||||
create table biz_pallet_inventory (
|
||||
pallet_id bigint not null,
|
||||
test_batch_id bigint null,
|
||||
active_filling_id bigint,
|
||||
warehouse_id bigint,
|
||||
site_id bigint,
|
||||
@@ -1442,9 +1514,43 @@ create table biz_pallet_inventory (
|
||||
constraint fk_biz_pallet_inventory_warehouse foreign key (warehouse_id) references biz_warehouse(warehouse_id),
|
||||
constraint fk_biz_pallet_inventory_site foreign key (site_id) references biz_customer_site(site_id),
|
||||
constraint fk_biz_pallet_inventory_line foreign key (current_line_id) references biz_production_line(line_id),
|
||||
constraint fk_biz_pallet_inventory_event foreign key (last_event_id) references biz_pallet_event(event_id)
|
||||
constraint fk_biz_pallet_inventory_event foreign key (last_event_id) references biz_pallet_event(event_id),
|
||||
constraint fk_biz_pallet_inventory_test_batch_id foreign key (test_batch_id) references biz_test_batch(batch_id)
|
||||
);
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
|
||||
-- ----------------------------
|
||||
-- 初始化-托盘业务一级菜单和权限
|
||||
-- ----------------------------
|
||||
|
||||
@@ -19,6 +19,8 @@ drop table if exists biz_customer_site;
|
||||
drop table if exists biz_customer;
|
||||
drop table if exists biz_warehouse;
|
||||
drop table if exists biz_strain;
|
||||
drop table if exists biz_test_batch_user;
|
||||
drop table if exists biz_test_batch;
|
||||
|
||||
-- ----------------------------
|
||||
-- 1、部门表
|
||||
@@ -811,9 +813,49 @@ create table gen_table_column (
|
||||
-- ----------------------------
|
||||
-- 20、托盘业务表(按依赖创建)
|
||||
-- ----------------------------
|
||||
-- 测试数据批次
|
||||
create table biz_test_batch (
|
||||
batch_id bigint(20) 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(20) comment '关闭人ID',
|
||||
closed_at datetime comment '关闭时间',
|
||||
purged_by bigint(20) comment '清理人ID',
|
||||
purged_at datetime comment '清理时间',
|
||||
purge_summary text comment '清理摘要JSON',
|
||||
preview_action varchar(16) comment '预览动作',
|
||||
preview_token_hash char(64) comment '预览令牌摘要',
|
||||
preview_scope_hash char(64) comment '预览范围摘要',
|
||||
preview_expires_at datetime comment '预览过期时间',
|
||||
remark varchar(500) 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(20) not null comment '测试数据批次ID',
|
||||
user_id bigint(20) 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 = '测试数据批次与用户关联';
|
||||
|
||||
-- 菌种主数据表
|
||||
create table biz_strain (
|
||||
strain_id bigint(20) not null auto_increment comment '菌种ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
strain_code varchar(64) not null comment '菌种编码',
|
||||
strain_name varchar(100) not null comment '菌种名称',
|
||||
status char(1) not null default '0' comment '状态(0正常 1停用)',
|
||||
@@ -823,13 +865,16 @@ create table biz_strain (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (strain_id),
|
||||
key idx_biz_strain_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_strain_code unique (strain_code),
|
||||
constraint fk_biz_strain_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_strain_status check (status in ('0', '1'))
|
||||
) engine=innodb comment = '菌种主数据表';
|
||||
|
||||
-- 仓库主数据表
|
||||
create table biz_warehouse (
|
||||
warehouse_id bigint(20) not null auto_increment comment '仓库ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
warehouse_code varchar(64) not null comment '仓库编码',
|
||||
warehouse_name varchar(100) not null comment '仓库名称',
|
||||
address varchar(500) comment '仓库地址',
|
||||
@@ -840,13 +885,16 @@ create table biz_warehouse (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (warehouse_id),
|
||||
key idx_biz_warehouse_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_warehouse_code unique (warehouse_code),
|
||||
constraint fk_biz_warehouse_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_warehouse_status check (status in ('0', '1'))
|
||||
) engine=innodb comment = '仓库主数据表';
|
||||
|
||||
-- 客户主数据表
|
||||
create table biz_customer (
|
||||
customer_id bigint(20) not null auto_increment comment '客户ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
customer_code varchar(64) not null comment '客户编码',
|
||||
customer_name varchar(100) not null comment '客户名称',
|
||||
status char(1) not null default '0' comment '状态(0正常 1停用)',
|
||||
@@ -856,13 +904,16 @@ create table biz_customer (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (customer_id),
|
||||
key idx_biz_customer_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_customer_code unique (customer_code),
|
||||
constraint fk_biz_customer_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_customer_status check (status in ('0', '1'))
|
||||
) engine=innodb comment = '客户主数据表';
|
||||
|
||||
-- 客户现场主数据表
|
||||
create table biz_customer_site (
|
||||
site_id bigint(20) not null auto_increment comment '现场ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
customer_id bigint(20) not null comment '客户ID',
|
||||
site_code varchar(64) not null comment '现场编码',
|
||||
site_name varchar(100) not null comment '现场名称',
|
||||
@@ -874,7 +925,9 @@ create table biz_customer_site (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (site_id),
|
||||
key idx_biz_customer_site_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_customer_site_customer_code unique (customer_id, site_code),
|
||||
constraint fk_biz_customer_site_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint fk_biz_customer_site_customer foreign key (customer_id) references biz_customer (customer_id),
|
||||
constraint ck_biz_customer_site_status check (status in ('0', '1'))
|
||||
) engine=innodb comment = '客户现场主数据表';
|
||||
@@ -882,6 +935,7 @@ create table biz_customer_site (
|
||||
-- 客户现场产线主数据表
|
||||
create table biz_production_line (
|
||||
line_id bigint(20) not null auto_increment comment '产线ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
site_id bigint(20) not null comment '现场ID',
|
||||
line_code varchar(64) not null comment '产线编码',
|
||||
line_name varchar(100) not null comment '产线名称',
|
||||
@@ -892,7 +946,9 @@ create table biz_production_line (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (line_id),
|
||||
key idx_biz_production_line_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_production_line_site_code unique (site_id, line_code),
|
||||
constraint fk_biz_production_line_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint fk_biz_production_line_site foreign key (site_id) references biz_customer_site (site_id),
|
||||
constraint ck_biz_production_line_status check (status in ('0', '1'))
|
||||
) engine=innodb comment = '客户现场产线主数据表';
|
||||
@@ -900,6 +956,7 @@ create table biz_production_line (
|
||||
-- 托盘资产主数据表
|
||||
create table biz_pallet (
|
||||
pallet_id bigint(20) not null auto_increment comment '托盘ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
pallet_code varchar(64) not null comment '托盘编号',
|
||||
qr_token varchar(128) not null comment '二维码固定标识',
|
||||
capacity_packages int not null comment '容量包数',
|
||||
@@ -910,8 +967,10 @@ create table biz_pallet (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (pallet_id),
|
||||
key idx_biz_pallet_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_pallet_code unique (pallet_code),
|
||||
constraint uq_biz_pallet_qr_token unique (qr_token),
|
||||
constraint fk_biz_pallet_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_pallet_capacity_packages check (capacity_packages > 0),
|
||||
constraint ck_biz_pallet_asset_status check (asset_status in ('0', '1'))
|
||||
) engine=innodb comment = '托盘资产主数据表';
|
||||
@@ -941,6 +1000,7 @@ create table biz_user_site (
|
||||
-- 首次入库单
|
||||
create table biz_inbound_order (
|
||||
inbound_id bigint(20) not null auto_increment comment '入库单ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
inbound_no varchar(64) not null comment '入库单号',
|
||||
warehouse_id bigint(20) not null comment '仓库ID',
|
||||
status varchar(32) not null default 'DRAFT' comment '单据状态',
|
||||
@@ -954,29 +1014,35 @@ create table biz_inbound_order (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (inbound_id),
|
||||
key idx_biz_inbound_order_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_inbound_order_no unique (inbound_no),
|
||||
constraint uq_biz_inbound_order_warehouse_confirm_idempotency unique (warehouse_id, confirm_idempotency_key),
|
||||
constraint fk_biz_inbound_order_warehouse foreign key (warehouse_id) references biz_warehouse (warehouse_id),
|
||||
constraint fk_biz_inbound_order_confirmed_by foreign key (confirmed_by) references sys_user (user_id),
|
||||
constraint fk_biz_inbound_order_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_inbound_order_status check (status in ('DRAFT', 'CONFIRMED'))
|
||||
) engine=innodb comment = '首次入库单';
|
||||
|
||||
-- 首次入库单托盘明细
|
||||
create table biz_inbound_item (
|
||||
inbound_item_id bigint(20) not null auto_increment comment '入库明细ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
inbound_id bigint(20) not null comment '入库单ID',
|
||||
pallet_id bigint(20) not null comment '托盘ID',
|
||||
create_by varchar(64) default '' comment '创建者',
|
||||
create_time datetime comment '创建时间',
|
||||
primary key (inbound_item_id),
|
||||
key idx_biz_inbound_item_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_inbound_item_order_pallet unique (inbound_id, pallet_id),
|
||||
constraint fk_biz_inbound_item_order foreign key (inbound_id) references biz_inbound_order (inbound_id),
|
||||
constraint fk_biz_inbound_item_pallet foreign key (pallet_id) references biz_pallet (pallet_id)
|
||||
constraint fk_biz_inbound_item_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
|
||||
constraint fk_biz_inbound_item_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id)
|
||||
) engine=innodb comment = '首次入库单托盘明细';
|
||||
|
||||
-- 托盘装填记录
|
||||
create table biz_filling_record (
|
||||
filling_id bigint(20) not null auto_increment comment '装填记录ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
filling_no varchar(64) not null comment '装填单号',
|
||||
pallet_id bigint(20) not null comment '托盘ID',
|
||||
warehouse_id bigint(20) not null comment '仓库ID',
|
||||
@@ -998,6 +1064,7 @@ create table biz_filling_record (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (filling_id),
|
||||
key idx_biz_filling_record_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_filling_record_no unique (filling_no),
|
||||
constraint uq_biz_filling_record_warehouse_idempotency unique (warehouse_id, idempotency_key),
|
||||
constraint uq_biz_filling_record_pallet_active_slot unique (pallet_id, active_slot),
|
||||
@@ -1005,6 +1072,7 @@ create table biz_filling_record (
|
||||
constraint fk_biz_filling_record_warehouse foreign key (warehouse_id) references biz_warehouse (warehouse_id),
|
||||
constraint fk_biz_filling_record_strain foreign key (strain_id) references biz_strain (strain_id),
|
||||
constraint fk_biz_filling_record_operator foreign key (operator_id) references sys_user (user_id),
|
||||
constraint fk_biz_filling_record_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_filling_record_initial_packages check (initial_packages > 0),
|
||||
constraint ck_biz_filling_record_active_slot check (active_slot is null or active_slot = 'ACTIVE')
|
||||
) engine=innodb comment = '托盘装填记录';
|
||||
@@ -1012,6 +1080,7 @@ create table biz_filling_record (
|
||||
-- 整托发货单
|
||||
create table biz_shipment_order (
|
||||
shipment_id bigint(20) not null auto_increment comment '发货单ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
shipment_no varchar(64) not null comment '发货单号',
|
||||
source_warehouse_id bigint(20) not null comment '来源仓库ID',
|
||||
target_site_id bigint(20) not null comment '目标现场ID',
|
||||
@@ -1026,17 +1095,20 @@ create table biz_shipment_order (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (shipment_id),
|
||||
key idx_biz_shipment_order_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_shipment_order_no unique (shipment_no),
|
||||
constraint uq_biz_shipment_order_route_confirm_idempotency unique (source_warehouse_id, target_site_id, confirm_idempotency_key),
|
||||
constraint fk_biz_shipment_order_warehouse foreign key (source_warehouse_id) references biz_warehouse (warehouse_id),
|
||||
constraint fk_biz_shipment_order_site foreign key (target_site_id) references biz_customer_site (site_id),
|
||||
constraint fk_biz_shipment_order_confirmed_by foreign key (confirmed_by) references sys_user (user_id),
|
||||
constraint fk_biz_shipment_order_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_shipment_order_status check (status in ('DRAFT', 'CONFIRMED'))
|
||||
) engine=innodb comment = '整托发货单';
|
||||
|
||||
-- 整托发货明细
|
||||
create table biz_shipment_item (
|
||||
shipment_item_id bigint(20) not null auto_increment comment '发货明细ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
shipment_id bigint(20) not null comment '发货单ID',
|
||||
pallet_id bigint(20) not null comment '托盘ID',
|
||||
active_filling_id bigint(20) comment '确认时活动装填记录ID',
|
||||
@@ -1044,16 +1116,19 @@ create table biz_shipment_item (
|
||||
create_by varchar(64) default '' comment '创建者',
|
||||
create_time datetime comment '创建时间',
|
||||
primary key (shipment_item_id),
|
||||
key idx_biz_shipment_item_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_shipment_item_order_pallet unique (shipment_id, pallet_id),
|
||||
constraint fk_biz_shipment_item_order foreign key (shipment_id) references biz_shipment_order (shipment_id),
|
||||
constraint fk_biz_shipment_item_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
|
||||
constraint fk_biz_shipment_item_filling foreign key (active_filling_id) references biz_filling_record (filling_id),
|
||||
constraint fk_biz_shipment_item_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_shipment_item_package_qty check (package_qty is null or package_qty > 0)
|
||||
) engine=innodb comment = '整托发货明细';
|
||||
|
||||
-- 客户现场使用事实记录
|
||||
create table biz_usage_record (
|
||||
usage_id bigint(20) not null auto_increment comment '使用记录ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
usage_no varchar(64) not null comment '使用记录号',
|
||||
pallet_id bigint(20) not null comment '托盘ID',
|
||||
active_filling_id bigint(20) not null comment '活动装填记录ID',
|
||||
@@ -1066,6 +1141,7 @@ create table biz_usage_record (
|
||||
operator_id bigint(20) not null comment '操作人ID',
|
||||
occurred_at datetime not null comment '发生时间',
|
||||
primary key (usage_id),
|
||||
key idx_biz_usage_record_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_usage_record_no unique (usage_no),
|
||||
constraint uq_biz_usage_record_site_idempotency unique (site_id, idempotency_key),
|
||||
constraint fk_biz_usage_record_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
|
||||
@@ -1073,6 +1149,7 @@ create table biz_usage_record (
|
||||
constraint fk_biz_usage_record_site foreign key (site_id) references biz_customer_site (site_id),
|
||||
constraint fk_biz_usage_record_line foreign key (line_id) references biz_production_line (line_id),
|
||||
constraint fk_biz_usage_record_operator foreign key (operator_id) references sys_user (user_id),
|
||||
constraint fk_biz_usage_record_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_usage_record_used_packages check (used_packages > 0),
|
||||
constraint ck_biz_usage_record_remaining_packages_after check (remaining_packages_after >= 0)
|
||||
) engine=innodb comment = '客户现场使用事实记录';
|
||||
@@ -1080,6 +1157,7 @@ create table biz_usage_record (
|
||||
-- 托盘退回单
|
||||
create table biz_return_order (
|
||||
return_id bigint(20) not null auto_increment comment '退回单ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
return_no varchar(64) not null comment '退回单号',
|
||||
source_site_id bigint(20) not null comment '来源现场ID',
|
||||
target_warehouse_id bigint(20) not null comment '目标仓库ID',
|
||||
@@ -1098,6 +1176,7 @@ create table biz_return_order (
|
||||
update_time datetime comment '更新时间',
|
||||
remark varchar(500) default null comment '备注',
|
||||
primary key (return_id),
|
||||
key idx_biz_return_order_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_return_order_no unique (return_no),
|
||||
constraint uq_biz_return_order_route_request_idempotency unique (source_site_id, target_warehouse_id, request_idempotency_key),
|
||||
constraint uq_biz_return_order_route_confirm_idempotency unique (source_site_id, target_warehouse_id, confirm_idempotency_key),
|
||||
@@ -1105,12 +1184,14 @@ create table biz_return_order (
|
||||
constraint fk_biz_return_order_warehouse foreign key (target_warehouse_id) references biz_warehouse (warehouse_id),
|
||||
constraint fk_biz_return_order_requested_by foreign key (requested_by) references sys_user (user_id),
|
||||
constraint fk_biz_return_order_confirmed_by foreign key (confirmed_by) references sys_user (user_id),
|
||||
constraint fk_biz_return_order_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_return_order_status check (status in ('REQUESTED', 'CONFIRMED'))
|
||||
) engine=innodb comment = '托盘退回单';
|
||||
|
||||
-- 托盘退回明细
|
||||
create table biz_return_item (
|
||||
return_item_id bigint(20) not null auto_increment comment '退回明细ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
return_id bigint(20) not null comment '退回单ID',
|
||||
pallet_id bigint(20) not null comment '托盘ID',
|
||||
active_filling_id_snapshot bigint(20) comment '申请时活动装填记录快照',
|
||||
@@ -1118,16 +1199,19 @@ create table biz_return_item (
|
||||
create_by varchar(64) default '' comment '创建者',
|
||||
create_time datetime comment '创建时间',
|
||||
primary key (return_item_id),
|
||||
key idx_biz_return_item_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_return_item_order_pallet unique (return_id, pallet_id),
|
||||
constraint fk_biz_return_item_order foreign key (return_id) references biz_return_order (return_id),
|
||||
constraint fk_biz_return_item_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
|
||||
constraint fk_biz_return_item_filling foreign key (active_filling_id_snapshot) references biz_filling_record (filling_id),
|
||||
constraint fk_biz_return_item_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_return_item_remaining_packages_snapshot check (remaining_packages_snapshot >= 0)
|
||||
) engine=innodb comment = '托盘退回明细';
|
||||
|
||||
-- 托盘只追加流转事件;必须先于库存快照创建
|
||||
create table biz_pallet_event (
|
||||
event_id bigint(20) not null auto_increment comment '事件ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
pallet_id bigint(20) not null comment '托盘ID',
|
||||
event_seq int not null comment '托盘内事件序号',
|
||||
event_type varchar(32) not null comment '事件类型',
|
||||
@@ -1148,6 +1232,7 @@ create table biz_pallet_event (
|
||||
idempotency_key varchar(64) not null comment '幂等键',
|
||||
request_hash varchar(64) not null comment '请求摘要',
|
||||
primary key (event_id),
|
||||
key idx_biz_pallet_event_test_batch_id (test_batch_id),
|
||||
constraint uq_biz_pallet_event_pallet_seq unique (pallet_id, event_seq),
|
||||
constraint uq_biz_pallet_event_pallet_idempotency unique (pallet_id, idempotency_key),
|
||||
constraint fk_biz_pallet_event_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
|
||||
@@ -1158,6 +1243,7 @@ create table biz_pallet_event (
|
||||
constraint fk_biz_pallet_event_after_site foreign key (after_site_id) references biz_customer_site (site_id),
|
||||
constraint fk_biz_pallet_event_after_line foreign key (after_line_id) references biz_production_line (line_id),
|
||||
constraint fk_biz_pallet_event_operator foreign key (operator_id) references sys_user (user_id),
|
||||
constraint fk_biz_pallet_event_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_pallet_event_event_type check (
|
||||
event_type in (
|
||||
'INBOUND_CONFIRMED',
|
||||
@@ -1173,6 +1259,7 @@ create table biz_pallet_event (
|
||||
-- 托盘当前库存、位置和流转状态
|
||||
create table biz_pallet_inventory (
|
||||
pallet_id bigint(20) not null comment '托盘ID',
|
||||
test_batch_id bigint(20) null comment '测试数据批次ID;NULL表示正式数据',
|
||||
active_filling_id bigint(20) comment '当前活动装填记录ID',
|
||||
warehouse_id bigint(20) comment '当前仓库ID',
|
||||
site_id bigint(20) comment '当前现场ID',
|
||||
@@ -1183,12 +1270,14 @@ create table biz_pallet_inventory (
|
||||
version int not null default 0 comment '并发版本号',
|
||||
updated_at datetime not null comment '更新时间',
|
||||
primary key (pallet_id),
|
||||
key idx_biz_pallet_inventory_test_batch_id (test_batch_id),
|
||||
constraint fk_biz_pallet_inventory_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
|
||||
constraint fk_biz_pallet_inventory_filling foreign key (active_filling_id) references biz_filling_record (filling_id),
|
||||
constraint fk_biz_pallet_inventory_warehouse foreign key (warehouse_id) references biz_warehouse (warehouse_id),
|
||||
constraint fk_biz_pallet_inventory_site foreign key (site_id) references biz_customer_site (site_id),
|
||||
constraint fk_biz_pallet_inventory_line foreign key (current_line_id) references biz_production_line (line_id),
|
||||
constraint fk_biz_pallet_inventory_event foreign key (last_event_id) references biz_pallet_event (event_id),
|
||||
constraint fk_biz_pallet_inventory_test_batch_id foreign key (test_batch_id) references biz_test_batch (batch_id),
|
||||
constraint ck_biz_pallet_inventory_flow_state check (
|
||||
flow_state in (
|
||||
'UNSTOCKED',
|
||||
|
||||
Reference in New Issue
Block a user