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")):
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(
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
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):