django_evolution.mutations.sql_mutation

Mutation for executing SQL statements.

New in version 2.2.

Classes

SQLMutation(tag, sql[, update_func])

A mutation that executes SQL on the database.

class django_evolution.mutations.sql_mutation.SQLMutation(tag, sql, update_func=None)

Bases: BaseMutation

A mutation that executes SQL on the database.

Unlike most mutations, this one is largely database-dependent. It allows arbitrary SQL to be executed. It’s recommended that the execution does not modify the schema of a table (unless it’s highly database-specific with no counterpart in Django Evolution), but rather is limited to things like populating data.

SQL statements cannot be optimized. Any scheduled database operations prior to the SQL statement will be executed without any further optimization. This can lead to longer database evolution times.

Changed in version 2.2: Moved into the django_evolution.mutations.sql_mutation module.

__init__(tag, sql, update_func=None)

Initialize the mutation.

Parameters:
  • tag (unicode) – A unique tag identifying this SQL operation.

  • sql (unicode) – The SQL to execute.

  • update_func (callable, optional) – A function to call to simulate updating the database signature. This is required for simulate() to work.

get_hint_params()

Return parameters for the mutation’s hinted evolution.

Returns:

A list of parameter strings to pass to the mutation’s constructor in a hinted evolution.

Return type:

list of unicode

simulate(simulation)

Simulate a mutation for an application.

This will run the update_func provided when instantiating the mutation, passing it app_label and project_sig. It should then modify the signature to match what the SQL statement would do.

Parameters:

simulation (Simulation) – The state for the simulation.

Raises:
mutate(mutator)

Schedule a database mutation on the mutator.

This will instruct the mutator to execute the SQL for an app.

Parameters:

mutator (django_evolution.mutators.AppMutator) – The mutator to perform an operation on.

Raises:

django_evolution.errors.EvolutionNotImplementedError – The configured mutation is not supported on this type of database.

is_mutable(*args, **kwargs)

Return whether the mutation can be applied to the database.

Parameters:
  • *args (tuple, unused) – Unused positional arguments.

  • **kwargs (tuple, unused) – Unused positional arguments.

Returns:

True, always.

Return type:

bool