mafw.db.migration.discovery

Model discovery for the migration service.

Discovery builds the deduplicated set of MAFwBaseModel subclasses to compare against the live database schema. Models are collected exclusively from the global model register (mafw_model_register) so the user never has to enumerate changed fields or model modules.

The register maps a table name to a single model, so deduplication is intrinsic: the same model registered twice occupies one key. Discovery additionally recomputes each model’s _meta.table_name and detects cross-model table-name collisions (for example two model classes that resolve to the same explicit Meta.table_name); on a collision it raises a MigrationConflictingTableNameError so that no diff is produced from an ambiguous model set.

Added in version 2.4.

author:

Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)

Functions

discover([registry])

Discover every registered MAFwBaseModel subclass.

Classes

DiscoveryResult(models, table_names)

The result of a model-discovery operation.

class mafw.db.migration.discovery.DiscoveryResult(models: tuple[type[MAFwBaseModel], ...], table_names: frozenset[str])[source]

Bases: object

The result of a model-discovery operation.

Parameters:
  • models (tuple[type[MAFwBaseModel], ...]) – The deduplicated, table-name-unique models to compare.

  • table_names (frozenset[str]) – The set of table names of the discovered models.

Added in version 2.4.

mafw.db.migration.discovery._table_name(model: type[MAFwBaseModel]) → str[source]

Return the database table name declared by a model.

Parameters:

model (type[MAFwBaseModel]) – The model whose table name is requested.

Returns:

The table name from the model metadata.

Return type:

str

mafw.db.migration.discovery.discover(registry: ~mafw.db.model_register.ModelRegister = <mafw.db.model_register.ModelRegister object>) → DiscoveryResult[source]

Discover every registered MAFwBaseModel subclass.

Collection is exclusive to the supplied register (defaulting to the global mafw_model_register). Non-MAFwBaseModel classes, unregistered classes, and the internal MigrationHistory model are excluded. The returned set is deduplicated and unique by table name.

Parameters:

registry (ModelRegister) – The model register to discover from. Defaults to the global register.

Returns:

The deduplicated discovery result.

Return type:

DiscoveryResult

Raises:

MigrationConflictingTableNameError – if two or more discovered models resolve to the same table name.