.. changelog::
:version: 0.8.4
+ .. change::
+ :tags: feature, autogenerate
+ :pullreq: github:20
+
+ Added an autogenerate renderer for the :class:`.ExecuteSQLOp` operation
+ object; only renders if given a plain SQL string, otherwise raises
+ NotImplementedError. Can be of help with custom autogenerate
+ sequences that includes straight SQL execution. Pull request courtesy
+ Jacob Magnusson.
+
.. change::
:tags: bug, batch
:tickets: 345
import re
import sys
-from alembic.testing import TestBase, exclusions
+from alembic.testing import TestBase, exclusions, assert_raises
from alembic.operations import ops
from sqlalchemy import MetaData, Column, Table, String, \
from sqlalchemy.types import UserDefinedType
from sqlalchemy.dialects import mysql, postgresql
from sqlalchemy.engine.default import DefaultDialect
-from sqlalchemy.sql import and_, column, literal_column, false
+from sqlalchemy.sql import and_, column, literal_column, false, table
from alembic.migration import MigrationContext
from alembic.autogenerate import api
"existing_server_default=sa.text(!U'5'))"
)
+ def test_render_executesql_plaintext(self):
+ op_obj = ops.ExecuteSQLOp("drop table foo")
+ eq_(
+ autogenerate.render_op_text(self.autogen_context, op_obj),
+ "op.execute('drop table foo')"
+ )
+
+ def test_render_executesql_sqlexpr_notimplemented(self):
+ sql = table('x', column('q')).insert()
+ op_obj = ops.ExecuteSQLOp(sql)
+ assert_raises(
+ NotImplementedError,
+ autogenerate.render_op_text, self.autogen_context, op_obj
+ )
+
class RenderNamingConventionTest(TestBase):
__requires__ = ('sqlalchemy_094',)