django_evolution.mutations.sql_mutation
Mutation for executing SQL statements.
New in version 2.2.
Classes
|
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 forsimulate()
to work.
- get_hint_params()
Return parameters for the mutation’s hinted evolution.
- simulate(simulation)
Simulate a mutation for an application.
This will run the
update_func
provided when instantiating the mutation, passing itapp_label
andproject_sig
. It should then modify the signature to match what the SQL statement would do.- Parameters:
simulation (
Simulation
) – The state for the simulation.- Raises:
django_evolution.errors.CannotSimulate –
update_func
was not provided or was not a function.django_evolution.errors.SimulationFailure – The simulation failed. The reason is in the exception’s message. This would be run by
update_func
.
- 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.