django_evolution.evolve.base
Base classes for evolver-related objects.
New in version 2.2: This was previously located in django_evolution.evolve
.
Classes
|
Base class for a task to perform during evolution. |
- class django_evolution.evolve.base.BaseEvolutionTask(task_id, evolver)
Bases:
object
Base class for a task to perform during evolution.
- can_simulate
Whether the task can be simulated without requiring additional information.
This is set after calling
prepare()
.- Type:
- evolution_required
Whether an evolution is required by this task.
This is set after calling
prepare()
.- Type:
- evolver
The evolver that will execute the task.
- Type:
Evolver
- new_evolutions
A list of evolution model entries this task would create.
This is set after calling
prepare()
.- Type:
- sql
A list of SQL statements to perform for the task. Each entry can be a string or tuple accepted by
run_sql()
.- Type:
- classmethod prepare_tasks(evolver, tasks, **kwargs)
Prepare a list of tasks.
This is responsible for calling
prepare()
on each of the provided tasks. It can augment this by calculating any other state needed in order to influence the tasks or react to them.If this applies state to the class, it should always be careful to completely reset the state on each run, in case there are multiple
Evolver
instances at work within a process.- Parameters:
evolver (
Evolver
) – The evolver that’s handling the tasks.tasks (
list
ofBaseEvolutionTask
) – The list of tasks to prepare. These will match the current class.**kwargs (
dict
) – Keyword arguments to pass to the tasks’ :py:meth:`prepare methods.
- classmethod execute_tasks(evolver, tasks, **kwargs)
Execute a list of tasks.
This is responsible for calling
execute()
on each of the provided tasks. It can augment this by executing any steps before or after the tasks.If this applies state to the class, it should always be careful to completely reset the state on each run, in case there are multiple
Evolver
instances at work within a process.This may depend on state from
prepare_tasks()
.- Parameters:
evolver (
Evolver
) – The evolver that’s handling the tasks.tasks (
list
ofBaseEvolutionTask
) – The list of tasks to execute. These will match the current class.**kwargs (
dict
) – Keyword arguments to pass to the tasks’ :py:meth:`execute methods.
- __init__(task_id, evolver)
Initialize the task.
- Parameters:
task_id (
unicode
) – The unique ID for the task.evolver (
Evolver
) – The evolver that will execute the task.
- is_mutation_mutable(mutation, **kwargs)
Return whether a mutation is mutable.
This is a handy wrapper around
BaseMutation.is_mutable
that passes standard arguments based on evolver state. Callers should pass any additional arguments that are required as keyword arguments.
- prepare(hinted, **kwargs)
Prepare state for this task.
This is responsible for determining whether the task applies to the database. It must set
evolution_required
,new_evolutions
, andsql
.This must be called before
execute()
orget_evolution_content()
.
- execute(cursor=None, sql_executor=None, **kwargs)
Execute the task.
This will make any changes necessary to the database.
Changed in version 2.1:
cursor
is now deprecated in favor ofsql_executor
.- Parameters:
cursor (
django.db.backends.util.CursorWrapper
, optional) – The legacy database cursor used to execute queries.sql_executor (
django_evolution.utils.sql.SQLExecutor
, optional) – The SQL executor used to run any SQL on the database.**kwargs (
dict
) – Additional keyword arguments, for future expansion.
- Raises:
django_evolution.errors.EvolutionExecutionError – The evolution task failed. Details are in the error.
- get_evolution_content()
Return the content for an evolution file for this task.
- Returns:
The evolution content.
- Return type:
- __repr__()
Return a string representation of the task.
- Returns:
The string representation.
- Return type: