alembic_pg_autogen.canonicalize¶
Desired-state canonicalization through PostgreSQL round-tripping.
Module Contents¶
Classes¶
Post-DDL catalog snapshot returned by |
Functions¶
Canonicalize user-provided DDL by round-tripping through PostgreSQL. |
|
Canonicalize function DDL and return the resulting |
|
Canonicalize trigger DDL and return the resulting |
|
Canonicalize view DDL and return the resulting |
Data¶
API¶
- alembic_pg_autogen.canonicalize.log = 'getLogger(...)'¶
- class alembic_pg_autogen.canonicalize.CanonicalState¶
Bases:
typing.NamedTuplePost-DDL catalog snapshot returned by
canonicalize().- functions: collections.abc.Sequence[alembic_pg_autogen.inspect.FunctionInfo] = None¶
- triggers: collections.abc.Sequence[alembic_pg_autogen.inspect.TriggerInfo] = None¶
- alembic_pg_autogen.canonicalize.canonicalize(conn: sqlalchemy.Connection, *, function_ddl: collections.abc.Sequence[str] = (), view_ddl: collections.abc.Sequence[str] = (), trigger_ddl: collections.abc.Sequence[str] = (), schemas: collections.abc.Sequence[str] | None = None) alembic_pg_autogen.canonicalize.CanonicalState¶
Canonicalize user-provided DDL by round-tripping through PostgreSQL.
Executes the given DDL statements inside a savepoint, reads back canonical forms via
inspect_functions/inspect_views/inspect_triggers, then rolls back the savepoint — leaving the database unchanged.DDL executes in dependency order: functions first (standalone), then views (may reference functions), then triggers (may reference functions and INSTEAD OF triggers may be on views).
- Args:
conn: An open SQLAlchemy connection (may have an active transaction). function_ddl:
CREATE FUNCTION/CREATE PROCEDUREstatements. view_ddl:CREATE VIEWstatements. trigger_ddl:CREATE TRIGGERstatements. schemas: Optional schema list passed to the inspect helpers. When None, all user schemas are included.- Returns:
A
CanonicalStatewith the full post-DDL catalog state.- Raises:
sqlalchemy.exc.DBAPIError: If any DDL statement is invalid.
- alembic_pg_autogen.canonicalize.canonicalize_functions(conn: sqlalchemy.Connection, ddl: collections.abc.Sequence[str], schemas: collections.abc.Sequence[str] | None = None) collections.abc.Sequence[alembic_pg_autogen.inspect.FunctionInfo]¶
Canonicalize function DDL and return the resulting
FunctionInfolist.Convenience wrapper around
canonicalize()with only function_ddl populated.
- alembic_pg_autogen.canonicalize.canonicalize_triggers(conn: sqlalchemy.Connection, ddl: collections.abc.Sequence[str], schemas: collections.abc.Sequence[str] | None = None) collections.abc.Sequence[alembic_pg_autogen.inspect.TriggerInfo]¶
Canonicalize trigger DDL and return the resulting
TriggerInfolist.Convenience wrapper around
canonicalize()with only trigger_ddl populated.
- alembic_pg_autogen.canonicalize.canonicalize_views(conn: sqlalchemy.Connection, ddl: collections.abc.Sequence[str], schemas: collections.abc.Sequence[str] | None = None) collections.abc.Sequence[alembic_pg_autogen.inspect.ViewInfo]¶
Canonicalize view DDL and return the resulting
ViewInfolist.Convenience wrapper around
canonicalize()with only view_ddl populated.