- move resolution of "starting rev" for --sql mode into

get_current_heads() directly; therefore we don't need to
do this in alembic.command, which we were doing for stamp but
not downgrade/upgrade.  The slight change here is that the
context.get_starting_revision_argument() method will
return an abbreviated starting rev as abbreviated in
all cases, including the stamp command, where we previously
were converting a stamp argument first, but not for the
upgrade or downgrade commands.
- Fixed bug where using a partial revision identifier as the
"starting revision" in ``--sql`` mode in a downgrade operation
would fail to resolve properly.  fixes #269
This commit is contained in:
Mike Bayer 2015-02-03 11:40:40 -05:00
parent 267063c1b8
commit 0955d44f4b
4 changed files with 58 additions and 7 deletions

View File

@ -330,9 +330,6 @@ def stamp(config, revision, sql=False, tag=None):
if not sql:
raise util.CommandError("Range revision not allowed")
starting_rev, revision = revision.split(':', 2)
starting_rev = script.get_revision(starting_rev)
if starting_rev is not None:
starting_rev = starting_rev.revision
def do_stamp(rev, context):
return script._stamp_revs(revision, rev)
@ -347,5 +344,3 @@ def stamp(config, revision, sql=False, tag=None):
tag=tag
):
script.run_env()

View File

@ -64,7 +64,6 @@ class MigrationContext(object):
self.opts = opts
self.dialect = dialect
self.script = opts.get('script')
as_sql = opts.get('as_sql', False)
transactional_ddl = opts.get("transactional_ddl")
@ -229,7 +228,12 @@ class MigrationContext(object):
"""
if self.as_sql:
return util.to_tuple(self._start_from_rev, default=())
start_from_rev = self._start_from_rev
if start_from_rev is not None and self.script:
start_from_rev = \
self.script.get_revision(start_from_rev).revision
return util.to_tuple(start_from_rev, default=())
else:
if self._start_from_rev:
raise util.CommandError(

View File

@ -6,6 +6,24 @@ Changelog
.. changelog::
:version: 0.7.5
.. change::
:tags: bug, commands
:tickets: 269
Fixed bug where using a partial revision identifier as the
"starting revision" in ``--sql`` mode in a downgrade operation
would fail to resolve properly.
As a side effect of this change, the
:meth:`.EnvironmentContext.get_starting_revision_argument`
method will return the "starting" revision in its originally-
given "partial" form in all cases, whereas previously when
running within the :meth:`.command.stamp` command, it would have
been resolved to a full number before passing it to the
:class:`.EnvironmentContext`. The resolution of this value to
a real revision number has basically been moved to a more fundamental
level within the offline migration process.
.. change::
:tags: feature, commands

View File

@ -80,6 +80,7 @@ assert context.get_revision_argument() == '%s'
command.stamp(self.cfg, b, sql=True)
command.downgrade(self.cfg, "%s:%s" % (c, b), sql=True)
def test_destination_rev_post_context(self):
env_file_fixture("""
context.configure(dialect_name='sqlite')
@ -175,3 +176,36 @@ assert not context.requires_connection()
command.upgrade(self.cfg, "%s:%s" % (a, d.revision), sql=True)
assert not re.match(r".*-- .*and multiline", buf.getvalue(), re.S | re.M)
def test_starting_rev_pre_context_abbreviated(self):
env_file_fixture("""
assert context.get_starting_revision_argument() == '%s'
""" % b[0:4])
command.upgrade(self.cfg, "%s:%s" % (b[0:4], c), sql=True)
command.stamp(self.cfg, "%s:%s" % (b[0:4], c), sql=True)
command.downgrade(self.cfg, "%s:%s" % (b[0:4], a), sql=True)
def test_destination_rev_pre_context_abbreviated(self):
env_file_fixture("""
assert context.get_revision_argument() == '%s'
""" % b[0:4])
command.upgrade(self.cfg, "%s:%s" % (a, b[0:4]), sql=True)
command.stamp(self.cfg, b[0:4], sql=True)
command.downgrade(self.cfg, "%s:%s" % (c, b[0:4]), sql=True)
def test_starting_rev_context_runs_abbreviated(self):
env_file_fixture("""
context.configure(dialect_name='sqlite')
context.run_migrations()
""")
command.upgrade(self.cfg, "%s:%s" % (b[0:4], c), sql=True)
command.downgrade(self.cfg, "%s:%s" % (b[0:4], a), sql=True)
def test_destination_rev_context_runs_abbreviated(self):
env_file_fixture("""
context.configure(dialect_name='sqlite')
context.run_migrations()
""")
command.upgrade(self.cfg, "%s:%s" % (a, b[0:4]), sql=True)
command.stamp(self.cfg, b[0:4], sql=True)
command.downgrade(self.cfg, "%s:%s" % (c, b[0:4]), sql=True)