django_evolution.evolve.base

Base classes for evolver-related objects.

New in version 2.2: This was previously located in django_evolution.evolve.

Classes

BaseEvolutionTask(task_id, evolver)

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:

bool

evolution_required

Whether an evolution is required by this task.

This is set after calling prepare().

Type:

bool

evolver

The evolver that will execute the task.

Type:

Evolver

id

The unique ID for the task.

Type:

unicode

new_evolutions

A list of evolution model entries this task would create.

This is set after calling prepare().

Type:

list of django_evolution.models.Evolution

sql

A list of SQL statements to perform for the task. Each entry can be a string or tuple accepted by run_sql().

Type:

list

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 of BaseEvolutionTask) – 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 of BaseEvolutionTask) – 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.

Parameters:
  • mutation (django_evolution.mutations.BaseMutation) – The mutation to check.

  • **kwargs (dict) – Additional keyword arguments to pass to BaseMutation.is_mutable.

Returns:

True if the mutation is mutable. False if it is not.

Return type:

bool

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, and sql.

This must be called before execute() or get_evolution_content().

Parameters:
  • hinted (bool) – Whether to prepare the task for hinted evolutions.

  • **kwargs (dict, unused) – Additional keyword arguments passed for task preparation. This is provide for future expansion purposes.

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 of sql_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:

unicode

__repr__()

Return a string representation of the task.

Returns:

The string representation.

Return type:

unicode

__str__()

Return a string description of the task.

Returns:

The string description.

Return type:

unicode