Commits

Mike Bayer committed 5c673ed

- [feature] Explicit error message describing the case
when downgrade --sql is used without specifying
specific start/end versions. #66

Comments (0)

Files changed (4)

+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

alembic/__init__.py

 from os import path
 
-__version__ = '0.4.0'
+__version__ = '0.4.1'
 
 package_dir = path.abspath(path.dirname(__file__))
 

alembic/command.py

         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 <fromrev>:<torev>")
 
     def downgrade(rev, context):
         return script._downgrade_revs(revision, rev)

tests/test_offline_environment.py

 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("""
 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)
 
 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("""
 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):
 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)
 
 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)
 
 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("""
 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("""
 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("""
 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 <fromrev>:<torev>",
+            command.downgrade,
+            self.cfg, b, sql=True
+        )