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)
tag=tag
):
script.run_env()
-
-
self.opts = opts
self.dialect = dialect
self.script = opts.get('script')
-
as_sql = opts.get('as_sql', False)
transactional_ddl = opts.get("transactional_ddl")
"""
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(
.. 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
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')
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)