#24543: Add checks / command options for "migrations not applied" and
"migrations
needed"
-----------------------------+--------------------------------------
Reporter: blueyed | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Old description:
> The `runserver` command prints a notice in case migrations are not
> applied:
>
> def check_migrations(self):
> """
> Checks to see if the set of migrations on disk matches the
> migrations in the database. Prints a warning if they don't match.
> """
> executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
> plan =
> executor.migration_plan(executor.loader.graph.leaf_nodes())
> if plan:
> self.stdout.write(self.style.NOTICE("\nYou have unapplied
> migrations; your app may not work properly until they are applied."))
> self.stdout.write(self.style.NOTICE("Run 'python manage.py
> migrate' to apply them.\n"))
>
> I would like to use this test during deployment.
>
> Maybe this would be appropriate for the new `--deploy` option for the
> check
> command introduced in Django 1.8?
>
> Additionally, I'd like to check if there are no migrations required,
> which I
> currently test by looking for `"No changes detected"` in `makemigrations
> --dry-run`.
>
> Even when this doesn't fit into the checks system, there should be a
> supported
> way to get theses information by means of return codes from a command.
New description:
The `runserver` command prints a notice in case migrations are not
applied:
{{{
def check_migrations(self):
"""
Checks to see if the set of migrations on disk matches the
migrations in the database. Prints a warning if they don't match.
"""
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
if plan:
self.stdout.write(self.style.NOTICE("\nYou have unapplied
migrations; your app may not work properly until they are applied."))
self.stdout.write(self.style.NOTICE("Run 'python manage.py
migrate' to apply them.\n"))
}}}
I would like to use this test during deployment.
Maybe this would be appropriate for the new `--deploy` option for the
check
command introduced in Django 1.8?
Additionally, I'd like to check if there are no migrations required, which
I
currently test by looking for `"No changes detected"` in `makemigrations
--dry-run`.
Even when this doesn't fit into the checks system, there should be a
supported
way to get theses information by means of return codes from a command.
--
Comment (by timgraham):
As for me, I simply execute `migrate` as part of a deployment script. If
there aren't any migrations to apply, it's just a no-op. Could you
elaborate on your use case for needing to know if migrations are applied
or not? Currently, `check --deploy` is simply a static analysis of a
settings file. The check you proposed would require the ability to connect
to the production database which might not be possible from a development
machine.
Regarding the second point, `makemigrations` gained an
[https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-
option---exit --exit] option in 1.8 which does what you describe.
--
Ticket URL: <https://code.djangoproject.com/ticket/24543#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.4a3798245c87f3a398c6afff52125065%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.