]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Include existing_comment in MySQLChangeColumn
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 24 Aug 2019 02:23:00 +0000 (22:23 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 24 Aug 2019 02:28:35 +0000 (22:28 -0400)
Fixed issue where emitting a change of column name for MySQL did not
preserve the column comment, even if it were specified as existing_comment.

Change-Id: I93a63e5b7c4b629e42088242a9be345de94aa6ea
Fixes: #594
alembic/ddl/mysql.py
docs/build/unreleased/594.rst [new file with mode: 0644]
tests/test_mysql.py

index 17ae2de737047480942b91486b221bda30849c06..e9195996f06bfb36f20a36925ff69a4bb7f57d86 100644 (file)
@@ -64,6 +64,9 @@ class MySQLImpl(DefaultImpl):
                     autoincrement=autoincrement
                     if autoincrement is not None
                     else existing_autoincrement,
+                    comment=comment
+                    if comment is not False
+                    else existing_comment,
                 )
             )
         elif (
diff --git a/docs/build/unreleased/594.rst b/docs/build/unreleased/594.rst
new file mode 100644 (file)
index 0000000..e68dadc
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, mysql
+    :tickets: 594
+
+    Fixed issue where emitting a change of column name for MySQL did not
+    preserve the column comment, even if it were specified as existing_comment.
+
index fa857b570811a3cee1eaa71bd463a5d803c998a3..ed4b173beae921ad3d8db7ff8e1c1e58db62d55c 100644 (file)
@@ -309,6 +309,23 @@ class MySQLOpTest(TestBase):
             "COMMENT 'existing column comment'"
         )
 
+    @config.requirements.comments_api
+    def test_rename_column_existing_comment(self):
+        context = op_fixture("mysql")
+        op.alter_column(
+            "t1",
+            "c1",
+            new_column_name="newc1",
+            existing_nullable=False,
+            existing_comment="existing column comment",
+            existing_type=Integer,
+        )
+
+        context.assert_(
+            "ALTER TABLE t1 CHANGE c1 newc1 INTEGER NOT NULL "
+            "COMMENT 'existing column comment'"
+        )
+
     @config.requirements.comments_api
     def test_alter_column_new_comment_replaces_existing(self):
         context = op_fixture("mysql")