001-production-init.xml 3.34 KB
<?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 initial schema (P5.7, minimal v1).

        Owns: production__work_order.

        Single-output work orders only — no BOM lines, no operations,
        no routings, no scheduling. The minimal v1 has just enough to
        prove that "a confirmed sales order auto-spawns a work order
        and completing it credits finished goods to inventory".

        NEITHER `output_item_code` NOR `source_sales_order_code` is a
        foreign key. They are cross-PBC references; a database FK
        across PBCs would couple pbc-production's schema with
        pbc-catalog and pbc-orders-sales at the storage level,
        defeating the bounded-context rule (CLAUDE.md guardrail #9).
        The application enforces existence via CatalogApi and the
        SalesOrderConfirmedSubscriber's idempotent dedup.
    -->

    <changeSet id="production-init-001" author="vibe_erp">
        <comment>Create production__work_order table</comment>
        <sql>
            CREATE TABLE production__work_order (
                id                          uuid PRIMARY KEY,
                code                        varchar(64)    NOT NULL,
                output_item_code            varchar(64)    NOT NULL,
                output_quantity             numeric(18,4)  NOT NULL,
                status                      varchar(16)    NOT NULL,
                due_date                    date,
                source_sales_order_code     varchar(64),
                ext                         jsonb          NOT NULL DEFAULT '{}'::jsonb,
                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_status_check
                    CHECK (status IN ('DRAFT', 'COMPLETED', 'CANCELLED')),
                CONSTRAINT production__work_order_qty_pos
                    CHECK (output_quantity &gt; 0)
            );
            CREATE UNIQUE INDEX production__work_order_code_uk
                ON production__work_order (code);
            CREATE INDEX production__work_order_status_idx
                ON production__work_order (status);
            CREATE INDEX production__work_order_output_item_idx
                ON production__work_order (output_item_code);
            CREATE INDEX production__work_order_source_so_idx
                ON production__work_order (source_sales_order_code);
            CREATE INDEX production__work_order_due_date_idx
                ON production__work_order (due_date);
            CREATE INDEX production__work_order_ext_gin
                ON production__work_order USING GIN (ext jsonb_path_ops);
        </sql>
        <rollback>
            DROP TABLE production__work_order;
        </rollback>
    </changeSet>

</databaseChangeLog>