Skip to content

Assimilating Piccolo ORM#

← Assimilation hub · Live test fixture: frameworks/06_piccolo/

Piccolo ORM schemas are already halfway to pgdorm's conventions — with four distinct traits worth knowing before cutover:

  1. Already-singular snake_case table names: Piccolo derives singular table names (account, order, tag, order_tag) automatically, so zero ordinary entity tables need renaming — only order_status renames to order_status_type when promoted to a pg.TypeTable.
  2. Piccolo migration table (migration): Pass --ignore-table migration so Piccolo's migration ledger stays completely untouched.
  3. Naive TIMESTAMP WITHOUT TIME ZONE by default: Piccolo's Timestamp() column maps to TIMESTAMP WITHOUT TIME ZONE (whereas Timestamptz() opts into timezone-aware timestamps). audit-schema flags TIMESTAMP_WITHOUT_TZ and pgdorm scaffold binds those columns cleanly to pg.Timestamp with zero column rewrites.
  4. Implicit id SERIAL PKs & unindexed FKs: Every Piccolo table carries an implicit id SERIAL PRIMARY KEY, and ForeignKey(...) omits indexes unless index=True is set. pgdorm renames id → <table_name>_id (preserving INT4 SERIAL) and adds every missing FK index online CONCURRENTLY.

1. Before & After — Table-by-Table Schema Comparison#

Run pgdorm scaffold while ignoring Piccolo's migration table:

pgdorm --dsn "$DATABASE_URL" --ignore-table migration \
  scaffold --type-table order_status --out app/models.py

Every original Piccolo Table class lines up directly beside its scaffolded pgdorm class below:

Imports & base setup
from piccolo.columns import Boolean, ForeignKey, Numeric, Timestamp, Varchar
from piccolo.table import Table
from decimal import Decimal
from enum import IntEnum
import pgdorm as pg
import pgdorm.migrate as pgm
order_status → order_status_type
TypeTable + IntEnumid → order_status_type_id
class OrderStatus(Table, tablename="order_status"):
    code = Varchar(length=32, unique=True)
class OrderStatusKind(IntEnum):
    PENDING = 1
    PAID = 2
    CANCELLED = 3


class OrderStatusType(pg.TypeTable, enum=OrderStatusKind):
    order_status_type_id: pg.Col[OrderStatusKind] = pg.pk()
account
SERIAL → IDENTITYid → account_id
class Account(Table, tablename="account"):
    email = Varchar(length=120, unique=True)
    is_active = Boolean(default=True)
    created_at = Timestamp()
class Account(pg.Table):
    account_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
    email: pg.Col[str] = pg.col(max_len=120, unique=True)
    is_active: pg.Col[bool] = pg.col(default=True)
    created_at: pg.Col[pg.Timestamp] = pg.col(default=pg.now())
order
SERIAL → IDENTITYid → order_id
class Order(Table, tablename="order"):
    account_id = ForeignKey(references=Account)
    status_id = ForeignKey(references=OrderStatus)
    total_eur = Numeric(digits=(10, 2), default=0)
    placed_at = Timestamp()
class Order(pg.Table):
    order_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
    account_id: pg.Col[pg.Int4] = pg.fk(Account, on_delete=pg.enums.OnDelete.CASCADE)
    status_id: pg.Col[pg.Int4] = pg.fk(OrderStatusType)
    total_eur: pg.Col[Decimal] = pg.col(precision=10, scale=2, default=Decimal('0.00'))
    placed_at: pg.Col[pg.Timestamp] = pg.col(default=pg.now())
tag
SERIAL → IDENTITYid → tag_id
class Tag(Table, tablename="tag"):
    name = Varchar(length=64, unique=True)
class Tag(pg.Table):
    tag_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
    name: pg.Col[str] = pg.col(max_len=64, unique=True)
order_tag
SERIAL → IDENTITYid → order_tag_id
class OrderTag(Table, tablename="order_tag"):
    order_id = ForeignKey(references=Order)
    tag_id = ForeignKey(references=Tag)
class OrderTag(pg.Table):
    order_tag_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
    order_id: pg.Col[pg.Int4] = pg.fk(Order, on_delete=pg.enums.OnDelete.CASCADE)
    tag_id: pg.Col[pg.Int4] = pg.fk(Tag, on_delete=pg.enums.OnDelete.CASCADE)

    @classmethod
    def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
        return (
            pg.Unique(cls.order_id, cls.tag_id),
        )
Ignored framework tables
--ignore-tablePreserved untouched
CREATE TABLE migration (
    id SERIAL NOT NULL PRIMARY KEY,
    name VARCHAR(200) NOT NULL,
    ran_on TIMESTAMPTZ NOT NULL DEFAULT now()
);

Left completely untouched via ignore_tables (migration). Never audited, renamed, or dropped by pgdorm.migrate — even when a legacy table name ends in _type.

Generated by pgdorm scaffold · tests/integration/migrations/onboarding/frameworks/06_piccolo/__captured__/scaffold.py.txt
from decimal import Decimal
from enum import IntEnum

import pgdorm as pg
import pgdorm.migrate as pgm


class OrderStatusKind(IntEnum):
    PENDING = 1
    PAID = 2
    CANCELLED = 3


class OrderStatusType(pg.TypeTable, enum=OrderStatusKind):
    order_status_type_id: pg.Col[OrderStatusKind] = pg.pk()


class Account(pg.Table):
    account_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
    email: pg.Col[str] = pg.col(max_len=120, unique=True)
    is_active: pg.Col[bool] = pg.col(default=True)
    created_at: pg.Col[pg.Timestamp] = pg.col(default=pg.now())


class Order(pg.Table):
    order_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
    account_id: pg.Col[pg.Int4] = pg.fk(Account, on_delete=pg.enums.OnDelete.CASCADE)
    status_id: pg.Col[pg.Int4] = pg.fk(OrderStatusType)
    total_eur: pg.Col[Decimal] = pg.col(precision=10, scale=2, default=Decimal('0.00'))
    placed_at: pg.Col[pg.Timestamp] = pg.col(default=pg.now())


class Tag(pg.Table):
    tag_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
    name: pg.Col[str] = pg.col(max_len=64, unique=True)


class OrderTag(pg.Table):
    order_tag_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
    order_id: pg.Col[pg.Int4] = pg.fk(Order, on_delete=pg.enums.OnDelete.CASCADE)
    tag_id: pg.Col[pg.Int4] = pg.fk(Tag, on_delete=pg.enums.OnDelete.CASCADE)

    @classmethod
    def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
        return (
            pg.Unique(cls.order_id, cls.tag_id),
        )


ADOPTION_MAP = pgm.AdoptionMap(
    tables={
        'account': pgm.TableMapping(target='account', columns={'id': 'account_id'}, pk_strategy=pgm.enums.PkStrategy.RENAME, migrate_serial_to_identity=True),
        'order': pgm.TableMapping(target='order', columns={'id': 'order_id'}, pk_strategy=pgm.enums.PkStrategy.RENAME, migrate_serial_to_identity=True),
        'order_status': pgm.TableMapping(target='order_status_type', columns={'id': 'order_status_type_id'}, as_type_table=True, pk_strategy=pgm.enums.PkStrategy.RENAME),
        'order_tag': pgm.TableMapping(target='order_tag', columns={'id': 'order_tag_id'}, pk_strategy=pgm.enums.PkStrategy.RENAME, migrate_serial_to_identity=True),
        'tag': pgm.TableMapping(target='tag', columns={'id': 'tag_id'}, pk_strategy=pgm.enums.PkStrategy.RENAME, migrate_serial_to_identity=True),
    },
    ignore_tables=frozenset({'migration'}),
)


APP = pgm.MigrationApp(tables=(OrderStatusType, Account, Order, Tag, OrderTag), ignore_tables=frozenset({'migration'}))
tests/integration/migrations/onboarding/frameworks/06_piccolo/source.py.txt
from piccolo.columns import Boolean, ForeignKey, Numeric, Timestamp, Varchar
from piccolo.table import Table


class OrderStatus(Table, tablename="order_status"):
    code = Varchar(length=32, unique=True)


class Account(Table, tablename="account"):
    email = Varchar(length=120, unique=True)
    is_active = Boolean(default=True)
    created_at = Timestamp()


class Tag(Table, tablename="tag"):
    name = Varchar(length=64, unique=True)


class Order(Table, tablename="order"):
    account_id = ForeignKey(references=Account)
    status_id = ForeignKey(references=OrderStatus)
    total_eur = Numeric(digits=(10, 2), default=0)
    placed_at = Timestamp()


class OrderTag(Table, tablename="order_tag"):
    order_id = ForeignKey(references=Order)
    tag_id = ForeignKey(references=Tag)
tests/integration/migrations/onboarding/frameworks/06_piccolo/schema.sql
CREATE TABLE migration (
    id SERIAL NOT NULL PRIMARY KEY,
    name VARCHAR(200) NOT NULL,
    ran_on TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE order_status (
    id SERIAL NOT NULL PRIMARY KEY,
    code VARCHAR(32) NOT NULL UNIQUE
);

CREATE TABLE account (
    id SERIAL NOT NULL PRIMARY KEY,
    email VARCHAR(120) NOT NULL UNIQUE,
    is_active BOOLEAN NOT NULL DEFAULT true,
    created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now()
);

CREATE TABLE tag (
    id SERIAL NOT NULL PRIMARY KEY,
    name VARCHAR(64) NOT NULL UNIQUE
);

CREATE TABLE "order" (
    id SERIAL NOT NULL PRIMARY KEY,
    account_id INTEGER NOT NULL REFERENCES account(id) ON DELETE CASCADE,
    status_id INTEGER NOT NULL REFERENCES order_status(id),
    total_eur NUMERIC(10, 2) NOT NULL DEFAULT 0.00,
    placed_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now()
);

CREATE TABLE order_tag (
    id SERIAL NOT NULL PRIMARY KEY,
    order_id INTEGER NOT NULL REFERENCES "order"(id) ON DELETE CASCADE,
    tag_id INTEGER NOT NULL REFERENCES tag(id) ON DELETE CASCADE,
    UNIQUE (order_id, tag_id)
);
tests/integration/migrations/onboarding/frameworks/06_piccolo/seed.sql
INSERT INTO migration (name) VALUES ('2026-11-28T12:00:00:000000');
INSERT INTO order_status (id, code) VALUES (1, 'pending'), (2, 'paid'), (3, 'cancelled');
INSERT INTO account (email) VALUES ('[email protected]');
INSERT INTO tag (name) VALUES ('piccolo');
INSERT INTO "order" (account_id, status_id, total_eur) VALUES (1, 1, 64.00);
INSERT INTO order_tag (order_id, tag_id) VALUES (1, 1);

2. Live catalog audit#

Notice zero TABLE_NAME_PLURAL findings — only PK renames, SERIAL metadata, naive TIMESTAMP_WITHOUT_TZ info notices, and unindexed FKs.

migratable · exit 0
8 migration10 info
  • MIGRATIONUNINDEXED_FK
    order · order_account_id_fkey
    FK 'order_account_id_fkey' on order(account_id) has no covering B-tree index.
  • MIGRATIONUNINDEXED_FK
    order · order_status_id_fkey
    FK 'order_status_id_fkey' on order(status_id) has no covering B-tree index.
  • MIGRATIONUNINDEXED_FK
    order_tag · order_tag_tag_id_fkey
    FK 'order_tag_tag_id_fkey' on order_tag(tag_id) has no covering B-tree index.
  • MIGRATIONPK_NAME_MISMATCH
    account · id
    Table 'account' PK is 'id' instead of 'account_id'.
  • MIGRATIONPK_NAME_MISMATCH
    order · id
    Table 'order' PK is 'id' instead of 'order_id'.
  • MIGRATIONPK_NAME_MISMATCH
    order_status · id
    Table 'order_status' PK is 'id' instead of 'order_status_id'.
  • MIGRATIONPK_NAME_MISMATCH
    order_tag · id
    Table 'order_tag' PK is 'id' instead of 'order_tag_id'.
  • MIGRATIONPK_NAME_MISMATCH
    tag · id
    Table 'tag' PK is 'id' instead of 'tag_id'.
  • INFOSERIAL_COLUMN
    account · id
    Column account.id uses owned SERIAL sequence default (nextval('account_id_seq'::regclass)).
  • INFOSERIAL_COLUMN
    order · id
    Column order.id uses owned SERIAL sequence default (nextval('order_id_seq'::regclass)).
  • INFOSERIAL_COLUMN
    order_status · id
    Column order_status.id uses owned SERIAL sequence default (nextval('order_status_id_seq'::regclass)).
  • INFOSERIAL_COLUMN
    order_tag · id
    Column order_tag.id uses owned SERIAL sequence default (nextval('order_tag_id_seq'::regclass)).
  • INFOSERIAL_COLUMN
    tag · id
    Column tag.id uses owned SERIAL sequence default (nextval('tag_id_seq'::regclass)).
  • INFOTYPE_TABLE_CANDIDATE
    account
    Table 'account' looks like a lookup table (Single integer PK + unique character varying(120) email, referenced by order.)
  • INFOTYPE_TABLE_CANDIDATE
    order_status
    Table 'order_status' looks like a lookup table (Single integer PK + unique character varying(32) code, referenced by order.)
  • INFOTYPE_TABLE_CANDIDATE
    tag
    Table 'tag' looks like a lookup table (Single integer PK + unique character varying(64) name, referenced by order_tag.)
  • INFOTIMESTAMP_WITHOUT_TZ
    account · created_at
    Column account.created_at uses TIMESTAMP WITHOUT TIME ZONE.
  • INFOTIMESTAMP_WITHOUT_TZ
    order · placed_at
    Column order.placed_at uses TIMESTAMP WITHOUT TIME ZONE.
Inspect raw machine-readable audit JSON (tests/integration/migrations/onboarding/frameworks/06_piccolo/captured/audit.json)
{
  "counts": {
    "blocker": 0,
    "info": 10,
    "migration_required": 8,
    "unmanaged": 0
  },
  "findings": [
    {
      "auto_fixable": true,
      "category": "indexes",
      "code": "UNINDEXED_FK",
      "doc_anchor": "constraints-and-indexes",
      "message": "FK 'order_account_id_fkey' on order(account_id) has no covering B-tree index.",
      "object_kind": "foreign_key",
      "object_name": "order_account_id_fkey",
      "severity": "migration_required",
      "suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
      "table": "order"
    },
    {
      "auto_fixable": true,
      "category": "indexes",
      "code": "UNINDEXED_FK",
      "doc_anchor": "constraints-and-indexes",
      "message": "FK 'order_status_id_fkey' on order(status_id) has no covering B-tree index.",
      "object_kind": "foreign_key",
      "object_name": "order_status_id_fkey",
      "severity": "migration_required",
      "suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
      "table": "order"
    },
    {
      "auto_fixable": true,
      "category": "indexes",
      "code": "UNINDEXED_FK",
      "doc_anchor": "constraints-and-indexes",
      "message": "FK 'order_tag_tag_id_fkey' on order_tag(tag_id) has no covering B-tree index.",
      "object_kind": "foreign_key",
      "object_name": "order_tag_tag_id_fkey",
      "severity": "migration_required",
      "suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
      "table": "order_tag"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_NAME_MISMATCH",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'account' PK is 'id' instead of 'account_id'.",
      "object_kind": "primary_key",
      "object_name": "id",
      "severity": "migration_required",
      "suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
      "table": "account"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_NAME_MISMATCH",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'order' PK is 'id' instead of 'order_id'.",
      "object_kind": "primary_key",
      "object_name": "id",
      "severity": "migration_required",
      "suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
      "table": "order"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_NAME_MISMATCH",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'order_status' PK is 'id' instead of 'order_status_id'.",
      "object_kind": "primary_key",
      "object_name": "id",
      "severity": "migration_required",
      "suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
      "table": "order_status"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_NAME_MISMATCH",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'order_tag' PK is 'id' instead of 'order_tag_id'.",
      "object_kind": "primary_key",
      "object_name": "id",
      "severity": "migration_required",
      "suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
      "table": "order_tag"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "PK_NAME_MISMATCH",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Table 'tag' PK is 'id' instead of 'tag_id'.",
      "object_kind": "primary_key",
      "object_name": "id",
      "severity": "migration_required",
      "suggestion": "Rename single int/UUID PK to `<table_name>_id`, or add surrogate PK.",
      "table": "tag"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "SERIAL_COLUMN",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Column account.id uses owned SERIAL sequence default (nextval('account_id_seq'::regclass)).",
      "object_kind": "column",
      "object_name": "id",
      "severity": "info",
      "suggestion": "Assimilate upgrades SERIAL PKs to IDENTITY; bind uses `server_managed=True`.",
      "table": "account"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "SERIAL_COLUMN",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Column order.id uses owned SERIAL sequence default (nextval('order_id_seq'::regclass)).",
      "object_kind": "column",
      "object_name": "id",
      "severity": "info",
      "suggestion": "Assimilate upgrades SERIAL PKs to IDENTITY; bind uses `server_managed=True`.",
      "table": "order"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "SERIAL_COLUMN",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Column order_status.id uses owned SERIAL sequence default (nextval('order_status_id_seq'::regclass)).",
      "object_kind": "column",
      "object_name": "id",
      "severity": "info",
      "suggestion": "Assimilate upgrades SERIAL PKs to IDENTITY; bind uses `server_managed=True`.",
      "table": "order_status"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "SERIAL_COLUMN",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Column order_tag.id uses owned SERIAL sequence default (nextval('order_tag_id_seq'::regclass)).",
      "object_kind": "column",
      "object_name": "id",
      "severity": "info",
      "suggestion": "Assimilate upgrades SERIAL PKs to IDENTITY; bind uses `server_managed=True`.",
      "table": "order_tag"
    },
    {
      "auto_fixable": true,
      "category": "primary_key",
      "code": "SERIAL_COLUMN",
      "doc_anchor": "primary-keys-and-serials",
      "message": "Column tag.id uses owned SERIAL sequence default (nextval('tag_id_seq'::regclass)).",
      "object_kind": "column",
      "object_name": "id",
      "severity": "info",
      "suggestion": "Assimilate upgrades SERIAL PKs to IDENTITY; bind uses `server_managed=True`.",
      "table": "tag"
    },
    {
      "auto_fixable": true,
      "category": "type_table",
      "code": "TYPE_TABLE_CANDIDATE",
      "doc_anchor": "type-table-namespace",
      "message": "Table 'account' looks like a lookup table (Single integer PK + unique character varying(120) `email`, referenced by order.)",
      "object_kind": "table",
      "object_name": "account",
      "severity": "info",
      "suggestion": "Review candidate; pass `--type-table <table>` or `as_type_table=True` to promote.",
      "table": "account"
    },
    {
      "auto_fixable": true,
      "category": "type_table",
      "code": "TYPE_TABLE_CANDIDATE",
      "doc_anchor": "type-table-namespace",
      "message": "Table 'order_status' looks like a lookup table (Single integer PK + unique character varying(32) `code`, referenced by order.)",
      "object_kind": "table",
      "object_name": "order_status",
      "severity": "info",
      "suggestion": "Review candidate; pass `--type-table <table>` or `as_type_table=True` to promote.",
      "table": "order_status"
    },
    {
      "auto_fixable": true,
      "category": "type_table",
      "code": "TYPE_TABLE_CANDIDATE",
      "doc_anchor": "type-table-namespace",
      "message": "Table 'tag' looks like a lookup table (Single integer PK + unique character varying(64) `name`, referenced by order_tag.)",
      "object_kind": "table",
      "object_name": "tag",
      "severity": "info",
      "suggestion": "Review candidate; pass `--type-table <table>` or `as_type_table=True` to promote.",
      "table": "tag"
    },
    {
      "auto_fixable": false,
      "category": "types",
      "code": "TIMESTAMP_WITHOUT_TZ",
      "doc_anchor": "column-types",
      "message": "Column account.created_at uses TIMESTAMP WITHOUT TIME ZONE.",
      "object_kind": "column",
      "object_name": "created_at",
      "severity": "info",
      "suggestion": "Scaffold emits `pg.Col[pg.Timestamp]` automatically.",
      "table": "account"
    },
    {
      "auto_fixable": false,
      "category": "types",
      "code": "TIMESTAMP_WITHOUT_TZ",
      "doc_anchor": "column-types",
      "message": "Column order.placed_at uses TIMESTAMP WITHOUT TIME ZONE.",
      "object_kind": "column",
      "object_name": "placed_at",
      "severity": "info",
      "suggestion": "Scaffold emits `pg.Col[pg.Timestamp]` automatically.",
      "table": "order"
    }
  ],
  "ignored_tables": [
    "migration"
  ],
  "migratable": true,
  "schema": "public",
  "table_count": 5,
  "type_table_candidates": [
    {
      "code_column": "email",
      "code_pg_type": "character varying(120)",
      "confidence": "medium",
      "pk_column": "id",
      "pk_pg_type": "integer",
      "reason": "Single integer PK + unique character varying(120) `email`, referenced by order.",
      "referencing_tables": [
        "order"
      ],
      "table": "account"
    },
    {
      "code_column": "code",
      "code_pg_type": "character varying(32)",
      "confidence": "high",
      "pk_column": "id",
      "pk_pg_type": "integer",
      "reason": "Single integer PK + unique character varying(32) `code`, referenced by order.",
      "referencing_tables": [
        "order"
      ],
      "table": "order_status"
    },
    {
      "code_column": "name",
      "code_pg_type": "character varying(64)",
      "confidence": "high",
      "pk_column": "id",
      "pk_pg_type": "integer",
      "reason": "Single integer PK + unique character varying(64) `name`, referenced by order_tag.",
      "referencing_tables": [
        "order_tag"
      ],
      "table": "tag"
    }
  ],
  "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. Compiled assimilation SQL#

Because account, order, tag, and order_tag already use singular names, Phase 2 is remarkably compact (only 7 metadata-only statements) and Phase 4 builds the three missing FK indexes CONCURRENTLY.

Generated by pgdorm adopt-plan --format sql · tests/integration/migrations/onboarding/frameworks/06_piccolo/__captured__/plan.sql
-- pgdorm Assimilation Plan: 0001_assimilate (06_piccolo)
-- Checksum: 34836e96838b7da74efce6f4167a14bbe48787c01925808636368faf9ce513b9
-- Ignored tables: migration
-- Preserved unmanaged objects: 0

-- ===========================================================================
-- PHASE 2 (TRANSACTIONAL DDL): Atomic pgdorm compiled schema assimilation
-- ===========================================================================
BEGIN;

-- (Optional PRE-DDL hook: DROP blocking views/matviews here)

-- [1] (ACCESS EXCLUSIVE) Rename table order_status -> order_status_type
ALTER TABLE "public"."order_status" RENAME TO "order_status_type";
-- [2] (ACCESS EXCLUSIVE) Rename column account.id -> account_id
ALTER TABLE "public"."account" RENAME COLUMN "id" TO "account_id";
-- [3] (ACCESS EXCLUSIVE) Rename column order.id -> order_id
ALTER TABLE "public"."order" RENAME COLUMN "id" TO "order_id";
-- [4] (ACCESS EXCLUSIVE) Rename column order_status_type.id -> order_status_type_id
ALTER TABLE "public"."order_status_type" RENAME COLUMN "id" TO "order_status_type_id";
-- [5] (ACCESS EXCLUSIVE) Rename column order_tag.id -> order_tag_id
ALTER TABLE "public"."order_tag" RENAME COLUMN "id" TO "order_tag_id";
-- [6] (ACCESS EXCLUSIVE) Rename column tag.id -> tag_id
ALTER TABLE "public"."tag" RENAME COLUMN "id" TO "tag_id";
-- [7] (ACCESS EXCLUSIVE) Drop default on account.account_id
ALTER TABLE "public"."account" ALTER COLUMN "account_id" DROP DEFAULT;
-- [8] (ACCESS EXCLUSIVE) Add identity on account.account_id
ALTER TABLE "public"."account" ALTER COLUMN "account_id" ADD GENERATED BY DEFAULT AS IDENTITY;
-- [9] (ACCESS EXCLUSIVE) Drop default on order.order_id
ALTER TABLE "public"."order" ALTER COLUMN "order_id" DROP DEFAULT;
-- [10] (ACCESS EXCLUSIVE) Add identity on order.order_id
ALTER TABLE "public"."order" ALTER COLUMN "order_id" ADD GENERATED BY DEFAULT AS IDENTITY;
-- [11] (ACCESS EXCLUSIVE) Drop default on order_status_type.order_status_type_id
ALTER TABLE "public"."order_status_type" ALTER COLUMN "order_status_type_id" DROP DEFAULT;
-- [12] (ACCESS EXCLUSIVE) Alter column type order_status_type.code -> text
ALTER TABLE "public"."order_status_type" ALTER COLUMN "code" TYPE TEXT;
-- [13] (ACCESS EXCLUSIVE) Drop default on order_tag.order_tag_id
ALTER TABLE "public"."order_tag" ALTER COLUMN "order_tag_id" DROP DEFAULT;
-- [14] (ACCESS EXCLUSIVE) Add identity on order_tag.order_tag_id
ALTER TABLE "public"."order_tag" ALTER COLUMN "order_tag_id" ADD GENERATED BY DEFAULT AS IDENTITY;
-- [15] (ACCESS EXCLUSIVE) Drop default on tag.tag_id
ALTER TABLE "public"."tag" ALTER COLUMN "tag_id" DROP DEFAULT;
-- [16] (ACCESS EXCLUSIVE) Add identity on tag.tag_id
ALTER TABLE "public"."tag" ALTER COLUMN "tag_id" ADD GENERATED BY DEFAULT AS IDENTITY;

COMMIT;

-- ===========================================================================
-- PHASE 4 (POST-COMMIT ONLINE / AUTOCOMMIT): CONCURRENTLY & VALIDATE steps
-- Run outside any BEGIN ... COMMIT block (or call pgm.finalize_external()).
-- ===========================================================================
-- [post-1] (SHARE UPDATE EXCLUSIVE) Create index ix_gmxltmzo on order
CREATE INDEX CONCURRENTLY IF NOT EXISTS "ix_gmxltmzo" ON "public"."order" ("status_id");
-- [post-2] (SHARE UPDATE EXCLUSIVE) Create index ix_hltnpbgg on order
CREATE INDEX CONCURRENTLY IF NOT EXISTS "ix_hltnpbgg" ON "public"."order" ("account_id");
-- [post-3] (NONE) Sync TypeTable seeds for order_status_type
-- (Parameterized query executed automatically by pgm.finalize_external())
INSERT INTO "public"."order_status_type" ("order_status_type_id", "code")
VALUES ($1, $2), ($3, $4), ($5, $6)
ON CONFLICT ("order_status_type_id") DO UPDATE SET "code" = EXCLUDED."code";
-- [post-4] (SHARE UPDATE EXCLUSIVE) Create index ix_tedtbckb on order_tag
CREATE INDEX CONCURRENTLY IF NOT EXISTS "ix_tedtbckb" ON "public"."order_tag" ("tag_id");

4. Apply directly with upgrade_schema()#

With zero unmanaged view dependencies, apply ap.plan.ops via pgm.Migration + pgm.upgrade_schema(..., allow_breaking=True, allow_destructive=True, ignore_tables=APP.ignore_tables) (same pattern as SQLAlchemy Step 4), then verify zero drift with pgdorm ... status.