]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
lots of TODOs for straight SQL mode
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Apr 2011 16:59:38 +0000 (12:59 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Apr 2011 16:59:38 +0000 (12:59 -0400)
alembic/config.py
alembic/context.py
alembic/op.py
alembic/script.py

index 008189700f937a4d12c7806e25a53ac483c20ad3..f6bcaefd96bcc7baebb69c2864eb9e3321c0e3fd 100644 (file)
@@ -48,7 +48,10 @@ def main(argv):
                             action="store_true",
                             help="Don't emit SQL to database - dump to "
                                     "standard output instead")
-
+        # TODO:
+        # --dialect - name of dialect when --sql mode is set - *no DB connections
+        # should occur, add this to env.py templates as a conditional*
+        # --init-version-table - add CREATE for version table
         positional_help = {
             'directory':"location of scripts directory",
             'revision':"revision identifier"
index 9bac6063c16c71735833ea06d254cc3f5dfff3f1..0b33a9e107a8d28e2828faeab7bd6cf5345f2a95 100644 (file)
@@ -38,10 +38,10 @@ class DefaultContext(object):
 
     def _current_rev(self):
         if self.as_sql:
-            if not self.connection.dialect.has_table(self.connection,
-                    'alembic_version'):
-                self._exec(CreateTable(_version))
-                return None
+            # TODO: no coverage here !
+            # TODO: what if migrations table is needed on remote DB ?? 
+            # need an option
+            raise Exception("revisions must be specified with --sql")
         else:
             _version.create(self.connection, checkfirst=True)
         return self.connection.scalar(_version.select())
@@ -70,7 +70,11 @@ class DefaultContext(object):
         if self.as_sql and self.transactional_ddl:
             print "BEGIN;\n"
 
-        current_rev = prev_rev = rev = self._current_rev()
+        if self.as_sql:
+            # TODO: coverage, --sql with just one rev == error
+            current_rev = prev_rev = rev = None
+        else:
+            current_rev = prev_rev = rev = self._current_rev()
         for change, rev in self._migrations_fn(current_rev):
             log.info("Running %s %s -> %s", change.__name__, prev_rev, rev)
             change(**kw)
@@ -89,6 +93,7 @@ class DefaultContext(object):
             construct = text(construct)
         if self.as_sql:
             if args or kw:
+                # TODO: coverage
                 raise Exception("Execution arguments not allowed with as_sql")
             print unicode(
                     construct.compile(dialect=self.dialect)
@@ -135,7 +140,8 @@ class DefaultContext(object):
     ):
 
         if nullable is not util.NO_VALUE:
-            self._exec(base.ColumnNullable(table_name, column_name, nullable, schema=schema))
+            self._exec(base.ColumnNullable(table_name, column_name, 
+                                nullable, schema=schema))
         if server_default is not util.NO_VALUE:
             self._exec(base.ColumnDefault(
                                 table_name, column_name, server_default,
@@ -145,7 +151,6 @@ class DefaultContext(object):
             self._exec(base.ColumnType(
                                 table_name, column_name, type_, schema=schema
                             ))
-        # ... etc
 
     def add_column(self, table_name, column):
         self._exec(base.AddColumn(table_name, column))
index aaefb09aece848070269edd8b8a8d6af44900d21..2f3d633bf4849facdbfb0d4b80372b7b9e4cd066 100644 (file)
@@ -11,6 +11,7 @@ __all__ = [
             'create_foreign_key', 
             'create_table',
             'drop_table',
+            'bulk_insert',
             'create_unique_constraint', 
             'get_context',
             'get_bind',
index 67aa654f57450b37a759c353f3ecdaf3c462c871..9784d68e2682141a1df513021bd0a6fab1ed75a3 100644 (file)
@@ -66,6 +66,9 @@ class ScriptDirectory(object):
             if script is None and lower is not None:
                 raise util.CommandError("Couldn't find revision %s" % downrev)
 
+    # TODO: call range_ok -> as_sql and do as_sql validation
+    # here - range is required in as_sql mode, not allowed in 
+    # non-as_sql mode. split into upgrade_to/upgrade_to_as_sql
     def upgrade_from(self, range_ok, destination, current_rev):
         if destination is not None and ':' in destination:
             if not range_ok:
@@ -79,6 +82,9 @@ class ScriptDirectory(object):
             reversed(list(revs))
             ]
 
+    # TODO: call range_ok -> as_sql and do as_sql validation
+    # here - range is required in as_sql mode, not allowed in 
+    # non-as_sql mode.  split into downgrade_to/downgrade_to_as_sql
     def downgrade_to(self, range_ok, destination, current_rev):
         if destination is not None and ':' in destination:
             if not range_ok: