]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- The ``alembic revision`` command accepts the ``--sql`` option to
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 23 Nov 2014 20:35:12 +0000 (15:35 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 23 Nov 2014 20:35:12 +0000 (15:35 -0500)
suit some very obscure use case where the ``revision_environment``
flag is set up, so that ``env.py`` is run when ``alembic revision``
is run even though autogenerate isn't specified.   As this flag is
otherwise confusing, error messages are now raised if
``alembic revision`` is invoked with both ``--sql`` and
``--autogenerate`` or with ``--sql`` without
``revision_environment`` being set.
fixes #248

alembic/command.py
docs/build/changelog.rst
tests/test_command.py

index 2bdb944224329e3af871627a5df995310e86a60d..530af17af4bd5353ff945cf380acaae5c446fc21 100644 (file)
@@ -84,6 +84,10 @@ def revision(
     if autogenerate:
         environment = True
 
+        if sql:
+            raise util.CommandError(
+                "Using --sql with --autogenerate does not make any sense")
+
         def retrieve_migrations(rev, context):
             if set(script.get_revisions(rev)) != \
                     set(script.get_revisions("heads")):
@@ -93,6 +97,10 @@ def revision(
     elif environment:
         def retrieve_migrations(rev, context):
             return []
+    elif sql:
+        raise util.CommandError(
+            "Using --sql with the revision command when "
+            "revision_environment is not configured does not make any sense")
 
     if environment:
         with EnvironmentContext(
index 4e9a97c9d773923829bacae60ff25e7e031cb1f2..d4694eb308a7256357fafdfeee7373564a0addc8 100644 (file)
@@ -80,6 +80,19 @@ Changelog
       specific revisions as well, e.g. ``alembic upgrade ae10+3``, to produce
       a migration target relative to the given exact version.
 
+    .. change::
+      :tags: bug, commands
+      :tickets: 248
+
+      The ``alembic revision`` command accepts the ``--sql`` option to
+      suit some very obscure use case where the ``revision_environment``
+      flag is set up, so that ``env.py`` is run when ``alembic revision``
+      is run even though autogenerate isn't specified.   As this flag is
+      otherwise confusing, error messages are now raised if
+      ``alembic revision`` is invoked with both ``--sql`` and
+      ``--autogenerate`` or with ``--sql`` without
+      ``revision_environment`` being set.
+
     .. change::
       :tags: bug, autogenerate, postgresql
       :tickets: 247
index 933b347fdc3aba4824a40fbd0237c6ed3c82d776..257914417a7e8cc1fa406d906a4d2b47159890d6 100644 (file)
@@ -232,6 +232,28 @@ finally:
             command.revision, self.cfg, autogenerate=True
         )
 
+    def test_nonsensical_sql_mode_autogen(self):
+        self._env_fixture()
+        assert_raises_message(
+            util.CommandError,
+            "Using --sql with --autogenerate does not make any sense",
+            command.revision, self.cfg, autogenerate=True, sql=True
+        )
+
+    def test_nonsensical_sql_no_env(self):
+        self._env_fixture()
+        assert_raises_message(
+            util.CommandError,
+            "Using --sql with the revision command when revision_environment "
+            "is not configured does not make any sense",
+            command.revision, self.cfg, sql=True
+        )
+
+    def test_sensical_sql_w_env(self):
+        self._env_fixture()
+        self.cfg.set_main_option("revision_environment", "true")
+        command.revision(self.cfg, sql=True)
+
 
 class UpgradeDowngradeStampTest(TestBase):