--
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/CAFNZOJNoi583wUoQp%2BRBB_%2B3i_vqSPRbVNwhiU_OG7V2eL8x3g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM1vtHgDU2VO-kyV9CM%2BxXRPbPmHKgUVJqYGxd2POdou%2BQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAL6gfQY-hCG3pH7asZ1GCqBuOOpYnOHgzMDMfyaYVpEkme4s8A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CABpHFHTDHevJLPe8XAGKWR%2BrgxznJJPSSUxM_j8aTjc5j5aUDw%40mail.gmail.com.
Hi everyone,
I agree that there is room for improvement around migrations in Django with respect to the expected downtime/table locking. But I don’t know whether this should in Django itself or handled by a 3rd party library.
I’m maintaining the django-migration-linter (the very idea was to have an automated tool since reviewing migrations is not something new Django devs can do easily), which currently tackles another issue than the one you mention. It tries, in a best effort manner as you’ve seen through the SQL checks, to understand if the migration is introducing a backward incompatible change to your schema, which will desynchronize your code and database schema (so you’ll get errors when you deploy one without the other – and you’ll have a hard time doing a rollback).
It’s a different aspect, compared to checking that the forward migration will be instant and non-locking. However, it is planned to add this to the linter too (https://github.com/3YOURMIND/django-migration-linter/issues/99).
You’ve noticed that it’s based on the SQL strings, which has advantages and drawbacks. The checks are easy to implement (just a set of rules basically), it could be completely Django-agnostic and it can lint RunSQL operations. But it’s a bit harder to represent a state when multiple SQL statements are executed, to check if they cancel each other out for instance.
An idea about
something that could be in Django would be, somehow like the
“database features”,
marking for each migration operation (AlterField, AddField, …)
on each database
backend, if they can potentially mean downtime. It would be a
hint about the
risk of the migration, and display a warning if necessary.
Going one step further, for some operations, Django could
query the
number of rows of the corresponding table and have some risk
heuristics. Basically: “you’re adding a column to a table with
less than 100 rows, this
should not be risky” or “you’re adding a column to a table with
millions of
rows, be careful!”.
However, as these heuristics would be rather arbitrary, I’m not
sure that the Django
project would want to make this kind of choices – so it might be
a better fit for
a library. (what I’m describing is more or less the ultimate
goal the django-migration-linter)
Hope this gives some insights about the project and how it could help on this topic :)
Cheers,
David
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAFNZOJMJm_g20VjxEpojj46e4Zjp5h4qwq7QS6DMUCw4TeinRw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/eb1590cc-1e07-2749-39a7-30e67b9d4955%40gmail.com.