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"
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())
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)
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)
):
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,
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))
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:
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: