001-warehousing-init.xml
4.3 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
<?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-warehousing initial schema (P5.4).
Owns: warehousing__stock_transfer + warehousing__stock_transfer_line.
StockTransfer is a first-class orchestration aggregate on top of
the flat InventoryApi.recordMovement primitive. Confirming a DRAFT
transfer writes one TRANSFER_OUT + TRANSFER_IN pair per line
atomically in a single transaction, referenced TR:<code>.
Neither item_code nor the location codes are foreign keys — they
are cross-PBC references. DB-level FKs across PBCs would couple
pbc-warehousing's schema with pbc-catalog and pbc-inventory at
the storage level, defeating the bounded-context rule. Existence
is enforced at the application layer via CatalogApi at create time
and InventoryApi.recordMovement at confirm time.
-->
<changeSet id="warehousing-init-001" author="vibe_erp">
<comment>Create warehousing__stock_transfer + warehousing__stock_transfer_line tables</comment>
<sql>
CREATE TABLE warehousing__stock_transfer (
id uuid PRIMARY KEY,
code varchar(64) NOT NULL,
from_location_code varchar(64) NOT NULL,
to_location_code varchar(64) NOT NULL,
status varchar(16) NOT NULL,
transfer_date date,
note varchar(512),
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 warehousing__stock_transfer_status_check
CHECK (status IN ('DRAFT', 'CONFIRMED', 'CANCELLED')),
CONSTRAINT warehousing__stock_transfer_locations_distinct
CHECK (from_location_code <> to_location_code)
);
CREATE UNIQUE INDEX warehousing__stock_transfer_code_uk
ON warehousing__stock_transfer (code);
CREATE INDEX warehousing__stock_transfer_status_idx
ON warehousing__stock_transfer (status);
CREATE INDEX warehousing__stock_transfer_from_idx
ON warehousing__stock_transfer (from_location_code);
CREATE INDEX warehousing__stock_transfer_to_idx
ON warehousing__stock_transfer (to_location_code);
CREATE TABLE warehousing__stock_transfer_line (
id uuid PRIMARY KEY,
transfer_id uuid NOT NULL
REFERENCES warehousing__stock_transfer (id) ON DELETE CASCADE,
line_no integer NOT NULL,
item_code varchar(64) NOT NULL,
quantity numeric(18,4) 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 warehousing__stock_transfer_line_qty_pos
CHECK (quantity > 0)
);
CREATE UNIQUE INDEX warehousing__stock_transfer_line_uk
ON warehousing__stock_transfer_line (transfer_id, line_no);
CREATE INDEX warehousing__stock_transfer_line_item_idx
ON warehousing__stock_transfer_line (item_code);
</sql>
<rollback>
DROP TABLE warehousing__stock_transfer_line;
DROP TABLE warehousing__stock_transfer;
</rollback>
</changeSet>
</databaseChangeLog>