]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Render correct DDL for unsetting table comments
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Jan 2019 16:18:02 +0000 (11:18 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Jan 2019 16:18:02 +0000 (11:18 -0500)
Fixed issue where the DDL emitted for :class:`.DropTableComment`, which
will be used by an upcoming version of Alembic, was incorrect for the MySQL
and Oracle databases.

Fixes: #4436
Change-Id: I196de09495a37adface4caa9dcbc29a6d0ad159a

doc/build/changelog/unreleased_12/4436.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/sql/ddl.py
lib/sqlalchemy/testing/suite/test_ddl.py

diff --git a/doc/build/changelog/unreleased_12/4436.rst b/doc/build/changelog/unreleased_12/4436.rst
new file mode 100644 (file)
index 0000000..c359b42
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+   :tags: bug, sql, oracle, mysql
+   :tickets: 4436
+
+   Fixed issue where the DDL emitted for :class:`.DropTableComment`, which
+   will be used by an upcoming version of Alembic, was incorrect for the MySQL
+   and Oracle databases.
index 4a0d82fe155102469197316ec15d6f9346b4f4e6..6e1b4e49a678ea81bfac6905f6505c3852ee2563 100644 (file)
@@ -1724,6 +1724,11 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
             ),
         )
 
+    def visit_drop_table_comment(self, create):
+        return "ALTER TABLE %s COMMENT ''" % (
+            self.preparer.format_table(create.element)
+        )
+
     def visit_set_column_comment(self, create):
         return "ALTER TABLE %s CHANGE %s %s" % (
             self.preparer.format_table(create.element.table),
index b58d038cf389a4aeb48d99b2dc1672536227967d..7e9a79909963e8342a902c3dba1fa7284157d80d 100644 (file)
@@ -994,6 +994,11 @@ class OracleDDLCompiler(compiler.DDLCompiler):
 
         return text
 
+    def visit_drop_table_comment(self, drop):
+        return "COMMENT ON TABLE %s IS ''" % self.preparer.format_table(
+            drop.element
+        )
+
     def visit_create_index(self, create):
         index = create.element
         self._verify_index_table(index)
index e77b2880f0d50f7f2a617431c0d6c82fa6e233d1..898ca75b22aa6e119b8acbac45279150c7d3bfc1 100644 (file)
@@ -1868,6 +1868,11 @@ class PGDDLCompiler(compiler.DDLCompiler):
             colspec += " NOT NULL"
         return colspec
 
+    def visit_drop_table_comment(self, drop):
+        return "COMMENT ON TABLE %s IS NULL" % self.preparer.format_table(
+            drop.element
+        )
+
     def visit_create_enum_type(self, create):
         type_ = create.element
 
index f247fa782374a911245d0fbbf73d224220a73d46..d58f378f8bf9e93d1de894747a53d9df6ccdac4f 100644 (file)
@@ -688,7 +688,11 @@ class SetTableComment(_CreateDropBase):
 
 
 class DropTableComment(_CreateDropBase):
-    """Represent a COMMENT ON TABLE IS NULL statement."""
+    """Represent a COMMENT ON TABLE '' statement.
+
+    Note this varies a lot across database backends.
+
+    """
 
     __visit_name__ = "drop_table_comment"
 
index 8317590c810fe36a7100943062f8e5956d248ee4..fe6911c4060dbfc9f530b7b37d91776ac11ed91b 100644 (file)
@@ -4,7 +4,9 @@ from .. import util
 from ..assertions import eq_
 from ..config import requirements
 from ... import Column
+from ... import inspect
 from ... import Integer
+from ... import schema
 from ... import String
 from ... import Table
 
@@ -55,5 +57,27 @@ class TableDDLTest(fixtures.TestBase):
         table.create(config.db, checkfirst=False)
         self._simple_roundtrip(table)
 
+    @requirements.comment_reflection
+    @util.provide_metadata
+    def test_add_table_comment(self):
+        table = self._simple_fixture()
+        table.create(config.db, checkfirst=False)
+        table.comment = "a comment"
+        config.db.execute(schema.SetTableComment(table))
+        eq_(
+            inspect(config.db).get_table_comment("test_table"),
+            {"text": "a comment"},
+        )
+
+    @requirements.comment_reflection
+    @util.provide_metadata
+    def test_drop_table_comment(self):
+        table = self._simple_fixture()
+        table.create(config.db, checkfirst=False)
+        table.comment = "a comment"
+        config.db.execute(schema.SetTableComment(table))
+        config.db.execute(schema.DropTableComment(table))
+        eq_(inspect(config.db).get_table_comment("test_table"), {"text": None})
+
 
 __all__ = ("TableDDLTest",)