#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------+---------------------------------
     Reporter:  slachinger     |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Migrations     |    Version:  1.7
     Severity:  Normal         |   Keywords:  Modify Field Column
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+---------------------------------
 If a migration modifies multiple columns of a table for each column/field
 an ALTER TABLE statement is executed. However most DBMS (all but sqlite?)
 support modification of several columns at once.

 For example, the consider this migration:
 {{{
 #!div style="font-size: 80%"
   {{{#!python
 class Migration(migrations.Migration):

     dependencies = [
         ('core', '0001_initial'),
     ]

     operations = [
         migrations.AlterField(
             model_name='employee',
             name='salary',
             field=models.BigIntegerField(),
             preserve_default=True,
         ),
         migrations.AlterField(
             model_name='employee',
             name='academic_degrees',
             field=models.CharField(max_length=200),
             preserve_default=True,
         ),
     ]
   }}}
 }}}

 This currently results in two ALTER TABLE statments being executed:
 {{{
 #!div style="font-size: 80%"
   {{{#!sql

 ALTER TABLE employee MODIFY COLUMN salary bigint;
 ALTER TABLE employee MODIFY COLUMN academic_degrees varchar(200);
    }}}
 }}}

 But this takes twice as long as using only one ALTER TABLE statement since
 the whole table is essentially recreated twice (at least in MySQL but IIRC
 it is the same in PG):
 {{{
 #!div style="font-size: 80%"
   {{{#!sql
 ALTER TABLE employee MODIFY COLUMN salary bigint, MODIFY COLUMN
 academic_degrees varchar(200);
    }}}
 }}}

 This is particulary annoying because it essentially multiplies the time
 the migration runs by the number of modified fields and thus causes much
 longer downtimes of the service.

 NOTE: this is most likely related to #24203 which refers to adding columns
 instead of modifying.

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

Reply via email to