Skip to content

state

state

Canonical Schema State Representations

This module defines the canonical schema representations used for comparisons in django-migration-audit.

These data structures are used by: - Extractor (builds expected schema from migration operations) - Introspection (reads actual schema from live database)

By using the same canonical format for both expected and actual schemas, we enable apples-to-apples comparison in Comparison B: Reality Check.

The state classes represent: - ColumnState: A single database column - TableState: A database table with its columns - SchemaState: The entire database schema

ColumnState(name, db_type, null, default=None) dataclass

Canonical representation of a database column.

name instance-attribute

db_type instance-attribute

null instance-attribute

default = None class-attribute instance-attribute

identity()

Identity tuple for comparison across sources.

IndexState(name, columns) dataclass

Canonical representation of a database index.

name instance-attribute

columns instance-attribute

ConstraintState(name, constraint_type, columns) dataclass

Canonical representation of a database constraint (unique or check).

name instance-attribute

constraint_type instance-attribute

columns instance-attribute

TableState(name, columns=dict(), indexes=dict(), constraints=dict()) dataclass

Canonical representation of a database table.

name instance-attribute

columns = field(default_factory=dict) class-attribute instance-attribute

indexes = field(default_factory=dict) class-attribute instance-attribute

constraints = field(default_factory=dict) class-attribute instance-attribute

has_column(column_name)

column(column_name)

has_index(index_name)

has_constraint(constraint_name)

SchemaState(tables=dict()) dataclass

Canonical representation of an entire database schema.

tables = field(default_factory=dict) class-attribute instance-attribute

has_table(table_name)

table(table_name)

all_tables()

ProjectState()

Mutable state builder for constructing expected schema from migration operations.

This is used by the extractor to replay migration operations and build the expected schema state.

create_table(app_label, name, fields, options)

Create a new table from a CreateModel operation.

drop_table(app_label, name)

Drop a table from a DeleteModel operation.

add_column(app_label, model_name, field)

Add a column from an AddField operation.

remove_column(app_label, model_name, name)

Remove a column from a RemoveField operation.

alter_column(app_label, model_name, field)

Alter a column from an AlterField operation.

rename_table(app_label, model_name, new_table_name)

Rename a table from an AlterModelTable operation.

add_constraint(app_label, model_name, constraint)

Add a constraint from an AddConstraint operation.

remove_constraint(app_label, model_name, name)

Remove a constraint from a RemoveConstraint operation.

add_index(app_label, model_name, index)

Add an index from an AddIndex operation.

remove_index(app_label, model_name, name)

Remove an index from a RemoveIndex operation.

to_schema_state()

Convert the mutable ProjectState to an immutable SchemaState.