From: Mike Bayer Date: Thu, 18 Oct 2012 16:08:45 +0000 (-0400) Subject: - [feature] Explicit error message describing the case X-Git-Tag: rel_0_4_1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c673ede893880795a64d260cf83b85b6eaea3b9;p=thirdparty%2Fsqlalchemy%2Falembic.git - [feature] Explicit error message describing the case when downgrade --sql is used without specifying specific start/end versions. #66 --- diff --git a/CHANGES b/CHANGES index c74d5ae4..907aa40a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +0.4.1 +===== +- [feature] Explicit error message describing the case + when downgrade --sql is used without specifying + specific start/end versions. #66 + 0.4.0 ===== - [feature] Support for tables in alternate schemas diff --git a/alembic/__init__.py b/alembic/__init__.py index 5a8fffad..fb9171b5 100644 --- a/alembic/__init__.py +++ b/alembic/__init__.py @@ -1,6 +1,6 @@ from os import path -__version__ = '0.4.0' +__version__ = '0.4.1' package_dir = path.abspath(path.dirname(__file__)) diff --git a/alembic/command.py b/alembic/command.py index 747744ec..b3341472 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -132,6 +132,8 @@ def downgrade(config, revision, sql=False, tag=None): if not sql: raise util.CommandError("Range revision not allowed") starting_rev, revision = revision.split(':', 2) + elif sql: + raise util.CommandError("downgrade with --sql requires :") def downgrade(rev, context): return script._downgrade_revs(revision, rev) diff --git a/tests/test_offline_environment.py b/tests/test_offline_environment.py index 813fb2e3..92d7a12e 100644 --- a/tests/test_offline_environment.py +++ b/tests/test_offline_environment.py @@ -22,7 +22,7 @@ class OfflineEnvironmentTest(TestCase): assert not context.requires_connection() """) command.upgrade(self.cfg, a, sql=True) - command.downgrade(self.cfg, a, sql=True) + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True) def test_requires_connection(self): env_file_fixture(""" @@ -38,7 +38,7 @@ context.configure(dialect_name='sqlite', starting_rev='x') assert context.get_starting_revision_argument() == 'x' """) command.upgrade(self.cfg, a, sql=True) - command.downgrade(self.cfg, a, sql=True) + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True) command.current(self.cfg) command.stamp(self.cfg, a) @@ -73,8 +73,8 @@ assert context.get_starting_revision_argument() is None assert context.get_revision_argument() == '%s' """ % b) command.upgrade(self.cfg, b, sql=True) - command.downgrade(self.cfg, b, sql=True) 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(""" @@ -82,7 +82,7 @@ context.configure(dialect_name='sqlite') assert context.get_revision_argument() == '%s' """ % b) command.upgrade(self.cfg, b, sql=True) - command.downgrade(self.cfg, b, sql=True) + command.downgrade(self.cfg, "%s:%s" % (c, b), sql=True) command.stamp(self.cfg, b, sql=True) def test_head_rev_pre_context(self): @@ -90,7 +90,7 @@ assert context.get_revision_argument() == '%s' assert context.get_head_revision() == '%s' """ % c) command.upgrade(self.cfg, b, sql=True) - command.downgrade(self.cfg, b, sql=True) + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True) command.stamp(self.cfg, b, sql=True) command.current(self.cfg) @@ -100,7 +100,7 @@ context.configure(dialect_name='sqlite') assert context.get_head_revision() == '%s' """ % c) command.upgrade(self.cfg, b, sql=True) - command.downgrade(self.cfg, b, sql=True) + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True) command.stamp(self.cfg, b, sql=True) command.current(self.cfg) @@ -109,14 +109,14 @@ assert context.get_head_revision() == '%s' assert context.get_tag_argument() == 'hi' """) command.upgrade(self.cfg, b, sql=True, tag='hi') - command.downgrade(self.cfg, b, sql=True, tag='hi') + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True, tag='hi') def test_tag_pre_context_None(self): env_file_fixture(""" assert context.get_tag_argument() is None """) command.upgrade(self.cfg, b, sql=True) - command.downgrade(self.cfg, b, sql=True) + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True) def test_tag_cmd_arg(self): env_file_fixture(""" @@ -124,7 +124,7 @@ context.configure(dialect_name='sqlite') assert context.get_tag_argument() == 'hi' """) command.upgrade(self.cfg, b, sql=True, tag='hi') - command.downgrade(self.cfg, b, sql=True, tag='hi') + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True, tag='hi') def test_tag_cfg_arg(self): env_file_fixture(""" @@ -132,7 +132,7 @@ context.configure(dialect_name='sqlite', tag='there') assert context.get_tag_argument() == 'there' """) command.upgrade(self.cfg, b, sql=True, tag='hi') - command.downgrade(self.cfg, b, sql=True, tag='hi') + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True, tag='hi') def test_tag_None(self): env_file_fixture(""" @@ -140,4 +140,15 @@ context.configure(dialect_name='sqlite') assert context.get_tag_argument() is None """) command.upgrade(self.cfg, b, sql=True) - command.downgrade(self.cfg, b, sql=True) + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True) + + def test_downgrade_wo_colon(self): + env_file_fixture(""" +context.configure(dialect_name='sqlite') +""") + assert_raises_message( + util.CommandError, + "downgrade with --sql requires :", + command.downgrade, + self.cfg, b, sql=True + )