#24203: Optimisation: adding multiple fields to same model should attempt to run
single ALTER TABLE statement
--------------------------------------+-----------------------
     Reporter:  peterlauri            |      Owner:  nobody
         Type:  Cleanup/optimization  |     Status:  new
    Component:  Migrations            |    Version:  1.7
     Severity:  Normal                |   Keywords:  migration
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+-----------------------
 Origin: https://groups.google.com/d/msg/django-users/DDekrNgXH2U/k1un-
 e8CbnMJ

 When adding multiple fields to a Model the makemigrate and migrate does
 not attempt to create one ALTER TABLE statement, but rather one per field
 added. This can cause slow migrations of large tables.

 I propose to optimise to attempt to merge multiple AddField to one single
 ALTER TABLE request when the migrate is run.

 My real world case the db backend was MySQL, here is PG example of 2nd
 migration db output after adding two fields to one model.

 {{{
   Applying play.0002_auto_20150122_1825...DEBUG ALTER TABLE "play_play"
 ADD COLUMN "field2" varchar(100) NULL; (params [])
 DEBUG (0.000) ALTER TABLE "play_play" ADD COLUMN "field2" varchar(100)
 NULL; args=[]
 DEBUG ALTER TABLE "play_play" ALTER COLUMN "field2" DROP DEFAULT; (params
 [])
 DEBUG (0.000) ALTER TABLE "play_play" ALTER COLUMN "field2" DROP DEFAULT;
 args=[]
 DEBUG ALTER TABLE "play_play" ADD COLUMN "field3" varchar(100) NULL;
 (params [])
 DEBUG (0.000) ALTER TABLE "play_play" ADD COLUMN "field3" varchar(100)
 NULL; args=[]
 DEBUG ALTER TABLE "play_play" ALTER COLUMN "field3" DROP DEFAULT; (params
 [])
 DEBUG (0.000) ALTER TABLE "play_play" ALTER COLUMN "field3" DROP DEFAULT;
 args=[]
 }}}

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

Reply via email to