]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- tests and changelog for pullreq github:20
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Dec 2015 22:03:44 +0000 (17:03 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Dec 2015 22:03:44 +0000 (17:03 -0500)
docs/build/changelog.rst
tests/test_autogen_render.py

index 17be02809728d476d831cf31c57894cef2616f12..75bdb2bb695d71c1b4bbfb4f7bc2a0b2181805e5 100644 (file)
@@ -6,6 +6,16 @@ Changelog
 .. 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
index cd4b1eb433ec25b6ed81a4bd695e8920c04ea38c..e069d0837beb595e0a0d3b78ae5498f9c01774c6 100644 (file)
@@ -1,6 +1,6 @@
 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, \
@@ -13,7 +13,7 @@ from sqlalchemy.types import TIMESTAMP
 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
 
@@ -1458,6 +1458,21 @@ unique=False, """
             "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',)