From a0511731dc98d3202d47a1568b4b58ac98be2c78 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 22 Apr 2011 12:59:38 -0400 Subject: [PATCH] lots of TODOs for straight SQL mode --- alembic/config.py | 5 ++++- alembic/context.py | 19 ++++++++++++------- alembic/op.py | 1 + alembic/script.py | 6 ++++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/alembic/config.py b/alembic/config.py index 00818970..f6bcaefd 100644 --- a/alembic/config.py +++ b/alembic/config.py @@ -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" diff --git a/alembic/context.py b/alembic/context.py index 9bac6063..0b33a9e1 100644 --- a/alembic/context.py +++ b/alembic/context.py @@ -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)) diff --git a/alembic/op.py b/alembic/op.py index aaefb09a..2f3d633b 100644 --- a/alembic/op.py +++ b/alembic/op.py @@ -11,6 +11,7 @@ __all__ = [ 'create_foreign_key', 'create_table', 'drop_table', + 'bulk_insert', 'create_unique_constraint', 'get_context', 'get_bind', diff --git a/alembic/script.py b/alembic/script.py index 67aa654f..9784d68e 100644 --- a/alembic/script.py +++ b/alembic/script.py @@ -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: -- 2.47.2