Management command that fails when there are created migrations waiting to be applied to the database

31 views
Skip to first unread message

Gordon

unread,
Mar 26, 2020, 2:29:15 AM3/26/20
to Django developers (Contributions to Django itself)
Good morning.

I had created ticket https://code.djangoproject.com/ticket/31402 after discussing in IRC about a built in way to stop a continuous delivery pipeline if the deployment would need to run database migrations. (i.e. if running `python manage.py migration` would do anything or not.

In my specific scenario, I would like to run `python manage.py showmigrations --database=foo --check` and have it fail if there are unapplied migrations to the 'foo' database (or the default database as the case may be).  In this case, the automatic deployment would halt to prevent downtime.

The discussion resulted with one must parse the results from `python manage.py showmigrations`.  I.e. write a script that checks the output of `showmigrations` for something like '[ ]'.

I can certainly do that, but it seems like it would be generally useful to have this type of command available within Django.  It could be used to improve the release process for any project that uses some sort of automatic deployment scenario.

The ticket was rejected with the response, use `python manage.py makemigrations --check`.  However, I believe that this command determines if the current version of models on disk would result in a new migration being made.  This is not the same as the functionality I have suggested.  Am I wrong here?

Please let me know your thoughts.

Fran Hrženjak

unread,
Mar 26, 2020, 2:59:39 AM3/26/20
to django-d...@googlegroups.com
If I’m understanding correctly, the difference between `makemigrations --check` and your use case is that one checks if we need to *create* any migrations while the other checks (or would check) if we need to *run* any migrations.

Seems reasonable to me. Although I would prefer we just add a `--check` option to the existing `migrate` command to keep it simpler and consistent with the existing option for `makemigrations` command. 

 

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/728bde3f-e68c-4224-9101-5c98a45c1016%40googlegroups.com.
--
LP,
Fran

Gordon

unread,
Mar 26, 2020, 3:01:18 AM3/26/20
to Django developers (Contributions to Django itself)
Exactly!  I need to know if we will *run* migrations.
To unsubscribe from this group and stop receiving emails from it, send an email to django-d...@googlegroups.com.
--
LP,
Fran

Mariusz Felisiak

unread,
Mar 26, 2020, 3:12:06 AM3/26/20
to Django developers (Contributions to Django itself)
Now I understand better your use case, you want to exit when you have unapplied migrations. Currently you can use `migrate --plan` that shows migrations to apply or "No planned migration operations." if such migrations don't exist. I agree we can add `migrate --check` option.

Best,
Mariusz

Mariusz Felisiak

unread,
Mar 26, 2020, 3:15:02 AM3/26/20
to Django developers (Contributions to Django itself)
Ticket accepted.
Reply all
Reply to author
Forward
0 new messages