#30490: migrations unique_index on (app, name).
-------------------------------------+-------------------------------------
     Reporter:  Richard              |                    Owner:  nobody
  Kojedzinszky                       |
         Type:  Bug                  |                   Status:  new
    Component:  Uncategorized        |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  migrations parallel  |             Triage Stage:
  run                                |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Richard Kojedzinszky):

 Perhaps, a similar patch would be a good starting point:

 
https://github.com/rkojedzinszky/django/commit/12477598fb3711f50ff482328ddcda62934caee6


 Replying to [comment:3 Richard Kojedzinszky]:
 >
 > Unfortunately, knowing that the migration tasks and recording its
 existence is not run in the same transaction, in a worst case scenario,
 the info that a migration has been applied can be lost at all. So, in any
 circumstances, they should be in the same transaction.
 >
 >
 > Replying to [ticket:30490 Richard Kojedzinszky]:
 > > 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#comment:4>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.c384b4255a729642d6bba24dd262de6b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to