From: Mike Bayer Date: Sun, 23 Nov 2014 20:35:12 +0000 (-0500) Subject: - The ``alembic revision`` command accepts the ``--sql`` option to X-Git-Tag: rel_0_7_0~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15376ba1d60bc2529f830e8b52fa6b2e9eac29d6;p=thirdparty%2Fsqlalchemy%2Falembic.git - 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. fixes #248 --- diff --git a/alembic/command.py b/alembic/command.py index 2bdb9442..530af17a 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -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( diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index 4e9a97c9..d4694eb3 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -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 diff --git a/tests/test_command.py b/tests/test_command.py index 933b347f..25791441 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -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):