Commits

Anonymous committed eeab9fa

Add --fake option for migrations, and give add_column more sensible param names

  • Participants
  • Parent commits cb00e0a

Comments (0)

Files changed (4)

File db/generic.py

         "integer": "INT",
         "boolean": "BOOLEAN",
         "serial": "SERIAL",
+        "datetime": "TIMESTAMP WITH TIME ZONE",
     }
 
     def __init__(self):
         self.execute('DROP TABLE %s;' % params)
 
 
-    def add_column(self, table_name, column_name, type_name, type_param=None, unique=False, null=True, related_to=None, default=None, primary=False):
+    def add_column(self, table_name, name, type, type_param=None, unique=False, null=True, related_to=None, default=None, primary=False):
         """
         Adds the column 'column_name' to the table 'table_name'.
         The column will have type 'type_name', which is one of the generic
         @param primary: If this is the primary key column
         """
         qn = connection.ops.quote_name
-        sql, sqlparams = self.column_sql(column_name, type_name, type_param, unique, null, related_to)
+        sql, sqlparams = self.column_sql(name, type, type_param, unique, null, related_to)
         params = (
             qn(table_name),
             sql,

File management/commands/migrate.py

             help='Will run out-of-order missing migrations as they are - no rollbacks.'),
         make_option('--only', action='store_true', dest='only', default=False,
             help='Only runs or rolls back the migration specified, and none around it.'),
+        make_option('--fake', action='store_true', dest='fake', default=False,
+            help="Pretends to do the migrations, but doesn't actually execute them."),
     )
     help = "Runs migrations for all apps."
 
-    def handle(self, target=None, skip=False, merge=False, only=False, backwards=False, **options):
+    def handle(self, target=None, skip=False, merge=False, only=False, backwards=False, fake=False, **options):
         # Work out what the resolve mode is
         resolve_mode = merge and "merge" or (skip and "skip" or None)
         # Turn on db debugging
                     migrations,
                     resolve_mode = resolve_mode,
                     target_name = target,
+                    fake = fake,
                 )
                 continue

File management/commands/startmigration.py

     # Make sure it doesn't need to be mapped back to a more generic type
     type = {
         "varchar": "string",
+        "timestamp with time zone": "datetime",
     }.get(type, type)
     return type, param

File migration.py

     return getattr(module.migrations, name).Migration
 
 
-def run_forwards(app_name, migrations):
+def run_forwards(app_name, migrations, fake=False):
     """
     Runs the specified migrations forwards, in order.
     """
         record.save()
 
 
-def run_backwards(app_name, migrations, ignore=[]):
+def run_backwards(app_name, migrations, ignore=[], fake=False):
     """
     Runs the specified migrations backwards, in order, skipping those
     migrations in 'ignore'.
     # If we're using merge, and going forwards, merge
     if target >= current and resolve_mode == "merge" and missing:
         print " - Merging..."
-        run_forwards(app_name, missing)
+        run_forwards(app_name, missing, fake=fake)
     
     # Now do the right direction.
     if target == current:
     elif target < current:
         # Rollback
         print " - Rolling back..."
-        run_backwards(app_name, reversed(current_migrations[target:current]))
+        run_backwards(app_name, reversed(current_migrations[target:current]), fake=fake)
     else:
         print " - Migrating..."
-        run_forwards(app_name, migrations[current:target])
+        run_forwards(app_name, migrations[current:target], fake=fake)