dodil/erp-platform

templates/brick-example/src/brick_example/schema.sql

-- Every table is prefixed with the brick's name: at tier 1 several bricks share one bucket.
-- Every table has a natural primary key (never SERIAL), and every child's key starts with the
-- root's key — the repository finds stale rows under a quote by that prefix.
-- Money is NUMERIC(18,2). Creation columns go last, so a later column is an append, not a reshape.

CREATE TABLE IF NOT EXISTS example_quotes (
    quote_id    VARCHAR NOT NULL,
    customer    VARCHAR NOT NULL,
    owner       VARCHAR NOT NULL,
    status      VARCHAR NOT NULL,
    currency    VARCHAR NOT NULL,
    created_at  TIMESTAMP,
    updated_at  TIMESTAMP,
    PRIMARY KEY (quote_id)
);

CREATE TABLE IF NOT EXISTS example_lines (
    quote_id    VARCHAR NOT NULL,
    line_no     INTEGER NOT NULL,
    description VARCHAR NOT NULL,
    quantity    INTEGER NOT NULL,
    unit_price  NUMERIC(18,2) NOT NULL,
    created_at  TIMESTAMP,
    updated_at  TIMESTAMP,
    PRIMARY KEY (quote_id, line_no)
);