alembic_pg_autogen.diff

Diff logic for comparing canonical catalog snapshots.

Module Contents

Classes

Action

The kind of operation needed to reconcile current state with desired state.

FunctionOp

A single diff operation on a PostgreSQL function.

TriggerOp

A single diff operation on a PostgreSQL trigger.

DiffResult

Result of comparing two canonical catalog snapshots.

Functions

diff

Compare two canonical catalog snapshots and produce diff operations.

_diff_items

Diff two sequences of catalog items by identity key (first 3 fields).

Data

API

alembic_pg_autogen.diff.log = 'getLogger(...)'
class alembic_pg_autogen.diff.Action(*args, **kwds)

Bases: enum.Enum

The kind of operation needed to reconcile current state with desired state.

Initialization

CREATE = 'create'
REPLACE = 'replace'
DROP = 'drop'
class alembic_pg_autogen.diff.FunctionOp

Bases: typing.NamedTuple

A single diff operation on a PostgreSQL function.

action: alembic_pg_autogen.diff.Action = None
current: alembic_pg_autogen.inspect.FunctionInfo | None = None
desired: alembic_pg_autogen.inspect.FunctionInfo | None = None
class alembic_pg_autogen.diff.TriggerOp

Bases: typing.NamedTuple

A single diff operation on a PostgreSQL trigger.

action: alembic_pg_autogen.diff.Action = None
current: alembic_pg_autogen.inspect.TriggerInfo | None = None
desired: alembic_pg_autogen.inspect.TriggerInfo | None = None
class alembic_pg_autogen.diff.DiffResult

Bases: typing.NamedTuple

Result of comparing two canonical catalog snapshots.

function_ops: collections.abc.Sequence[alembic_pg_autogen.diff.FunctionOp] = None
trigger_ops: collections.abc.Sequence[alembic_pg_autogen.diff.TriggerOp] = None
alembic_pg_autogen.diff._InfoT = 'TypeVar(...)'
alembic_pg_autogen.diff._OpT = 'TypeVar(...)'
alembic_pg_autogen.diff.diff(current: alembic_pg_autogen.canonicalize.CanonicalState, desired: alembic_pg_autogen.canonicalize.CanonicalState) alembic_pg_autogen.diff.DiffResult

Compare two canonical catalog snapshots and produce diff operations.

Matches functions by (schema, name, identity_args) and triggers by (schema, table_name, trigger_name). Objects present only in desired produce CREATE ops, objects only in current produce DROP ops, and objects in both with differing definitions produce REPLACE ops.

Args:

current: The current database state (from inspection). desired: The desired state (from canonicalization).

Returns:

A DiffResult with sorted sequences of function and trigger ops.

alembic_pg_autogen.diff._diff_items(current_items: collections.abc.Sequence[alembic_pg_autogen.diff._InfoT], desired_items: collections.abc.Sequence[alembic_pg_autogen.diff._InfoT], make_op: collections.abc.Callable[[alembic_pg_autogen.diff.Action, alembic_pg_autogen.diff._InfoT | None, alembic_pg_autogen.diff._InfoT | None], alembic_pg_autogen.diff._OpT]) list[alembic_pg_autogen.diff._OpT]

Diff two sequences of catalog items by identity key (first 3 fields).