Add utilities for fetching dependencies for an evolution or its app.

Review Request #11228 — Created Oct. 18, 2020 and submitted

Information

Django Evolution
master

Reviewers

Django Evolution 2.1 is getting support for dependencies defined in
evolutions, allowing a single evolution or all evolutions for an app to
apply before or after other evolutions or migrations. These can be
specified as an app-level dependency (in the evolutions/__init__.py)
or an evolution-level dependency by setting the following:

  • BEFORE_EVOLUTIONS
  • BEFORE_MIGRATIONS
  • AFTER_EVOLUTIONS
  • AFTER_MIGRATIONS

Each is a list of items, where each item is either a string containing
an app label (for evolutions) or a tuple containing an app label and
evolution/migration name (for evolutions and migrations).

This change begins adding support for this by introducing utility
functions that will look up these dependencies.
get_evolution_app_dependencies() will fetch the dependencies specified
at the top-level evolutions/__init__.py for an app, and
get_evolution_dependencies() will fetch those defined in a particular
evolution.

Along with checking an evolution's specified dependencies,
get_evolution_dependencies() will also check if any mutations have
dependencies to inject. This is a new feature of mutations.

Currently only MoveToDjangoMigrations implements mutation-defined
dependencies, and ensures that the evolution will apply after the
migrations it applies to. This ensures that for a new database (or new
app), the migrations will always apply first (since the intent is to
ultimately have the app use them instead of evolutions). For an existing
app, the evolver will already make sure those migrations are marked as
applied by scanning ahead for this mutation, and it's important that the
evolution doesn't try to apply before this step happens.

Upcoming changes will factor the dependencies in when determining the
order in which migrations and evolutions will apply.

Unit tests pass.

Made use of this with upcoming changes to implement full dependency
support.

Summary ID
Add utilities for fetching dependencies for an evolution or its app.
Django Evolution 2.1 is getting support for dependencies defined in evolutions, allowing a single evolution or all evolutions for an app to apply before or after other evolutions or migrations. These can be specified as an app-level dependency (in the `evolutions/__init__.py`) or an evolution-level dependency by setting the following: * `BEFORE_EVOLUTIONS` * `BEFORE_MIGRATIONS` * `AFTER_EVOLUTIONS` * `AFTER_MIGRATIONS` Each is a list of items, where each item is either a string containing an app label (for evolutions) or a tuple containing an app label and evolution/migration name (for evolutions and migrations). This change begins adding support for this by introducing utility functions that will look up these dependencies. `get_evolution_app_dependencies()` will fetch the dependencies specified at the top-level `evolutions/__init__.py` for an app, and `get_evolution_dependencies()` will fetch those defined in a particular evolution. Along with checking an evolution's specified dependencies, `get_evolution_dependencies()` will also check if any mutations have dependencies to inject. This is a new feature of mutations. Currently only `MoveToDjangoMigrations` implements mutation-defined dependencies, and ensures that the evolution will apply after the migrations it applies to. This ensures that for a new database (or new app), the migrations will always apply first (since the intent is to ultimately have the app use them instead of evolutions). For an existing app, the evolver will already make sure those migrations are marked as applied by scanning ahead for this mutation, and it's important that the evolution doesn't try to apply before this step happens. Upcoming changes will factor the dependencies in when determining the order in which migrations and evolutions will apply.
deb683e014dad3af505f66af8692ea603f522e3f
chipx86
chipx86
david
  1. Ship It!
  2. 
      
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to master (bc48632)
Loading...