#30490: migrations unique_index on (app, name)
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  rkojedzinszky                      |
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  1.11
  Uncategorized                      |       Keywords:  migrations parallel
               Severity:  Normal     |  run
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I've a django based api service. I run it in containers, in kubernetes.
 When I update my image, basically I run the migiration process, then start
 the application. With k8s for example, when I start the deployment with 2
 or more replicas, actually 2 parallel running migration process will
 start. With the following very simple migration process, unfortunately the
 migration will be applied twice:

 {{{
 from django.db import migrations
 from django.db.models import F
 import time

 def forward(apps, schema_editor):
     TT = apps.get_model('center', 'TestTable')
     time.sleep(10)
     TT.objects.all().update(value=F('value') + 1)

 def backward(apps, schema_editor):
     TT = apps.get_model('center', 'TestTable')
     TT.objects.all().update(value=F('value') - 1)


 class Migration(migrations.Migration):

     dependencies = [
         ('center', '0007_testtable'),
     ]

     operations = [
             migrations.RunPython(forward, backward)
     ]
 }}}

 Even if the migration process is ran in a transaction, due to the unique
 index missing, it will be applied multiple times.

 Even though my setup may be rare, I think it would really be necessary to
 prevent migrations to be applied more than once. Db unique_together could
 be utilized for that.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30490>
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/056.d67383951f4f1eb0bbf05add87e4014c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to