002-production-v2.xml
4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd">
<!--
pbc-production v2 schema additions.
Two things:
1) Widen the status CHECK constraint to admit IN_PROGRESS.
v1 locked DRAFT / COMPLETED / CANCELLED only; v2 adds an
IN_PROGRESS state between DRAFT and COMPLETED so
started-but-not-finished work is observable.
2) Create production__work_order_input — the BOM child table.
Each row is one raw material consumed per unit of output.
complete() iterates these lines and writes one
MATERIAL_ISSUE ledger row per line before writing the
PRODUCTION_RECEIPT, all in one transaction. An empty list
is legal (complete() just writes the PRODUCTION_RECEIPT
and nothing else), which lets the SalesOrderConfirmedSubscriber
keep auto-spawning orders without knowing the BOM.
NEITHER source_location_code NOR item_code is a foreign key —
same cross-PBC rationale as the parent table. The application
enforces existence through CatalogApi / LocationJpaRepository
at create time.
-->
<changeSet id="production-v2-001-status-in-progress" author="vibe_erp">
<comment>Widen production__work_order.status CHECK to allow IN_PROGRESS</comment>
<sql>
ALTER TABLE production__work_order
DROP CONSTRAINT production__work_order_status_check;
ALTER TABLE production__work_order
ADD CONSTRAINT production__work_order_status_check
CHECK (status IN ('DRAFT', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED'));
</sql>
<rollback>
ALTER TABLE production__work_order
DROP CONSTRAINT production__work_order_status_check;
ALTER TABLE production__work_order
ADD CONSTRAINT production__work_order_status_check
CHECK (status IN ('DRAFT', 'COMPLETED', 'CANCELLED'));
</rollback>
</changeSet>
<changeSet id="production-v2-002-work-order-input" author="vibe_erp">
<comment>Create production__work_order_input (BOM child table)</comment>
<sql>
CREATE TABLE production__work_order_input (
id uuid PRIMARY KEY,
work_order_id uuid NOT NULL
REFERENCES production__work_order(id) ON DELETE CASCADE,
line_no integer NOT NULL,
item_code varchar(64) NOT NULL,
quantity_per_unit numeric(18,4) NOT NULL,
source_location_code varchar(64) NOT NULL,
created_at timestamptz NOT NULL,
created_by varchar(128) NOT NULL,
updated_at timestamptz NOT NULL,
updated_by varchar(128) NOT NULL,
version bigint NOT NULL DEFAULT 0,
CONSTRAINT production__work_order_input_qty_pos
CHECK (quantity_per_unit > 0),
CONSTRAINT production__work_order_input_line_no_pos
CHECK (line_no > 0),
CONSTRAINT production__work_order_input_line_uk
UNIQUE (work_order_id, line_no)
);
CREATE INDEX production__work_order_input_wo_idx
ON production__work_order_input (work_order_id);
CREATE INDEX production__work_order_input_item_idx
ON production__work_order_input (item_code);
</sql>
<rollback>
DROP TABLE production__work_order_input;
</rollback>
</changeSet>
</databaseChangeLog>