django_evolution.evolve.evolve_app_task

Task for evolving an application.

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

Classes

EvolveAppTask(evolver, app[, evolutions, ...])

A task for evolving models in an application.

class django_evolution.evolve.evolve_app_task.EvolveAppTask(evolver, app, evolutions=None, migrations=None)

Bases: BaseEvolutionTask

A task for evolving models in an application.

This task will run through any evolutions in the provided application and handle applying each of those evolutions that haven’t yet been applied.

app

The app module to evolve.

Type:

module

app_label

The app label for the app to evolve.

Type:

unicode

classmethod prepare_tasks(evolver, tasks, hinted=False, **kwargs)

Prepare a list of tasks.

If migrations are supported, then before preparing any of the tasks, this will begin setting up state needed to apply any migrations for apps that use them (or will use them after any evolutions are applied).

After tasks are prepared, this will apply any migrations that need to be applied, updating the app’s signature appropriately and recording all applied migrations.

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.

Raises:

django_evolution.errors.BaseMigrationError – There was an error with the setup or validation of migrations. A subclass containing additional details will be raised.

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.

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.

  • cursor (django.db.backends.util.CursorWrapper) – The database cursor used to execute queries.

  • **kwargs (dict) – Keyword arguments to pass to the tasks’ :py:meth:`execute methods.

__init__(evolver, app, evolutions=None, migrations=None)

Initialize the task.

Parameters:
  • evolver (Evolver) – The evolver that will execute the task.

  • app (module) – The app module to evolve.

  • evolutions (list of dict, optional) –

    Optional evolutions to use for the app instead of loading from a file. This is intended for testing purposes.

    Each dictionary needs a label key for the evolution label and a mutations key for a list of BaseMutation instances.

  • migrations (list of django.db.migrations.Migration, optional) – Optional migrations to use for the app instead of loading from files. This is intended for testing purposes.

generate_mutations_info(pending_mutations, update_evolver=True)

Generate information on a series of mutations.

This will optimize and run the list of pending mutations against the evolver’s stored signature and return the optimized list of mutations and SQL, along with some information on the app.

The evolver’s signature will be updated by default, but this can be disabled in order to just retrieve information without making any changes.

Parameters:
  • pending_mutations (list of :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` django_evolution.mutations.BaseMutation) – The list of pending mutations to run.

  • update_evolver (bool, optional) – Whether to update the evolver’s signature.

Returns:

The resulting information from running the mutations. This includes the following:

app_mutator (AppMutator):

The app mutator that ran the mutations.

applied_migrations (list of tuple):

The list of migrations that were ultimately marked as applied.

mutations (list of BaseMutation):

The optimized list of mutations.

sql (list):

The optimized list of SQL statements to execute.

upgrade_method (unicode):

The resulting upgrade method for the app, after applying all mutations.

If there are no mutations to run after optimization, this will return None.

Return type:

dict

prepare(hinted=False, **kwargs)

Prepare state for this task.

This will determine if there are any unapplied evolutions in the app, and record that state and the SQL needed to apply the evolutions.

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

  • **kwargs (dict, unused) – Additional keyword arguments passed for task preparation.

execute(cursor=None, sql_executor=None, sql=None, evolutions=None, create_models_now=False)

Execute the task.

This will apply any evolutions queued up for the app.

Before the evolutions are applied for the app, the applying_evolution signal will be emitted. After, applied_evolution will be emitted.

Changed in version 2.1:

  • Added sql and evolutions arguments.

  • Deprecated cursor in favor of sql_executor.

Parameters:
  • cursor (django.db.backends.util.CursorWrapper, unused) – The legacy database cursor. This is no longer used.

  • sql_executor (django_evolution.utils.sql.SQLExecutor) – The SQL executor used to run any SQL on the database.

  • sql (list, optional) –

    A list of explicit SQL statements to execute.

    This will override sql if provided.

  • evolutions (list of django_evolution.models.Evolution, optional) –

    A list of evolutions being applied. These will be sent in the applying_evolution and applied_evolution signals.

    This will override new_evolutions if provided.

  • create_models_now (bool, optional) – Whether to create models as part of this execution. Normally, this is handled in execute_tasks(), but this flag allows for more fine-grained control of table creation in limited circumstances (intended only by Evolver).

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

__str__()

Return a string description of the task.

Returns:

The string description.

Return type:

unicode