django_evolution.mutators.app_mutator

Mutator that applies changes to an app.

New in version 2.2.

Classes

AppMutator(app_label, project_sig, ...[, ...])

Tracks and runs mutations for an app.

class django_evolution.mutators.app_mutator.AppMutator(app_label, project_sig, database_state, legacy_app_label=None, database=None)

Bases: BaseMutator

Tracks and runs mutations for an app.

An AppMutator is bound to a particular app name, and handles operations that apply to anything on that app.

This will create a ModelMutator internally for each set of adjacent operations that apply to the same model, allowing the database operations backend to optimize those operations. This means that it’s in the best interest of a developer to keep related mutations batched together as much as possible.

After all operations are added, the caller is expected to call to_sql() to get the SQL statements needed to apply those operations. Once called, the mutator is finalized, and new operations cannot be added.

Changed in version 2.2: Moved into the django_evolution.mutators.app_mutator module.

classmethod from_evolver(evolver, app_label, legacy_app_label=None, update_evolver=True)

Create an AppMutator based on the state from an Evolver.

Parameters:
  • evolver (django_evolution.evolve.Evolver) – The Evolver containing the state for the app mutator.

  • app_label (unicode) – The label of the app to evolve.

  • legacy_app_label (unicode, optional) – The legacy label of the app to evolve. This is based on the module name and is used in the transitioning of pre-Django 1.7 signatures.

Returns:

The new app mutator.

Return type:

AppMutator

__init__(app_label, project_sig, database_state, legacy_app_label=None, database=None)

Initialize the mutator.

Parameters:
run_mutation(mutation)

Runs a mutation that applies to this app.

If the mutation applies to a model, a ModelMutator for that model will be given the job of running this mutation. If the prior operation operated on the same model, then the previously created ModelMutator will be used. Otherwise, a new one will be created.

run_mutations(mutations)

Runs a list of mutations.

add_sql(mutation, sql)

Adds SQL that applies to the application.

to_sql()

Return SQL for the operations added to this mutator.

The SQL will represent all the operations made by the mutator. Once called, no new operations can be added.

Returns:

The list of SQL statements.

Each item may be one of the following:

  1. A Unicode string representing an SQL statement

  2. A tuple in the form of (sql_statement, sql_params)

  3. An instance of django_evolution.db.sql_result. SQLResult.

Return type:

list