8

This question touches the subject of zero downtime schema migrations in Django (like this one perhaps).

A two-way compatible schema migration deployment is usually as follows (correct me if this list is missing a step):

  1. Scale up old code.
  2. Create new schema change with all fields nullable.
  3. Deploy schema change.
  4. Create new code change that uses new fields.
  5. Deploy new code.
  6. Scale down old code.
  7. Optionally deploy new changes that make these fields non-nullable.

However, I have not found any resources in the Django docs about testing steps 2, 3, and 4. Ideally, before makemigrations generates a migration file, a series of tests should pass to indicate that the current codebase can run before and after this migration is run.

Question: is there already a built-in mechanism in Django, by which the two interleaved states ((old code, new schema), (new code, old schema)) during a hypothetical zero downtime forwards and backwards migration, can be tested?

Brian
  • 7,394
  • 3
  • 25
  • 46
  • 2
    Checkout https://medium.com/3yourmind/keeping-django-database-migrations-backward-compatible-727820260dbb – flix Mar 31 '19 at 09:20
  • Came across this today and am curious, but can you define what "scale up old code" means? How do you scale code? – Jamie Counsell Aug 13 '19 at 20:19
  • @JamieCounsell "scale up old code" implies scaling up the instances that have old code running on them. – Brian Aug 14 '19 at 21:06
  • @Brian hmm, as in, they're always online, but you're vertically scaling them? If that's the case, then steps 5 and 6 aren't very clear. If you mean taking those instances completely in and out of rotation (like a blue/green deployment sorta thing) so they're either handling requests ("scaled up") or not ("scaled down") then that makes more sense. – Jamie Counsell Aug 14 '19 at 21:29

0 Answers0