Corpus 03 · Pagila (PostgreSQL DVD Rental Sample)#
← All Assimilation Pathways · Live test suite: tests/integration/migrations/corpora/test_corpora.py
Pagila (PostgreSQL License) is the canonical rich-PostgreSQL sample schema — 15 tables plus almost every advanced catalog object you meet in real production databases:
- Partitioned table (
paymentpartitioned byRANGE (payment_date)) with inherited partition constraints filtered out viaconparentid = 0. - Custom PostgreSQL types: native
ENUM(mpaa_rating),DOMAIN(year),tsvector(fulltext), andtext[](special_features). - Custom aggregate (
group_concat), triggers, and 7 views — safely inventoried as unmanaged objects without crashingpg_get_functiondef()onprokind = 'a'. - Circular foreign keys (
store.manager_staff_id ↔ staff.store_id) preserved viapreserved_constraints=(...)soplan_migration()never drops an FK.
| Verification Rung | Mode | Result on Live PostgreSQL |
|---|---|---|
Catalog audit (audit-schema) |
Read-only | ✅ migratable=True (aggregates, views, triggers, partitions inventoried) |
Zero-DDL bind (scaffold --mode bind) |
Bind-as-is | ✅ plan_migration().ops == () (zero DDL, all FKs & partitions intact) |
| Full assimilation | Assimilate | ℹ️ Requires external TX bridge for the 7 views & triggers (see Unmanaged Objects) |
1. Source Schema#
tests/integration/migrations/corpora/03_pagila/schema.sql
-- Pagila sample database core schema (DVD rental store).
-- Licence: PostgreSQL License (devrimgunduz/pagila).
CREATE TYPE mpaa_rating AS ENUM ('G', 'PG', 'PG-13', 'R', 'NC-17');
CREATE DOMAIN year AS integer CHECK (VALUE >= 1901 AND VALUE <= 2155);
CREATE FUNCTION _group_concat(text, text) RETURNS text
LANGUAGE sql IMMUTABLE
AS $_$
SELECT CASE
WHEN $2 IS NULL THEN $1
WHEN $1 IS NULL THEN $2
ELSE $1 || ', ' || $2
END
$_$;
CREATE AGGREGATE group_concat(text) (
SFUNC = _group_concat,
STYPE = text
);
CREATE FUNCTION last_updated() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.last_update = CURRENT_TIMESTAMP;
RETURN NEW;
END $$;
CREATE TABLE language (
language_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name character(20) NOT NULL,
last_update timestamp with time zone DEFAULT now() NOT NULL
);
CREATE TABLE actor (
actor_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
first_name text NOT NULL,
last_name text NOT NULL,
last_update timestamp with time zone DEFAULT now() NOT NULL
);
CREATE INDEX idx_actor_last_name ON actor (last_name);
CREATE TABLE category (
category_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name text NOT NULL,
last_update timestamp with time zone DEFAULT now() NOT NULL
);
CREATE TABLE film (
film_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
title text NOT NULL,
description text,
release_year year,
language_id integer NOT NULL REFERENCES language(language_id) ON UPDATE CASCADE ON DELETE RESTRICT,
original_language_id integer REFERENCES language(language_id) ON UPDATE CASCADE ON DELETE RESTRICT,
rental_duration smallint DEFAULT 3 NOT NULL,
rental_rate numeric(4, 2) DEFAULT 4.99 NOT NULL,
length smallint,
replacement_cost numeric(5, 2) DEFAULT 19.99 NOT NULL,
rating mpaa_rating DEFAULT 'G'::mpaa_rating,
last_update timestamp with time zone DEFAULT now() NOT NULL,
special_features text[],
fulltext tsvector NOT NULL
);
CREATE INDEX idx_title ON film (title);
CREATE INDEX idx_fk_language_id ON film (language_id);
CREATE INDEX idx_fk_original_language_id ON film (original_language_id);
CREATE INDEX film_fulltext_idx ON film USING gist (fulltext);
CREATE TRIGGER last_updated BEFORE UPDATE ON film
FOR EACH ROW EXECUTE FUNCTION last_updated();
CREATE TABLE film_actor (
actor_id integer NOT NULL REFERENCES actor(actor_id) ON UPDATE CASCADE ON DELETE RESTRICT,
film_id integer NOT NULL REFERENCES film(film_id) ON UPDATE CASCADE ON DELETE RESTRICT,
last_update timestamp with time zone DEFAULT now() NOT NULL,
PRIMARY KEY (actor_id, film_id)
);
CREATE INDEX idx_fk_film_id ON film_actor (film_id);
CREATE TABLE film_category (
film_id integer NOT NULL REFERENCES film(film_id) ON UPDATE CASCADE ON DELETE RESTRICT,
category_id integer NOT NULL REFERENCES category(category_id) ON UPDATE CASCADE ON DELETE RESTRICT,
last_update timestamp with time zone DEFAULT now() NOT NULL,
PRIMARY KEY (film_id, category_id)
);
CREATE TABLE country (
country_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
country text NOT NULL,
last_update timestamp with time zone DEFAULT now() NOT NULL
);
CREATE TABLE city (
city_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
city text NOT NULL,
country_id integer NOT NULL REFERENCES country(country_id) ON UPDATE CASCADE ON DELETE RESTRICT,
last_update timestamp with time zone DEFAULT now() NOT NULL
);
CREATE INDEX idx_fk_country_id ON city (country_id);
CREATE TABLE address (
address_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
address text NOT NULL,
address2 text,
district text NOT NULL,
city_id integer NOT NULL REFERENCES city(city_id) ON UPDATE CASCADE ON DELETE RESTRICT,
postal_code text,
phone text NOT NULL,
last_update timestamp with time zone DEFAULT now() NOT NULL
);
CREATE INDEX idx_fk_city_id ON address (city_id);
CREATE TABLE store (
store_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
manager_staff_id integer NOT NULL,
address_id integer NOT NULL REFERENCES address(address_id) ON UPDATE CASCADE ON DELETE RESTRICT,
last_update timestamp with time zone DEFAULT now() NOT NULL
);
CREATE UNIQUE INDEX idx_unq_manager_staff_id ON store (manager_staff_id);
CREATE TABLE staff (
staff_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
first_name text NOT NULL,
last_name text NOT NULL,
address_id integer NOT NULL REFERENCES address(address_id) ON UPDATE CASCADE ON DELETE RESTRICT,
email text,
store_id integer NOT NULL REFERENCES store(store_id),
active boolean DEFAULT true NOT NULL,
username text NOT NULL,
password text,
last_update timestamp with time zone DEFAULT now() NOT NULL,
picture bytea
);
ALTER TABLE store
ADD CONSTRAINT store_manager_staff_id_fkey
FOREIGN KEY (manager_staff_id) REFERENCES staff(staff_id)
ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED;
CREATE TABLE customer (
customer_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
store_id integer NOT NULL REFERENCES store(store_id) ON UPDATE CASCADE ON DELETE RESTRICT,
first_name text NOT NULL,
last_name text NOT NULL,
email text,
address_id integer NOT NULL REFERENCES address(address_id) ON UPDATE CASCADE ON DELETE RESTRICT,
activebool boolean DEFAULT true NOT NULL,
create_date date DEFAULT CURRENT_DATE NOT NULL,
last_update timestamp with time zone DEFAULT now(),
active integer
);
CREATE INDEX idx_fk_store_id ON customer (store_id);
CREATE INDEX idx_fk_address_id ON customer (address_id);
CREATE INDEX idx_last_name ON customer (last_name);
CREATE TABLE inventory (
inventory_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
film_id integer NOT NULL REFERENCES film(film_id) ON UPDATE CASCADE ON DELETE RESTRICT,
store_id integer NOT NULL REFERENCES store(store_id) ON UPDATE CASCADE ON DELETE RESTRICT,
last_update timestamp with time zone DEFAULT now() NOT NULL
);
CREATE INDEX idx_store_id_film_id ON inventory (store_id, film_id);
CREATE TABLE rental (
rental_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
rental_date timestamp with time zone NOT NULL,
inventory_id integer NOT NULL REFERENCES inventory(inventory_id) ON UPDATE CASCADE ON DELETE RESTRICT,
customer_id integer NOT NULL REFERENCES customer(customer_id) ON UPDATE CASCADE ON DELETE RESTRICT,
return_date timestamp with time zone,
staff_id integer NOT NULL REFERENCES staff(staff_id) ON UPDATE CASCADE ON DELETE RESTRICT,
last_update timestamp with time zone DEFAULT now() NOT NULL
);
CREATE UNIQUE INDEX idx_unq_rental_rental_date_inventory_id_customer_id
ON rental (rental_date, inventory_id, customer_id);
CREATE INDEX idx_fk_inventory_id ON rental (inventory_id);
CREATE TABLE payment (
payment_id integer GENERATED BY DEFAULT AS IDENTITY,
customer_id integer NOT NULL REFERENCES customer(customer_id),
staff_id integer NOT NULL REFERENCES staff(staff_id),
rental_id integer NOT NULL REFERENCES rental(rental_id),
amount numeric(5, 2) NOT NULL,
payment_date timestamp with time zone NOT NULL,
PRIMARY KEY (payment_id, payment_date)
) PARTITION BY RANGE (payment_date);
CREATE TABLE payment_p2022_01 PARTITION OF payment
FOR VALUES FROM ('2022-01-01 00:00:00+00') TO ('2022-02-01 00:00:00+00');
CREATE TABLE payment_p2022_02 PARTITION OF payment
FOR VALUES FROM ('2022-02-01 00:00:00+00') TO ('2022-03-01 00:00:00+00');
CREATE VIEW actor_info AS
SELECT a.actor_id, a.first_name, a.last_name, group_concat(f.title) AS film_info
FROM actor a
LEFT JOIN film_actor fa ON a.actor_id = fa.actor_id
LEFT JOIN film f ON fa.film_id = f.film_id
GROUP BY a.actor_id, a.first_name, a.last_name;
2. Live Catalog Audit#
migratable · exit 0
12 migration6 unmanaged22 info
- FK 'film_category_category_id_fkey' on film_category(category_id) has no covering B-tree index.
- FK 'inventory_film_id_fkey' on inventory(film_id) has no covering B-tree index.
- FK 'payment_customer_id_fkey' on payment(customer_id) has no covering B-tree index.
- FK 'payment_rental_id_fkey' on payment(rental_id) has no covering B-tree index.
- FK 'payment_staff_id_fkey' on payment(staff_id) has no covering B-tree index.
- FK 'rental_customer_id_fkey' on rental(customer_id) has no covering B-tree index.
- FK 'rental_staff_id_fkey' on rental(staff_id) has no covering B-tree index.
- FK 'staff_address_id_fkey' on staff(address_id) has no covering B-tree index.
- FK 'staff_store_id_fkey' on staff(store_id) has no covering B-tree index.
- FK 'store_address_id_fkey' on store(address_id) has no covering B-tree index.
- Table 'film_actor' uses composite PK (actor_id, film_id).
- Table 'film_category' uses composite PK (film_id, category_id).
- Function '_group_concat' is unmanaged by pgdorm.migrate.
- View 'actor_info' (depends on: actor, film, film_actor) is unmanaged by pgdorm.migrate.
- Aggregate 'group_concat' is unmanaged by pgdorm.migrate.
- Function 'last_updated' is unmanaged by pgdorm.migrate.
- Index 'film_fulltext_idx' on 'film' (gist, non_btree:gist) will be preserved untouched.
- Trigger 'last_updated' on 'film' -> last_updated() is unmanaged by pgdorm.migrate.
- FK 'address_city_id_fkey' on 'address' defines ON UPDATE CASCADE.
- FK 'city_country_id_fkey' on 'city' defines ON UPDATE CASCADE.
- FK 'customer_address_id_fkey' on 'customer' defines ON UPDATE CASCADE.
- FK 'customer_store_id_fkey' on 'customer' defines ON UPDATE CASCADE.
- FK 'film_language_id_fkey' on 'film' defines ON UPDATE CASCADE.
- FK 'film_original_language_id_fkey' on 'film' defines ON UPDATE CASCADE.
- FK 'film_actor_actor_id_fkey' on 'film_actor' defines ON UPDATE CASCADE.
- FK 'film_actor_film_id_fkey' on 'film_actor' defines ON UPDATE CASCADE.
- FK 'film_category_category_id_fkey' on 'film_category' defines ON UPDATE CASCADE.
- FK 'film_category_film_id_fkey' on 'film_category' defines ON UPDATE CASCADE.
- FK 'inventory_film_id_fkey' on 'inventory' defines ON UPDATE CASCADE.
- FK 'inventory_store_id_fkey' on 'inventory' defines ON UPDATE CASCADE.
- FK 'rental_customer_id_fkey' on 'rental' defines ON UPDATE CASCADE.
- FK 'rental_inventory_id_fkey' on 'rental' defines ON UPDATE CASCADE.
- FK 'rental_staff_id_fkey' on 'rental' defines ON UPDATE CASCADE.
- FK 'staff_address_id_fkey' on 'staff' defines ON UPDATE CASCADE.
- FK 'store_address_id_fkey' on 'store' defines ON UPDATE CASCADE.
- Constraint 'store_manager_staff_id_fkey' on 'store' is DEFERRABLE.
- FK 'store_manager_staff_id_fkey' on 'store' defines ON UPDATE CASCADE.
- Column film.fulltext uses non-builtin type 'tsvector'.
- Column film.rating uses native PG enum 'mpaa_rating' (G, PG, PG-13, R, NC-17).
- Column film.release_year uses non-builtin type 'year'.
Inspect raw machine-readable audit JSON (tests/integration/migrations/corpora/03_pagila/captured/audit.json)
{
"counts": {
"blocker": 0,
"info": 22,
"migration_required": 12,
"unmanaged": 6
},
"findings": [
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'film_category_category_id_fkey' on film_category(category_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "film_category_category_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "film_category"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'inventory_film_id_fkey' on inventory(film_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "inventory_film_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "inventory"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'payment_customer_id_fkey' on payment(customer_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "payment_customer_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "payment"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'payment_rental_id_fkey' on payment(rental_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "payment_rental_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "payment"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'payment_staff_id_fkey' on payment(staff_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "payment_staff_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "payment"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'rental_customer_id_fkey' on rental(customer_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "rental_customer_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "rental"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'rental_staff_id_fkey' on rental(staff_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "rental_staff_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "rental"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'staff_address_id_fkey' on staff(address_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "staff_address_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "staff"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'staff_store_id_fkey' on staff(store_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "staff_store_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "staff"
},
{
"auto_fixable": true,
"category": "indexes",
"code": "UNINDEXED_FK",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'store_address_id_fkey' on store(address_id) has no covering B-tree index.",
"object_kind": "foreign_key",
"object_name": "store_address_id_fkey",
"severity": "migration_required",
"suggestion": "Assimilation plans online `CREATE INDEX CONCURRENTLY` for uncovered FKs.",
"table": "store"
},
{
"auto_fixable": true,
"category": "primary_key",
"code": "PK_COMPOSITE",
"doc_anchor": "primary-keys-and-serials",
"message": "Table 'film_actor' uses composite PK (actor_id, film_id).",
"object_kind": "primary_key",
"object_name": "actor_id,film_id",
"severity": "migration_required",
"suggestion": "Add surrogate `<table_name>_id` PK and demote composite PK to `pg.Unique(...)`.",
"table": "film_actor"
},
{
"auto_fixable": true,
"category": "primary_key",
"code": "PK_COMPOSITE",
"doc_anchor": "primary-keys-and-serials",
"message": "Table 'film_category' uses composite PK (film_id, category_id).",
"object_kind": "primary_key",
"object_name": "film_id,category_id",
"severity": "migration_required",
"suggestion": "Add surrogate `<table_name>_id` PK and demote composite PK to `pg.Unique(...)`.",
"table": "film_category"
},
{
"auto_fixable": false,
"category": "unmanaged",
"code": "FUNCTION_OR_PROC_PRESENT",
"doc_anchor": "unmanaged-objects",
"message": "Function '_group_concat' is unmanaged by pgdorm.migrate.",
"object_kind": "function",
"object_name": "_group_concat",
"severity": "unmanaged",
"suggestion": "Preserved untouched; review any routine referencing renamed tables or columns.",
"table": null
},
{
"auto_fixable": false,
"category": "unmanaged",
"code": "VIEW_PRESENT",
"doc_anchor": "unmanaged-objects",
"message": "View 'actor_info' (depends on: actor, film, film_actor) is unmanaged by pgdorm.migrate.",
"object_kind": "view",
"object_name": "actor_info",
"severity": "unmanaged",
"suggestion": "Use the external-TX bridge (`psycopg3`) to recreate impacted views atomically.",
"table": null
},
{
"auto_fixable": false,
"category": "unmanaged",
"code": "FUNCTION_OR_PROC_PRESENT",
"doc_anchor": "unmanaged-objects",
"message": "Aggregate 'group_concat' is unmanaged by pgdorm.migrate.",
"object_kind": "aggregate",
"object_name": "group_concat",
"severity": "unmanaged",
"suggestion": "Preserved untouched; review any routine referencing renamed tables or columns.",
"table": null
},
{
"auto_fixable": false,
"category": "unmanaged",
"code": "FUNCTION_OR_PROC_PRESENT",
"doc_anchor": "unmanaged-objects",
"message": "Function 'last_updated' is unmanaged by pgdorm.migrate.",
"object_kind": "function",
"object_name": "last_updated",
"severity": "unmanaged",
"suggestion": "Preserved untouched; review any routine referencing renamed tables or columns.",
"table": null
},
{
"auto_fixable": false,
"category": "unmanaged",
"code": "UNMANAGED_INDEX_PRESENT",
"doc_anchor": "unmanaged-objects",
"message": "Index 'film_fulltext_idx' on 'film' (gist, non_btree:gist) will be preserved untouched.",
"object_kind": "index",
"object_name": "film_fulltext_idx",
"severity": "unmanaged",
"suggestion": "Preserved automatically; verify expression predicates if columns are renamed.",
"table": "film"
},
{
"auto_fixable": false,
"category": "unmanaged",
"code": "TRIGGER_PRESENT",
"doc_anchor": "unmanaged-objects",
"message": "Trigger 'last_updated' on 'film' -> last_updated() is unmanaged by pgdorm.migrate.",
"object_kind": "trigger",
"object_name": "last_updated",
"severity": "unmanaged",
"suggestion": "Preserved untouched; verify trigger function bodies after table/column renames.",
"table": "film"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'address_city_id_fkey' on 'address' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "address_city_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "address"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'city_country_id_fkey' on 'city' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "city_country_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "city"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'customer_address_id_fkey' on 'customer' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "customer_address_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "customer"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'customer_store_id_fkey' on 'customer' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "customer_store_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "customer"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'film_language_id_fkey' on 'film' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "film_language_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "film"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'film_original_language_id_fkey' on 'film' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "film_original_language_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "film"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'film_actor_actor_id_fkey' on 'film_actor' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "film_actor_actor_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "film_actor"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'film_actor_film_id_fkey' on 'film_actor' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "film_actor_film_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "film_actor"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'film_category_category_id_fkey' on 'film_category' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "film_category_category_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "film_category"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'film_category_film_id_fkey' on 'film_category' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "film_category_film_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "film_category"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'inventory_film_id_fkey' on 'inventory' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "inventory_film_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "inventory"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'inventory_store_id_fkey' on 'inventory' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "inventory_store_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "inventory"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'rental_customer_id_fkey' on 'rental' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "rental_customer_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "rental"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'rental_inventory_id_fkey' on 'rental' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "rental_inventory_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "rental"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'rental_staff_id_fkey' on 'rental' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "rental_staff_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "rental"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'staff_address_id_fkey' on 'staff' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "staff_address_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "staff"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'store_address_id_fkey' on 'store' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "store_address_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "store"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "DEFERRABLE_CONSTRAINT",
"doc_anchor": "constraints-and-indexes",
"message": "Constraint 'store_manager_staff_id_fkey' on 'store' is DEFERRABLE.",
"object_kind": "constraint",
"object_name": "store_manager_staff_id_fkey",
"severity": "info",
"suggestion": "Existing constraint is preserved when untouched; recreate manually if altered.",
"table": "store"
},
{
"auto_fixable": false,
"category": "constraints",
"code": "FK_ON_UPDATE_ACTION",
"doc_anchor": "constraints-and-indexes",
"message": "FK 'store_manager_staff_id_fkey' on 'store' defines ON UPDATE CASCADE.",
"object_kind": "foreign_key",
"object_name": "store_manager_staff_id_fkey",
"severity": "info",
"suggestion": "Matched by signature; review if PK updates rely on `ON UPDATE CASCADE`.",
"table": "store"
},
{
"auto_fixable": false,
"category": "types",
"code": "CUSTOM_OR_EXTENSION_TYPE",
"doc_anchor": "column-types",
"message": "Column film.fulltext uses non-builtin type 'tsvector'.",
"object_kind": "column",
"object_name": "fulltext",
"severity": "info",
"suggestion": "Scaffold emits `Annotated[str, pg.CustomType(pg_type=...)]` for review.",
"table": "film"
},
{
"auto_fixable": true,
"category": "types",
"code": "PG_NATIVE_ENUM",
"doc_anchor": "column-types",
"message": "Column film.rating uses native PG enum 'mpaa_rating' (G, PG, PG-13, R, NC-17).",
"object_kind": "column",
"object_name": "rating",
"severity": "info",
"suggestion": "Use `mode='assimilate'` to migrate PG enums into seeded `IntEnum` `pg.TypeTable`s.",
"table": "film"
},
{
"auto_fixable": false,
"category": "types",
"code": "CUSTOM_OR_EXTENSION_TYPE",
"doc_anchor": "column-types",
"message": "Column film.release_year uses non-builtin type 'year'.",
"object_kind": "column",
"object_name": "release_year",
"severity": "info",
"suggestion": "Scaffold emits `Annotated[str, pg.CustomType(pg_type=...)]` for review.",
"table": "film"
}
],
"ignored_tables": [],
"migratable": true,
"schema": "public",
"table_count": 15,
"type_table_candidates": [],
"unmanaged_objects": {
"extensions": [],
"indexes": [
{
"access_method": "gist",
"indexdef": "CREATE INDEX film_fulltext_idx ON public.film USING gist (fulltext)",
"name": "film_fulltext_idx",
"reason": "non_btree:gist",
"table": "film"
}
],
"rls_policies": [],
"routines": [
{
"definition": "CREATE OR REPLACE FUNCTION public._group_concat(text, text)\n RETURNS text\n LANGUAGE sql\n IMMUTABLE\nAS $function$\nSELECT CASE\n WHEN $2 IS NULL THEN $1\n WHEN $1 IS NULL THEN $2\n ELSE $1 || ', ' || $2\nEND\n$function$\n",
"kind": "function",
"name": "_group_concat"
},
{
"definition": null,
"kind": "aggregate",
"name": "group_concat"
},
{
"definition": "CREATE OR REPLACE FUNCTION public.last_updated()\n RETURNS trigger\n LANGUAGE plpgsql\nAS $function$\nBEGIN\n NEW.last_update = CURRENT_TIMESTAMP;\n RETURN NEW;\nEND $function$\n",
"kind": "function",
"name": "last_updated"
}
],
"triggers": [
{
"definition": "CREATE TRIGGER last_updated BEFORE UPDATE ON public.film FOR EACH ROW EXECUTE FUNCTION last_updated()",
"function_name": "last_updated",
"name": "last_updated",
"table": "film"
}
],
"views": [
{
"definition": " SELECT a.actor_id,\n a.first_name,\n a.last_name,\n group_concat(f.title) AS film_info\n FROM actor a\n LEFT JOIN film_actor fa ON a.actor_id = fa.actor_id\n LEFT JOIN film f ON fa.film_id = f.film_id\n GROUP BY a.actor_id, a.first_name, a.last_name;",
"depends_on_tables": [
"actor",
"film",
"film_actor"
],
"materialized": false,
"name": "actor_info"
}
]
},
"workflow_steps": [
{
"detail": "Review 1 view(s), 1 trigger(s), and 3 routine(s); drop blocking views inside an external TX if altering columns.",
"order": 1,
"phase": "pre_ddl",
"summary": "Inspect unmanaged views, triggers, and routines"
},
{
"detail": "Run `pgdorm scaffold` and `pgdorm adopt-plan` (use `execute_plan_tx` inside a psycopg3 transaction when recreating views/functions atomically).",
"order": 2,
"phase": "ddl",
"summary": "Scaffold models, review AdoptionMap, and execute transactional DDL"
},
{
"detail": "Update SQL bodies to target assimilated table/column names before committing the external TX.",
"order": 3,
"phase": "post_ddl",
"summary": "Recreate adjusted views, materialized views, and routines"
},
{
"detail": "Run `finalize_external()` or `pgdorm upgrade`, then verify `pgdorm drift`.",
"order": 4,
"phase": "post_commit",
"summary": "Run CONCURRENTLY indexes, VALIDATE constraints, and record ledger"
}
]
}
3. Zero-DDL Bind Models (pgdorm scaffold --mode bind)#
Generated by pgdorm scaffold --mode bind · tests/integration/migrations/corpora/03_pagila/__captured__/bind_models.py.txt
from datetime import date
from datetime import datetime
from decimal import Decimal
from typing import Annotated
import pgdorm as pg
import pgdorm.migrate as pgm
class Actor(pg.Table):
actor_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
first_name: pg.Col[str]
last_name: pg.Col[str] = pg.col(index=True)
last_update: pg.Col[datetime] = pg.col(default=pg.now())
class Category(pg.Table):
category_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
name: pg.Col[str]
last_update: pg.Col[datetime] = pg.col(default=pg.now())
class Country(pg.Table):
country_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
country: pg.Col[str]
last_update: pg.Col[datetime] = pg.col(default=pg.now())
class City(pg.Table):
city_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
city: pg.Col[str]
country_id: pg.Col[pg.Int4] = pg.fk(Country, on_delete=pg.enums.OnDelete.RESTRICT)
last_update: pg.Col[datetime] = pg.col(default=pg.now())
class Address(pg.Table):
address_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
address: pg.Col[str]
address2: pg.Col[str | None] = pg.col(default=None)
district: pg.Col[str]
city_id: pg.Col[pg.Int4] = pg.fk(City, on_delete=pg.enums.OnDelete.RESTRICT)
postal_code: pg.Col[str | None] = pg.col(default=None)
phone: pg.Col[str]
last_update: pg.Col[datetime] = pg.col(default=pg.now())
class Language(pg.Table):
language_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
name: pg.Col[Annotated[str, pg.CustomType(pg_type='character(20)')]]
last_update: pg.Col[datetime] = pg.col(default=pg.now())
class Film(pg.Table):
film_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
title: pg.Col[str] = pg.col(index=True)
description: pg.Col[str | None] = pg.col(default=None)
release_year: pg.Col[Annotated[str, pg.CustomType(pg_type='year')] | None] = pg.col(default=None)
language_id: pg.Col[pg.Int4] = pg.fk(Language, on_delete=pg.enums.OnDelete.RESTRICT)
original_language_id: pg.Col[pg.Int4 | None] = pg.fk(Language, on_delete=pg.enums.OnDelete.RESTRICT, default=None)
rental_duration: pg.Col[pg.Int2] = pg.col(default=3)
rental_rate: pg.Col[Decimal] = pg.col(precision=4, scale=2, default=Decimal('4.99'))
length: pg.Col[pg.Int2 | None] = pg.col(default=None)
replacement_cost: pg.Col[Decimal] = pg.col(precision=5, scale=2, default=Decimal('19.99'))
rating: pg.Col[Annotated[str, pg.CustomType(pg_type='mpaa_rating')] | None] = pg.col(default='G')
last_update: pg.Col[datetime] = pg.col(default=pg.now())
special_features: pg.Col[list[str] | None] = pg.col(default=None)
fulltext: pg.Col[Annotated[str, pg.CustomType(pg_type='tsvector')]]
@classmethod
def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
return (
pg.Index(cls.original_language_id),
)
class FilmActor(pg.Table, strict_pk=False):
actor_id: pg.Col[pg.Int4]
film_id: pg.Col[pg.Int4]
last_update: pg.Col[datetime] = pg.col(default=pg.now())
@classmethod
def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
return (
pg.PrimaryKey(cls.actor_id, cls.film_id),
pg.ForeignKey((cls.actor_id,), (Actor.actor_id,), on_delete=pg.enums.OnDelete.RESTRICT),
pg.ForeignKey((cls.film_id,), (Film.film_id,), on_delete=pg.enums.OnDelete.RESTRICT),
)
class FilmCategory(pg.Table, strict_pk=False):
film_id: pg.Col[pg.Int4]
category_id: pg.Col[pg.Int4]
last_update: pg.Col[datetime] = pg.col(default=pg.now())
@classmethod
def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
return (
pg.PrimaryKey(cls.film_id, cls.category_id),
pg.ForeignKey((cls.category_id,), (Category.category_id,), on_delete=pg.enums.OnDelete.RESTRICT, auto_index=False),
pg.ForeignKey((cls.film_id,), (Film.film_id,), on_delete=pg.enums.OnDelete.RESTRICT),
)
class Customer(pg.Table, preserved_constraints=('customer_store_id_fkey',)):
# Preserved cycle FK 'customer_store_id_fkey': ('store_id',) -> store(store_id)
customer_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
store_id: pg.Col[pg.Int4] = pg.col(index=True)
first_name: pg.Col[str]
last_name: pg.Col[str] = pg.col(index=True)
email: pg.Col[str | None] = pg.col(default=None)
address_id: pg.Col[pg.Int4] = pg.fk(Address, on_delete=pg.enums.OnDelete.RESTRICT)
activebool: pg.Col[bool] = pg.col(default=True)
create_date: pg.Col[date] = pg.col(default=pg.current_date())
last_update: pg.Col[datetime | None] = pg.col(default=pg.now())
active: pg.Col[pg.Int4 | None] = pg.col(default=None)
class Inventory(pg.Table, preserved_constraints=('inventory_store_id_fkey',)):
# Preserved cycle FK 'inventory_store_id_fkey': ('store_id',) -> store(store_id)
inventory_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
film_id: pg.Col[pg.Int4] = pg.fk(Film, on_delete=pg.enums.OnDelete.RESTRICT, auto_index=False)
store_id: pg.Col[pg.Int4]
last_update: pg.Col[datetime] = pg.col(default=pg.now())
@classmethod
def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
return (
pg.Index(cls.store_id, cls.film_id),
)
class Payment(pg.Table, preserved_constraints=('payment_rental_id_fkey', 'payment_staff_id_fkey')):
# Preserved cycle FK 'payment_rental_id_fkey': ('rental_id',) -> rental(rental_id)
# Preserved cycle FK 'payment_staff_id_fkey': ('staff_id',) -> staff(staff_id)
payment_id: pg.Col[pg.Int4] = pg.col(default=pg.identity())
customer_id: pg.Col[pg.Int4] = pg.fk(Customer, auto_index=False)
staff_id: pg.Col[pg.Int4]
rental_id: pg.Col[pg.Int4]
amount: pg.Col[Decimal] = pg.col(precision=5, scale=2)
payment_date: pg.Col[datetime]
@classmethod
def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
return (
pg.PrimaryKey(cls.payment_id, cls.payment_date),
pg.PartitionBy.range(cls.payment_date),
)
class Rental(pg.Table, preserved_constraints=('rental_staff_id_fkey',)):
# Preserved cycle FK 'rental_staff_id_fkey': ('staff_id',) -> staff(staff_id)
rental_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
rental_date: pg.Col[datetime]
inventory_id: pg.Col[pg.Int4] = pg.fk(Inventory, on_delete=pg.enums.OnDelete.RESTRICT)
customer_id: pg.Col[pg.Int4] = pg.fk(Customer, on_delete=pg.enums.OnDelete.RESTRICT, auto_index=False)
return_date: pg.Col[datetime | None] = pg.col(default=None)
staff_id: pg.Col[pg.Int4]
last_update: pg.Col[datetime] = pg.col(default=pg.now())
@classmethod
def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
return (
pg.Index(cls.rental_date, cls.inventory_id, cls.customer_id, unique=True),
)
class Staff(pg.Table, preserved_constraints=('staff_store_id_fkey',)):
# Preserved cycle FK 'staff_store_id_fkey': ('store_id',) -> store(store_id)
staff_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
first_name: pg.Col[str]
last_name: pg.Col[str]
address_id: pg.Col[pg.Int4] = pg.fk(Address, on_delete=pg.enums.OnDelete.RESTRICT, auto_index=False)
email: pg.Col[str | None] = pg.col(default=None)
store_id: pg.Col[pg.Int4]
active: pg.Col[bool] = pg.col(default=True)
username: pg.Col[str]
password: pg.Col[str | None] = pg.col(default=None)
last_update: pg.Col[datetime] = pg.col(default=pg.now())
picture: pg.Col[bytes | None] = pg.col(default=None)
class Store(pg.Table):
store_id: pg.Col[pg.Int4] = pg.pk(default=pg.identity())
manager_staff_id: pg.Col[pg.Int4] = pg.fk(Staff, on_delete=pg.enums.OnDelete.RESTRICT, deferrable=True, initially_deferred=True)
address_id: pg.Col[pg.Int4] = pg.fk(Address, on_delete=pg.enums.OnDelete.RESTRICT, auto_index=False)
last_update: pg.Col[datetime] = pg.col(default=pg.now())
@classmethod
def __constraints__(cls) -> tuple[pg.TableConstraint, ...]:
return (
pg.Index(cls.manager_staff_id, unique=True),
)
ADOPTION_MAP = pgm.AdoptionMap(
)
APP = pgm.MigrationApp(tables=(Actor, Category, Country, City, Address, Language, Film, FilmActor, FilmCategory, Customer, Inventory, Payment, Rental, Staff, Store))