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

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
@@ -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);
-- ----------------------------
-- 初始化-托盘业务一级菜单和权限
-- ----------------------------