.. versionadded:: 0.8.0
+ .. versionchanged:: 0.8.1 - The
+ :paramref:`.EnvironmentContext.configure.process_revision_directives`
+ hook can append op directives into :class:`.UpgradeOps` and
+ :class:`.DowngradeOps` which will be rendered in Python regardless
+ of whether the ``--autogenerate`` option is in use or not;
+ the ``revision_environment`` configuration variable should be
+ set to "true" in the config to enable this.
+
+
.. seealso::
:ref:`customizing_revision`
.. changelog::
:version: 0.8.1
+ .. change::
+ :tags: feature, autogenerate
+
+ A custom :paramref:`.EnvironmentContext.configure.process_revision_directives`
+ hook can now generate op directives within the :class:`.UpgradeOps`
+ and :class:`.DowngradeOps` containers that will be generated as Python
+ code even when the ``--autogenerate`` flag is False; provided that
+ ``revision_environment=True``, the full render operation will be run
+ even in "offline" mode.
+
.. change::
:tags: bug, autogenerate
)
assert os.path.exists(rev_script.path)
+ def test_renders_added_directives_no_autogen(self):
+ m = sa.MetaData()
+
+ def process_revision_directives(context, rev, generate_revisions):
+ generate_revisions[0].upgrade_ops.ops.append(
+ ops.CreateIndexOp("some_index", "some_table", ["a", "b"])
+ )
+
+ with self._env_fixture(process_revision_directives, m):
+ rev = command.revision(
+ self.cfg, message="some message", head="model1@head", sql=True)
+
+ with mock.patch.object(rev.module, "op") as op_mock:
+ rev.module.upgrade()
+ eq_(
+ op_mock.mock_calls,
+ [mock.call.create_index(
+ 'some_index', 'some_table', ['a', 'b'], unique=False)]
+ )
+
def test_autogen(self):
m = sa.MetaData()
sa.Table('t', m, sa.Column('x', sa.Integer))