Corpus 01 · pgbench (PostgreSQL TPC-B-Like)#
← All Assimilation Pathways · Live test suite: tests/integration/migrations/corpora/test_corpora.py
PostgreSQL ships pgbench as its built-in TPC-B-like workload: four tables (pgbench_branches, pgbench_tellers, pgbench_accounts, pgbench_history) with INT4 keys (bid, tid, aid), fixed-width character(84) / character(22) padding columns, and a keyless pgbench_history append log.
Because external pgbench clients query pgbench_accounts, pgbench_tellers, pgbench_branches, and pgbench_history directly by name, this corpus demonstrates why zero-DDL --mode bind matters:
| Verification Rung | Mode | Result on Live PostgreSQL |
|---|---|---|
Catalog audit (audit-schema) |
Read-only | ✅ migratable=True |
Zero-DDL bind (scaffold --mode bind) |
Bind-as-is | ✅ plan_migration().ops == () |
Live 1-RTT TPC-B-like transaction (tx.pipeline(commit=True)) |
Bind-as-is | ✅ 1 RTT, external SQL still works |
Full assimilation (scaffold --mode assimilate) |
Assimilate | ✅ Atomic 1-tx, plan_migration().ops == () |
1. Source Schema#
-- PostgreSQL pgbench schema (pgbench -i --foreign-keys).
-- Licence: PostgreSQL License (ships with PostgreSQL).
CREATE TABLE pgbench_branches (
bid integer NOT NULL,
bbalance integer,
filler character(88),
PRIMARY KEY (bid)
);
CREATE TABLE pgbench_tellers (
tid integer NOT NULL,
bid integer REFERENCES pgbench_branches(bid),
tbalance integer,
filler character(84),
PRIMARY KEY (tid)
);
CREATE TABLE pgbench_accounts (
aid integer NOT NULL,
bid integer REFERENCES pgbench_branches(bid),
abalance integer,
filler character(84),
PRIMARY KEY (aid)
);
CREATE TABLE pgbench_history (
tid integer REFERENCES pgbench_tellers(tid),
bid integer REFERENCES pgbench_branches(bid),
aid integer REFERENCES pgbench_accounts(aid),
delta integer,
mtime timestamp without time zone,
filler character(22)
);
2. Live Catalog Audit#
- FK 'pgbench_accounts_bid_fkey' on pgbench_accounts(bid) has no covering B-tree index.
- FK 'pgbench_history_aid_fkey' on pgbench_history(aid) has no covering B-tree index.
- FK 'pgbench_history_bid_fkey' on pgbench_history(bid) has no covering B-tree index.
- FK 'pgbench_history_tid_fkey' on pgbench_history(tid) has no covering B-tree index.
- FK 'pgbench_tellers_bid_fkey' on pgbench_tellers(bid) has no covering B-tree index.
- Table 'pgbench_accounts' appears plural; assimilate to singular snake_case.
- Table 'pgbench_branches' appears plural; assimilate to singular snake_case.
- Table 'pgbench_tellers' appears plural; assimilate to singular snake_case.
- Table 'pgbench_accounts' PK is 'aid' instead of 'pgbench_accounts_id'.
- Table 'pgbench_branches' PK is 'bid' instead of 'pgbench_branches_id'.
- Table 'pgbench_history' has no primary key.
- Table 'pgbench_tellers' PK is 'tid' instead of 'pgbench_tellers_id'.
- Column pgbench_history.mtime uses TIMESTAMP WITHOUT TIME ZONE.
Inspect raw machine-readable audit JSON (tests/integration/migrations/corpora/01_pgbench/captured/audit.json)
{
"counts": {
"blocker": 0,
"info": 1,
"migration_required": 12,
"unmanaged": 0
},
"findings": [
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'pgbench_accounts_bid_fkey' on pgbench_accounts(bid) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "pgbench_accounts_bid_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "pgbench_accounts"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'pgbench_history_aid_fkey' on pgbench_history(aid) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "pgbench_history_aid_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "pgbench_history"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'pgbench_history_bid_fkey' on pgbench_history(bid) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "pgbench_history_bid_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "pgbench_history"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'pgbench_history_tid_fkey' on pgbench_history(tid) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "pgbench_history_tid_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "pgbench_history"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'pgbench_tellers_bid_fkey' on pgbench_tellers(bid) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "pgbench_tellers_bid_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "pgbench_tellers"
},
{
"auto_fixable": true,
"category": "naming",
"code": "TABLE_NAME_PLURAL",
"doc_anchor": "table-naming",
"message": "Table 'pgbench_accounts' appears plural; assimilate to singular snake_case.",
"object_kind": "table",
"object_name": "pgbench_accounts",
"severity": "migration_required",
"suggestion": "Rename table to singular snake_case via AdoptionMap.",
"table": "pgbench_accounts"
},
{
"auto_fixable": true,
"category": "naming",
"code": "TABLE_NAME_PLURAL",
"doc_anchor": "table-naming",
"message": "Table 'pgbench_branches' appears plural; assimilate to singular snake_case.",
"object_kind": "table",
"object_name": "pgbench_branches",
"severity": "migration_required",
"suggestion": "Rename table to singular snake_case via AdoptionMap.",
"table": "pgbench_branches"
},
{
"auto_fixable": true,
"category": "naming",
"code": "TABLE_NAME_PLURAL",
"doc_anchor": "table-naming",
"message": "Table 'pgbench_tellers' appears plural; assimilate to singular snake_case.",
"object_kind": "table",
"object_name": "pgbench_tellers",
"severity": "migration_required",
"suggestion": "Rename table to singular snake_case via AdoptionMap.",
"table": "pgbench_tellers"
},
{
"auto_fixable": true,
"category": "primary_key",
"code": "PK_NAME_MISMATCH",
"doc_anchor": "primary-keys-and-serials",
"message": "Table 'pgbench_accounts' PK is 'aid' instead of 'pgbench_accounts_id'.",
"object_kind": "primary_key",
"object_name": "aid",
"severity": "migration_required",
"suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
"table": "pgbench_accounts"
},
{
"auto_fixable": true,
"category": "primary_key",
"code": "PK_NAME_MISMATCH",
"doc_anchor": "primary-keys-and-serials",
"message": "Table 'pgbench_branches' PK is 'bid' instead of 'pgbench_branches_id'.",
"object_kind": "primary_key",
"object_name": "bid",
"severity": "migration_required",
"suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
"table": "pgbench_branches"
},
{
"auto_fixable": true,
"category": "primary_key",
"code": "PK_MISSING",
"doc_anchor": "primary-keys-and-serials",
"message": "Table 'pgbench_history' has no primary key.",
"object_kind": "primary_key",
"object_name": "pgbench_history",
"severity": "migration_required",
"suggestion": "Add `<table_name>_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY`.",
"table": "pgbench_history"
},
{
"auto_fixable": true,
"category": "primary_key",
"code": "PK_NAME_MISMATCH",
"doc_anchor": "primary-keys-and-serials",
"message": "Table 'pgbench_tellers' PK is 'tid' instead of 'pgbench_tellers_id'.",
"object_kind": "primary_key",
"object_name": "tid",
"severity": "migration_required",
"suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
"table": "pgbench_tellers"
},
{
"auto_fixable": false,
"category": "types",
"code": "TIMESTAMP_WITHOUT_TZ",
"doc_anchor": "column-types",
"message": "Column pgbench_history.mtime uses TIMESTAMP WITHOUT TIME ZONE.",
"object_kind": "column",
"object_name": "mtime",
"severity": "info",
"suggestion": "Scaffold emits `pg.Col[pg.Timestamp]` automatically.",
"table": "pgbench_history"
}
],
"ignored_tables": [],
"migratable": true,
"schema": "public",
"table_count": 4,
"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)#
Every column type (including CustomType(pg_type='character(84)')), bare key (strict_pk=False), and keyless append table binds to PostgreSQL with zero DDL and zero drift (plan_migration().ops == ()).
from typing import Annotated
import pgdorm as pg
import pgdorm.migrate as pgm
class PgbenchBranches(pg.Table, strict_pk=False):
bid: pg.Col[pg.Int4] = pg.pk()
bbalance: pg.Col[pg.Int4 | None] = pg.col(default=None)
filler: pg.Col[Annotated[str, pg.CustomType(pg_type='character(88)')] | None] = pg.col(default=None)
class PgbenchAccounts(pg.Table, strict_pk=False):
aid: pg.Col[pg.Int4] = pg.pk()
bid: pg.Col[pg.Int4 | None] = pg.fk(PgbenchBranches, auto_index=False, default=None)
abalance: pg.Col[pg.Int4 | None] = pg.col(default=None)
filler: pg.Col[Annotated[str, pg.CustomType(pg_type='character(84)')] | None] = pg.col(default=None)
class PgbenchTellers(pg.Table, strict_pk=False):
tid: pg.Col[pg.Int4] = pg.pk()
bid: pg.Col[pg.Int4 | None] = pg.fk(PgbenchBranches, auto_index=False, default=None)
tbalance: pg.Col[pg.Int4 | None] = pg.col(default=None)
filler: pg.Col[Annotated[str, pg.CustomType(pg_type='character(84)')] | None] = pg.col(default=None)
class PgbenchHistory(pg.Table, strict_pk=False):
tid: pg.Col[pg.Int4 | None] = pg.fk(PgbenchTellers, auto_index=False, default=None)
bid: pg.Col[pg.Int4 | None] = pg.fk(PgbenchBranches, auto_index=False, default=None)
aid: pg.Col[pg.Int4 | None] = pg.fk(PgbenchAccounts, auto_index=False, default=None)
delta: pg.Col[pg.Int4 | None] = pg.col(default=None)
mtime: pg.Col[pg.Timestamp | None] = pg.col(default=None)
filler: pg.Col[Annotated[str, pg.CustomType(pg_type='character(22)')] | None] = pg.col(default=None)
ADOPTION_MAP = pgm.AdoptionMap(
)
APP = pgm.MigrationApp(tables=(PgbenchBranches, PgbenchAccounts, PgbenchTellers, PgbenchHistory))