Skip to content

Corpus 02 · Derived from TPC-C (Order-Entry OLTP)#

← All Assimilation Pathways · Live test suite: tests/integration/migrations/corpora/test_corpora.py

Note

TPC fair-use notice. This schema is derived from the public TPC-C order-entry specification for schema-migration testing only. It is not an official TPC kit, publishes no TPC metrics (tpmC or price/performance), and is not comparable to published TPC-C results.

This 9-table order-entry schema (warehouse, district, customer, history, orders, new_order, item, stock, order_line) stresses the hardest relational patterns in production PostgreSQL:

  • Ordered 2- and 3-column composite primary keys ((c_w_id, c_d_id, c_id), (ol_w_id, ol_d_id, ol_o_id, ol_number)), where column order in pg_constraint.conkey determines whether an FK is already indexed by the PK's leftmost prefix (zero false UNINDEXED_FK findings).
  • Composite foreign keys referencing composite primary keys (orders → customer, order_line → orders, order_line → stock), which require exact drop-FK → swap-PK → re-add-FK dependency ordering during full assimilation so PostgreSQL never raises 2BP01 or silently drops constraints.
  • Keyless append table (history) and fixed-width character(N) + numeric(p,s) columns.
Verification Rung Mode Result on Live PostgreSQL
Catalog audit (audit-schema) Read-only ✅ migratable=True, 0 false UNINDEXED_FK
Zero-DDL bind (scaffold --mode bind) Bind-as-is ✅ plan_migration().ops == ()
Full atomic assimilation (scaffold --mode assimilate) Assimilate ✅ 1 atomic TX, all 9 FKs preserved, plan_migration().ops == ()

1. Source Schema#

tests/integration/migrations/corpora/02_tpcc_derived/schema.sql
-- Schema derived from the TPC-C specification (clause 1.3); not a TPC kit.
CREATE TABLE warehouse (
    w_id smallint NOT NULL,
    w_name varchar(10),
    w_street_1 varchar(20),
    w_street_2 varchar(20),
    w_city varchar(20),
    w_state char(2),
    w_zip char(9),
    w_tax numeric(4, 4),
    w_ytd numeric(12, 2),
    PRIMARY KEY (w_id)
);

CREATE TABLE district (
    d_id smallint NOT NULL,
    d_w_id smallint NOT NULL REFERENCES warehouse(w_id),
    d_name varchar(10),
    d_street_1 varchar(20),
    d_street_2 varchar(20),
    d_city varchar(20),
    d_state char(2),
    d_zip char(9),
    d_tax numeric(4, 4),
    d_ytd numeric(12, 2),
    d_next_o_id integer,
    PRIMARY KEY (d_w_id, d_id)
);

CREATE TABLE customer (
    c_id integer NOT NULL,
    c_d_id smallint NOT NULL,
    c_w_id smallint NOT NULL,
    c_first varchar(16),
    c_middle char(2),
    c_last varchar(16),
    c_street_1 varchar(20),
    c_street_2 varchar(20),
    c_city varchar(20),
    c_state char(2),
    c_zip char(9),
    c_phone char(16),
    c_since timestamp without time zone,
    c_credit char(2),
    c_credit_lim numeric(12, 2),
    c_discount numeric(4, 4),
    c_balance numeric(12, 2),
    c_ytd_payment numeric(12, 2),
    c_payment_cnt smallint,
    c_delivery_cnt smallint,
    c_data varchar(500),
    PRIMARY KEY (c_w_id, c_d_id, c_id),
    FOREIGN KEY (c_w_id, c_d_id) REFERENCES district(d_w_id, d_id)
);
CREATE INDEX customer_last_name ON customer (c_w_id, c_d_id, c_last, c_first);

CREATE TABLE history (
    h_c_id integer,
    h_c_d_id smallint,
    h_c_w_id smallint,
    h_d_id smallint,
    h_w_id smallint,
    h_date timestamp without time zone,
    h_amount numeric(6, 2),
    h_data varchar(24),
    FOREIGN KEY (h_c_w_id, h_c_d_id, h_c_id) REFERENCES customer(c_w_id, c_d_id, c_id),
    FOREIGN KEY (h_w_id, h_d_id) REFERENCES district(d_w_id, d_id)
);

CREATE TABLE orders (
    o_id integer NOT NULL,
    o_d_id smallint NOT NULL,
    o_w_id smallint NOT NULL,
    o_c_id integer,
    o_entry_d timestamp without time zone,
    o_carrier_id smallint,
    o_ol_cnt smallint,
    o_all_local smallint,
    PRIMARY KEY (o_w_id, o_d_id, o_id),
    FOREIGN KEY (o_w_id, o_d_id, o_c_id) REFERENCES customer(c_w_id, c_d_id, c_id)
);

CREATE TABLE new_order (
    no_o_id integer NOT NULL,
    no_d_id smallint NOT NULL,
    no_w_id smallint NOT NULL,
    PRIMARY KEY (no_w_id, no_d_id, no_o_id),
    FOREIGN KEY (no_w_id, no_d_id, no_o_id) REFERENCES orders(o_w_id, o_d_id, o_id)
);

CREATE TABLE item (
    i_id integer NOT NULL,
    i_im_id integer,
    i_name varchar(24),
    i_price numeric(5, 2),
    i_data varchar(50),
    PRIMARY KEY (i_id)
);

CREATE TABLE stock (
    s_i_id integer NOT NULL REFERENCES item(i_id),
    s_w_id smallint NOT NULL REFERENCES warehouse(w_id),
    s_quantity smallint,
    s_dist_01 char(24),
    s_dist_02 char(24),
    s_dist_03 char(24),
    s_dist_04 char(24),
    s_dist_05 char(24),
    s_dist_06 char(24),
    s_dist_07 char(24),
    s_dist_08 char(24),
    s_dist_09 char(24),
    s_dist_10 char(24),
    s_ytd numeric(8, 0),
    s_order_cnt smallint,
    s_remote_cnt smallint,
    s_data varchar(50),
    PRIMARY KEY (s_w_id, s_i_id)
);

CREATE TABLE order_line (
    ol_o_id integer NOT NULL,
    ol_d_id smallint NOT NULL,
    ol_w_id smallint NOT NULL,
    ol_number smallint NOT NULL,
    ol_i_id integer,
    ol_supply_w_id smallint,
    ol_delivery_d timestamp without time zone,
    ol_quantity smallint,
    ol_amount numeric(6, 2),
    ol_dist_info char(24),
    PRIMARY KEY (ol_w_id, ol_d_id, ol_o_id, ol_number),
    FOREIGN KEY (ol_w_id, ol_d_id, ol_o_id) REFERENCES orders(o_w_id, o_d_id, o_id),
    FOREIGN KEY (ol_supply_w_id, ol_i_id) REFERENCES stock(s_w_id, s_i_id)
);

2. Live Catalog Audit#

migratable · exit 0
15 migration4 info
  • MIGRATIONUNINDEXED_FK
    history · history_h_c_w_id_h_c_d_id_h_c_id_fkey
    FK 'history_h_c_w_id_h_c_d_id_h_c_id_fkey' on history(h_c_w_id, h_c_d_id, h_c_id) has no covering B-tree index.
  • MIGRATIONUNINDEXED_FK
    history · history_h_w_id_h_d_id_fkey
    FK 'history_h_w_id_h_d_id_fkey' on history(h_w_id, h_d_id) has no covering B-tree index.
  • MIGRATIONUNINDEXED_FK
    order_line · order_line_ol_supply_w_id_ol_i_id_fkey
    FK 'order_line_ol_supply_w_id_ol_i_id_fkey' on order_line(ol_supply_w_id, ol_i_id) has no covering B-tree index.
  • MIGRATIONUNINDEXED_FK
    orders · orders_o_w_id_o_d_id_o_c_id_fkey
    FK 'orders_o_w_id_o_d_id_o_c_id_fkey' on orders(o_w_id, o_d_id, o_c_id) has no covering B-tree index.
  • MIGRATIONUNINDEXED_FK
    stock · stock_s_i_id_fkey
    FK 'stock_s_i_id_fkey' on stock(s_i_id) has no covering B-tree index.
  • MIGRATIONTABLE_NAME_PLURAL
    orders
    Table 'orders' appears plural; assimilate to singular snake_case.
  • MIGRATIONPK_COMPOSITE
    customer · c_id,c_d_id,c_w_id
    Table 'customer' uses composite PK (c_id, c_d_id, c_w_id).
  • MIGRATIONPK_COMPOSITE
    district · d_id,d_w_id
    Table 'district' uses composite PK (d_id, d_w_id).
  • MIGRATIONPK_MISSING
    history
    Table 'history' has no primary key.
  • MIGRATIONPK_NAME_MISMATCH
    item · i_id
    Table 'item' PK is 'i_id' instead of 'item_id'.
  • MIGRATIONPK_COMPOSITE
    new_order · no_o_id,no_d_id,no_w_id
    Table 'new_order' uses composite PK (no_o_id, no_d_id, no_w_id).
  • MIGRATIONPK_COMPOSITE
    order_line · ol_o_id,ol_d_id,ol_w_id,ol_number
    Table 'order_line' uses composite PK (ol_o_id, ol_d_id, ol_w_id, ol_number).
  • MIGRATIONPK_COMPOSITE
    orders · o_id,o_d_id,o_w_id
    Table 'orders' uses composite PK (o_id, o_d_id, o_w_id).
  • MIGRATIONPK_COMPOSITE
    stock · s_i_id,s_w_id
    Table 'stock' uses composite PK (s_i_id, s_w_id).
  • MIGRATIONPK_NAME_MISMATCH
    warehouse · w_id
    Table 'warehouse' PK is 'w_id' instead of 'warehouse_id'.
  • INFOTIMESTAMP_WITHOUT_TZ
    customer · c_since
    Column customer.c_since uses TIMESTAMP WITHOUT TIME ZONE.
  • INFOTIMESTAMP_WITHOUT_TZ
    history · h_date
    Column history.h_date uses TIMESTAMP WITHOUT TIME ZONE.
  • INFOTIMESTAMP_WITHOUT_TZ
    order_line · ol_delivery_d
    Column order_line.ol_delivery_d uses TIMESTAMP WITHOUT TIME ZONE.
  • INFOTIMESTAMP_WITHOUT_TZ
    orders · o_entry_d
    Column orders.o_entry_d uses TIMESTAMP WITHOUT TIME ZONE.
Inspect raw machine-readable audit JSON (tests/integration/migrations/corpora/02_tpcc_derived/captured/audit.json)
{
  "counts": {
    "blocker": 0,
    "info": 4,
    "migration_required": 15,
    "unmanaged": 0
  },
  "findings": [
    {
      "auto_fixable": true,
      "category": "indexes",
      "code": "UNINDEXED_FK",
      "doc_anchor": "constraints-and-indexes",
      "message": "FK 'history_h_c_w_id_h_c_d_id_h_c_id_fkey' on history(h_c_w_id, h_c_d_id, h_c_id) has no covering B-tree index.",
      "object_kind": "foreign_key",
      "object_name": "history_h_c_w_id_h_c_d_id_h_c_id_fkey",
      "severity": "migration_required",
      "suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
      "table": "history"
    },
    {
      "auto_fixable": true,
      "category": "indexes",
      "code": "UNINDEXED_FK",
      "doc_anchor": "constraints-and-indexes",
      "message": "FK 'history_h_w_id_h_d_id_fkey' on history(h_w_id, h_d_id) has no covering B-tree index.",
      "object_kind": "foreign_key",
      "object_name": "history_h_w_id_h_d_id_fkey",
      "severity": "migration_required",
      "suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
      "table": "history"
    },
    {
      "auto_fixable": true,
      "category": "indexes",
      "code": "UNINDEXED_FK",
      "doc_anchor": "constraints-and-indexes",
      "message": "FK 'order_line_ol_supply_w_id_ol_i_id_fkey' on order_line(ol_supply_w_id, ol_i_id) has no covering B-tree index.",
      "object_kind": "foreign_key",
      "object_name": "order_line_ol_supply_w_id_ol_i_id_fkey",
      "severity": "migration_required",
      "suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
      "table": "order_line"
    },
    {
      "auto_fixable": true,
      "category": "indexes",
      "code": "UNINDEXED_FK",
      "doc_anchor": "constraints-and-indexes",
      "message": "FK 'orders_o_w_id_o_d_id_o_c_id_fkey' on orders(o_w_id, o_d_id, o_c_id) has no covering B-tree index.",
      "object_kind": "foreign_key",
      "object_name": "orders_o_w_id_o_d_id_o_c_id_fkey",
      "severity": "migration_required",
      "suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
      "table": "orders"
    },
    {
      "auto_fixable": true,
      "category": "indexes",
      "code": "UNINDEXED_FK",
      "doc_anchor": "constraints-and-indexes",
      "message": "FK 'stock_s_i_id_fkey' on stock(s_i_id) has no covering B-tree index.",
      "object_kind": "foreign_key",
      "object_name": "stock_s_i_id_fkey",
      "severity": "migration_required",
      "suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
      "table": "stock"
    },
    {
      "auto_fixable": true,
      "category": "naming",
      "code": "TABLE_NAME_PLURAL",
      "doc_anchor": "table-naming",
      "message": "Table 'orders' appears plural; assimilate to singular snake_case.",
      "object_kind": "table",
      "object_name": "orders",
      "severity": "migration_required",
      "suggestion": "Rename table to singular snake_case via AdoptionMap.",
      "table": "orders"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_COMPOSITE",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'customer' uses composite PK (c_id, c_d_id, c_w_id).",
      "object_kind": "primary_key",
      "object_name": "c_id,c_d_id,c_w_id",
      "severity": "migration_required",
      "suggestion": "Add surrogate `<table_name>_id` PK and demote composite PK to `pg.Unique(...)`.",
      "table": "customer"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_COMPOSITE",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'district' uses composite PK (d_id, d_w_id).",
      "object_kind": "primary_key",
      "object_name": "d_id,d_w_id",
      "severity": "migration_required",
      "suggestion": "Add surrogate `<table_name>_id` PK and demote composite PK to `pg.Unique(...)`.",
      "table": "district"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_MISSING",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'history' has no primary key.",
      "object_kind": "primary_key",
      "object_name": "history",
      "severity": "migration_required",
      "suggestion": "Add `<table_name>_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY`.",
      "table": "history"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_NAME_MISMATCH",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'item' PK is 'i_id' instead of 'item_id'.",
      "object_kind": "primary_key",
      "object_name": "i_id",
      "severity": "migration_required",
      "suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
      "table": "item"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_COMPOSITE",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'new_order' uses composite PK (no_o_id, no_d_id, no_w_id).",
      "object_kind": "primary_key",
      "object_name": "no_o_id,no_d_id,no_w_id",
      "severity": "migration_required",
      "suggestion": "Add surrogate `<table_name>_id` PK and demote composite PK to `pg.Unique(...)`.",
      "table": "new_order"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_COMPOSITE",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'order_line' uses composite PK (ol_o_id, ol_d_id, ol_w_id, ol_number).",
      "object_kind": "primary_key",
      "object_name": "ol_o_id,ol_d_id,ol_w_id,ol_number",
      "severity": "migration_required",
      "suggestion": "Add surrogate `<table_name>_id` PK and demote composite PK to `pg.Unique(...)`.",
      "table": "order_line"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_COMPOSITE",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'orders' uses composite PK (o_id, o_d_id, o_w_id).",
      "object_kind": "primary_key",
      "object_name": "o_id,o_d_id,o_w_id",
      "severity": "migration_required",
      "suggestion": "Add surrogate `<table_name>_id` PK and demote composite PK to `pg.Unique(...)`.",
      "table": "orders"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_COMPOSITE",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'stock' uses composite PK (s_i_id, s_w_id).",
      "object_kind": "primary_key",
      "object_name": "s_i_id,s_w_id",
      "severity": "migration_required",
      "suggestion": "Add surrogate `<table_name>_id` PK and demote composite PK to `pg.Unique(...)`.",
      "table": "stock"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_NAME_MISMATCH",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'warehouse' PK is 'w_id' instead of 'warehouse_id'.",
      "object_kind": "primary_key",
      "object_name": "w_id",
      "severity": "migration_required",
      "suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
      "table": "warehouse"
    },
    {
      "auto_fixable": false,
      "category": "types",
      "code": "TIMESTAMP_WITHOUT_TZ",
      "doc_anchor": "column-types",
      "message": "Column customer.c_since uses TIMESTAMP WITHOUT TIME ZONE.",
      "object_kind": "column",
      "object_name": "c_since",
      "severity": "info",
      "suggestion": "Scaffold emits `pg.Col[pg.Timestamp]` automatically.",
      "table": "customer"
    },
    {
      "auto_fixable": false,
      "category": "types",
      "code": "TIMESTAMP_WITHOUT_TZ",
      "doc_anchor": "column-types",
      "message": "Column history.h_date uses TIMESTAMP WITHOUT TIME ZONE.",
      "object_kind": "column",
      "object_name": "h_date",
      "severity": "info",
      "suggestion": "Scaffold emits `pg.Col[pg.Timestamp]` automatically.",
      "table": "history"
    },
    {
      "auto_fixable": false,
      "category": "types",
      "code": "TIMESTAMP_WITHOUT_TZ",
      "doc_anchor": "column-types",
      "message": "Column order_line.ol_delivery_d uses TIMESTAMP WITHOUT TIME ZONE.",
      "object_kind": "column",
      "object_name": "ol_delivery_d",
      "severity": "info",
      "suggestion": "Scaffold emits `pg.Col[pg.Timestamp]` automatically.",
      "table": "order_line"
    },
    {
      "auto_fixable": false,
      "category": "types",
      "code": "TIMESTAMP_WITHOUT_TZ",
      "doc_anchor": "column-types",
      "message": "Column orders.o_entry_d uses TIMESTAMP WITHOUT TIME ZONE.",
      "object_kind": "column",
      "object_name": "o_entry_d",
      "severity": "info",
      "suggestion": "Scaffold emits `pg.Col[pg.Timestamp]` automatically.",
      "table": "orders"
    }
  ],
  "ignored_tables": [],
  "migratable": true,
  "schema": "public",
  "table_count": 9,
  "type_table_candidates": [],
  "unmanaged_objects": {
    "extensions": [],
    "indexes": [],
    "rls_policies": [],
    "routines": [],
    "triggers": [],
    "views": []
  },
  "workflow_steps": [
    {
      "detail": "Run `pgdorm scaffold` and `pgdorm adopt-plan` (use `execute_plan_tx` inside a psycopg3 transaction when recreating views/functions atomically).",
      "order": 1,
      "phase": "ddl",
      "summary": "Scaffold models, review AdoptionMap, and execute transactional DDL"
    },
    {
      "detail": "Run `finalize_external()` or `pgdorm upgrade`, then verify `pgdorm drift`.",
      "order": 2,
      "phase": "post_commit",
      "summary": "Run CONCURRENTLY indexes, VALIDATE constraints, and record ledger"
    }
  ]
}

3. Zero-DDL Bind Models (pgdorm scaffold --mode bind)#

Composite PK order is preserved verbatim via pk_order=(...), and every composite FK, character(N), and numeric(p,s) column round-trips with zero pending operations.

Generated by pgdorm scaffold --mode bind · tests/integration/migrations/corpora/02_tpcc_derived/__captured__/bind_models.py.txt
from decimal import Decimal
from typing import Annotated

import pgdorm as pg
import pgdorm.migrate as pgm


class Item(pg.Table, strict_pk=False):
    i_id: pg.Col[pg.Int4] = pg.pk()
    i_im_id: pg.Col[pg.Int4 | None] = pg.col(default=None)
    i_name: pg.Col[str | None] = pg.col(max_len=24, default=None)
    i_price: pg.Col[Decimal | None] = pg.col(precision=5, scale=2, default=None)
    i_data: pg.Col[str | None] = pg.col(max_len=50, default=None)


class Warehouse(pg.Table, strict_pk=False):
    w_id: pg.Col[pg.Int2] = pg.pk()
    w_name: pg.Col[str | None] = pg.col(max_len=10, default=None)
    w_street_1: pg.Col[str | None] = pg.col(max_len=20, default=None)
    w_street_2: pg.Col[str | None] = pg.col(max_len=20, default=None)
    w_city: pg.Col[str | None] = pg.col(max_len=20, default=None)
    w_state: pg.Col[Annotated[str, pg.CustomType(pg_type='character(2)')] | None] = pg.col(default=None)
    w_zip: pg.Col[Annotated[str, pg.CustomType(pg_type='character(9)')] | None] = pg.col(default=None)
    w_tax: pg.Col[Decimal | None] = pg.col(precision=4, scale=4, default=None)
    w_ytd: pg.Col[Decimal | None] = pg.col(precision=12, scale=2, default=None)


class District(pg.Table, strict_pk=False):
    d_id: pg.Col[pg.Int2]
    d_w_id: pg.Col[pg.Int2]
    d_name: pg.Col[str | None] = pg.col(max_len=10, default=None)
    d_street_1: pg.Col[str | None] = pg.col(max_len=20, default=None)
    d_street_2: pg.Col[str | None] = pg.col(max_len=20, default=None)
    d_city: pg.Col[str | None] = pg.col(max_len=20, default=None)
    d_state: pg.Col[Annotated[str, pg.CustomType(pg_type='character(2)')] | None] = pg.col(default=None)
    d_zip: pg.Col[Annotated[str, pg.CustomType(pg_type='character(9)')] | None] = pg.col(default=None)
    d_tax: pg.Col[Decimal | None] = pg.col(precision=4, scale=4, default=None)
    d_ytd: pg.Col[Decimal | None] = pg.col(precision=12, scale=2, default=None)
    d_next_o_id: pg.Col[pg.Int4 | None] = pg.col(default=None)

    @classmethod
    def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
        return (
            pg.PrimaryKey(cls.d_w_id, cls.d_id),
            pg.ForeignKey((cls.d_w_id,), (Warehouse.w_id,)),
        )


class Customer(pg.Table, strict_pk=False):
    c_id: pg.Col[pg.Int4]
    c_d_id: pg.Col[pg.Int2]
    c_w_id: pg.Col[pg.Int2]
    c_first: pg.Col[str | None] = pg.col(max_len=16, default=None)
    c_middle: pg.Col[Annotated[str, pg.CustomType(pg_type='character(2)')] | None] = pg.col(default=None)
    c_last: pg.Col[str | None] = pg.col(max_len=16, default=None)
    c_street_1: pg.Col[str | None] = pg.col(max_len=20, default=None)
    c_street_2: pg.Col[str | None] = pg.col(max_len=20, default=None)
    c_city: pg.Col[str | None] = pg.col(max_len=20, default=None)
    c_state: pg.Col[Annotated[str, pg.CustomType(pg_type='character(2)')] | None] = pg.col(default=None)
    c_zip: pg.Col[Annotated[str, pg.CustomType(pg_type='character(9)')] | None] = pg.col(default=None)
    c_phone: pg.Col[Annotated[str, pg.CustomType(pg_type='character(16)')] | None] = pg.col(default=None)
    c_since: pg.Col[pg.Timestamp | None] = pg.col(default=None)
    c_credit: pg.Col[Annotated[str, pg.CustomType(pg_type='character(2)')] | None] = pg.col(default=None)
    c_credit_lim: pg.Col[Decimal | None] = pg.col(precision=12, scale=2, default=None)
    c_discount: pg.Col[Decimal | None] = pg.col(precision=4, scale=4, default=None)
    c_balance: pg.Col[Decimal | None] = pg.col(precision=12, scale=2, default=None)
    c_ytd_payment: pg.Col[Decimal | None] = pg.col(precision=12, scale=2, default=None)
    c_payment_cnt: pg.Col[pg.Int2 | None] = pg.col(default=None)
    c_delivery_cnt: pg.Col[pg.Int2 | None] = pg.col(default=None)
    c_data: pg.Col[str | None] = pg.col(max_len=500, default=None)

    @classmethod
    def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
        return (
            pg.PrimaryKey(cls.c_w_id, cls.c_d_id, cls.c_id),
            pg.ForeignKey((cls.c_w_id, cls.c_d_id), (District.d_w_id, District.d_id)),
            pg.Index(cls.c_w_id, cls.c_d_id, cls.c_last, cls.c_first),
        )


class History(pg.Table, strict_pk=False):
    h_c_id: pg.Col[pg.Int4 | None] = pg.col(default=None)
    h_c_d_id: pg.Col[pg.Int2 | None] = pg.col(default=None)
    h_c_w_id: pg.Col[pg.Int2 | None] = pg.col(default=None)
    h_d_id: pg.Col[pg.Int2 | None] = pg.col(default=None)
    h_w_id: pg.Col[pg.Int2 | None] = pg.col(default=None)
    h_date: pg.Col[pg.Timestamp | None] = pg.col(default=None)
    h_amount: pg.Col[Decimal | None] = pg.col(precision=6, scale=2, default=None)
    h_data: pg.Col[str | None] = pg.col(max_len=24, default=None)

    @classmethod
    def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
        return (
            pg.ForeignKey((cls.h_c_w_id, cls.h_c_d_id, cls.h_c_id), (Customer.c_w_id, Customer.c_d_id, Customer.c_id), auto_index=False),
            pg.ForeignKey((cls.h_w_id, cls.h_d_id), (District.d_w_id, District.d_id), auto_index=False),
        )


class Orders(pg.Table, strict_pk=False):
    o_id: pg.Col[pg.Int4]
    o_d_id: pg.Col[pg.Int2]
    o_w_id: pg.Col[pg.Int2]
    o_c_id: pg.Col[pg.Int4 | None] = pg.col(default=None)
    o_entry_d: pg.Col[pg.Timestamp | None] = pg.col(default=None)
    o_carrier_id: pg.Col[pg.Int2 | None] = pg.col(default=None)
    o_ol_cnt: pg.Col[pg.Int2 | None] = pg.col(default=None)
    o_all_local: pg.Col[pg.Int2 | None] = pg.col(default=None)

    @classmethod
    def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
        return (
            pg.PrimaryKey(cls.o_w_id, cls.o_d_id, cls.o_id),
            pg.ForeignKey((cls.o_w_id, cls.o_d_id, cls.o_c_id), (Customer.c_w_id, Customer.c_d_id, Customer.c_id), auto_index=False),
        )


class NewOrder(pg.Table, strict_pk=False):
    no_o_id: pg.Col[pg.Int4]
    no_d_id: pg.Col[pg.Int2]
    no_w_id: pg.Col[pg.Int2]

    @classmethod
    def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
        return (
            pg.PrimaryKey(cls.no_w_id, cls.no_d_id, cls.no_o_id),
            pg.ForeignKey((cls.no_w_id, cls.no_d_id, cls.no_o_id), (Orders.o_w_id, Orders.o_d_id, Orders.o_id)),
        )


class Stock(pg.Table, strict_pk=False):
    s_i_id: pg.Col[pg.Int4]
    s_w_id: pg.Col[pg.Int2]
    s_quantity: pg.Col[pg.Int2 | None] = pg.col(default=None)
    s_dist_01: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_dist_02: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_dist_03: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_dist_04: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_dist_05: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_dist_06: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_dist_07: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_dist_08: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_dist_09: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_dist_10: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)
    s_ytd: pg.Col[Decimal | None] = pg.col(precision=8, default=None)
    s_order_cnt: pg.Col[pg.Int2 | None] = pg.col(default=None)
    s_remote_cnt: pg.Col[pg.Int2 | None] = pg.col(default=None)
    s_data: pg.Col[str | None] = pg.col(max_len=50, default=None)

    @classmethod
    def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
        return (
            pg.PrimaryKey(cls.s_w_id, cls.s_i_id),
            pg.ForeignKey((cls.s_i_id,), (Item.i_id,), auto_index=False),
            pg.ForeignKey((cls.s_w_id,), (Warehouse.w_id,)),
        )


class OrderLine(pg.Table, strict_pk=False):
    ol_o_id: pg.Col[pg.Int4]
    ol_d_id: pg.Col[pg.Int2]
    ol_w_id: pg.Col[pg.Int2]
    ol_number: pg.Col[pg.Int2]
    ol_i_id: pg.Col[pg.Int4 | None] = pg.col(default=None)
    ol_supply_w_id: pg.Col[pg.Int2 | None] = pg.col(default=None)
    ol_delivery_d: pg.Col[pg.Timestamp | None] = pg.col(default=None)
    ol_quantity: pg.Col[pg.Int2 | None] = pg.col(default=None)
    ol_amount: pg.Col[Decimal | None] = pg.col(precision=6, scale=2, default=None)
    ol_dist_info: pg.Col[Annotated[str, pg.CustomType(pg_type='character(24)')] | None] = pg.col(default=None)

    @classmethod
    def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
        return (
            pg.PrimaryKey(cls.ol_w_id, cls.ol_d_id, cls.ol_o_id, cls.ol_number),
            pg.ForeignKey((cls.ol_supply_w_id, cls.ol_i_id), (Stock.s_w_id, Stock.s_i_id), auto_index=False),
            pg.ForeignKey((cls.ol_w_id, cls.ol_d_id, cls.ol_o_id), (Orders.o_w_id, Orders.o_d_id, Orders.o_id)),
        )


ADOPTION_MAP = pgm.AdoptionMap(
)


APP = pgm.MigrationApp(tables=(Item, Warehouse, District, Customer, History, Orders, NewOrder, Stock, OrderLine))