1. Andrew Godwin
  2. south
  3. Pull requests

Pull requests

#13 Merged at ecaafda
Repository
msabramo
Branch
migrate_+_or_-
Repository
andrewgodwin
Branch
default

Add ability to migrate forwards and backwards easily one by one

Author
  1. Marc Abramowitz
Reviewers
Description

For rolling back by one migration, I got tired of having to do migrate --list and noting the previous migration number, so I added new virtual migration names "current-1" and "current+1" (I would've just did "-1" and "+1", but minus sign looks like a command-line option so that wouldn't work).

Comments (1)

  1. Marc Abramowitz author

    Here's a demo of how it works and this illustrates the boundary cases like trying to migrate to current-1 at 0 and trying to migrate to current+1 when already fully migrated:

    $ django migrate --list dummyapp --verbosity=2         
    
     dummyapp
      (*) 0001_initial                                                              (applied 2011-10-06 21:30:48.108684)
      (*) 0002_auto__add_field_dog_breed                                            (applied 2011-10-06 21:30:52.618428)
      (*) 0003_auto__add_field_dog_color                                            (applied 2011-10-06 22:10:00.042959)
    
    $ django migrate dummyapp current-1 --no-initial-data 
    previous_migration: 0002_auto__add_field_dog_breed (applied: 2011-10-06 21:30:52.618428)
    Running migrations for dummyapp:
     - Migrating backwards to just after 0002_auto__add_field_dog_breed.
     < dummyapp:0003_auto__add_field_dog_color
    
    $ django migrate --list dummyapp --verbosity=2       
    
     dummyapp
      (*) 0001_initial                                                              (applied 2011-10-06 21:30:48.108684)
      (*) 0002_auto__add_field_dog_breed                                            (applied 2011-10-06 21:30:52.618428)
      ( ) 0003_auto__add_field_dog_color
    
    $ django migrate dummyapp current-1 --no-initial-data
    previous_migration: 0001_initial (applied: 2011-10-06 21:30:48.108684)
    Running migrations for dummyapp:
     - Migrating backwards to just after 0001_initial.
     < dummyapp:0002_auto__add_field_dog_breed
    
    $ django migrate --list dummyapp --verbosity=2       
    
     dummyapp
      (*) 0001_initial                                                              (applied 2011-10-06 21:30:48.108684)
      ( ) 0002_auto__add_field_dog_breed
      ( ) 0003_auto__add_field_dog_color
    
    $ django migrate dummyapp current-1 --no-initial-data
    previous_migration: zero
    Running migrations for dummyapp:
     - Migrating backwards to zero state.
     < dummyapp:0001_initial
    
    $ django migrate --list dummyapp --verbosity=2       
    
     dummyapp
      ( ) 0001_initial
      ( ) 0002_auto__add_field_dog_breed
      ( ) 0003_auto__add_field_dog_color
    
    $ django migrate dummyapp current-1 --no-initial-data
    previous_migration: zero
    Running migrations for dummyapp:
    - Nothing to migrate.
    
    $ django migrate --list dummyapp --verbosity=2       
    
     dummyapp
      ( ) 0001_initial
      ( ) 0002_auto__add_field_dog_breed
      ( ) 0003_auto__add_field_dog_color
    
    $ django migrate dummyapp current+1 --verbosity=2 --no-initial-data
    Running migrations for dummyapp:
     - Migrating forwards to 0001_initial.
     > dummyapp:0001_initial
       = CREATE TABLE "dummyapp_dog" ("id" integer NOT NULL PRIMARY KEY, "name" varchar(255) NOT NULL); []
     - Sending post_syncdb signal for dummyapp: ['Dog']
    
    $ django migrate --list dummyapp --verbosity=2                     
    
     dummyapp
      (*) 0001_initial                                                              (applied 2011-10-06 22:11:20.712978)
      ( ) 0002_auto__add_field_dog_breed
      ( ) 0003_auto__add_field_dog_color
    
    $ django migrate dummyapp current+1 --verbosity=2 --no-initial-data
    Running migrations for dummyapp:
     - Migrating forwards to 0002_auto__add_field_dog_breed.
     > dummyapp:0002_auto__add_field_dog_breed
       = CREATE TABLE "_south_new_dummyapp_dog" ("breed" varchar(255) NULL, "id" integer PRIMARY KEY, "name" varchar(255) NOT NULL) []
       = INSERT INTO "_south_new_dummyapp_dog" ("id", "name") SELECT "id", "name" FROM "dummyapp_dog"; []
       = DROP TABLE "dummyapp_dog"; []
       = ALTER TABLE "_south_new_dummyapp_dog" RENAME TO "dummyapp_dog"; []
    
    $ django migrate --list dummyapp --verbosity=2                     
    
     dummyapp
      (*) 0001_initial                                                              (applied 2011-10-06 22:11:20.712978)
      (*) 0002_auto__add_field_dog_breed                                            (applied 2011-10-06 22:11:43.428765)
      ( ) 0003_auto__add_field_dog_color
    
    $ django migrate dummyapp current+1 --verbosity=2 --no-initial-data
    Running migrations for dummyapp:
     - Migrating forwards to 0003_auto__add_field_dog_color.
     > dummyapp:0003_auto__add_field_dog_color
       = CREATE TABLE "_south_new_dummyapp_dog" ("color" varchar(255) NULL, "breed" varchar(255), "id" integer PRIMARY KEY, "name" varchar(255) NOT NULL) []
       = INSERT INTO "_south_new_dummyapp_dog" ("breed", "id", "name") SELECT "breed", "id", "name" FROM "dummyapp_dog"; []
       = DROP TABLE "dummyapp_dog"; []
       = ALTER TABLE "_south_new_dummyapp_dog" RENAME TO "dummyapp_dog"; []
    
    $ django migrate --list dummyapp --verbosity=2                     
    
     dummyapp
      (*) 0001_initial                                                              (applied 2011-10-06 22:11:20.712978)
      (*) 0002_auto__add_field_dog_breed                                            (applied 2011-10-06 22:11:43.428765)
      (*) 0003_auto__add_field_dog_color                                            (applied 2011-10-06 22:11:50.757682)
    
    $ django migrate dummyapp current+1 --verbosity=2 --no-initial-data
    Running migrations for dummyapp:
    - Nothing to migrate.
    
    $ django migrate --list dummyapp --verbosity=2                     
    
     dummyapp
      (*) 0001_initial                                                              (applied 2011-10-06 22:11:20.712978)
      (*) 0002_auto__add_field_dog_breed                                            (applied 2011-10-06 22:11:43.428765)
      (*) 0003_auto__add_field_dog_color                                            (applied 2011-10-06 22:11:50.757682)