]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Don't require space after MySQL pk comment
authorDaniël van Eeden <git@myname.nl>
Wed, 23 Jun 2021 14:00:43 +0000 (10:00 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 28 Jun 2021 13:39:59 +0000 (09:39 -0400)
Made a small adjustment in the table reflection feature of the MySQL
dialect to accommodate for alternate MySQL-oriented databases such as TiDB
which include their own "comment" directives at the end of a constraint
directive within "CREATE TABLE" where the format doesn't have the
additional space character after the comment, in this case the TiDB
"clustered index" feature. Pull request courtesy Daniël van Eeden.

Fixes: #6659
Closes: #6660
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6660
Pull-request-sha: 98791a441b2e3d26aa7cef9d3e2907fac113e30f

Change-Id: I20d206e0cdb809e4c6997b87159edf41249f7cd9

doc/build/changelog/unreleased_14/6659.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/reflection.py
test/dialect/mysql/test_reflection.py

diff --git a/doc/build/changelog/unreleased_14/6659.rst b/doc/build/changelog/unreleased_14/6659.rst
new file mode 100644 (file)
index 0000000..15e9c09
--- /dev/null
@@ -0,0 +1,10 @@
+.. change::
+    :tags: usecase, mysql
+    :tickets: 6659
+
+    Made a small adjustment in the table reflection feature of the MySQL
+    dialect to accommodate for alternate MySQL-oriented databases such as TiDB
+    which include their own "comment" directives at the end of a constraint
+    directive within "CREATE TABLE" where the format doesn't have the
+    additional space character after the comment, in this case the TiDB
+    "clustered index" feature. Pull request courtesy Daniël van Eeden.
index b78034de27d43b2d24fa985a365866aeb149c766..a1ad3adfe0883a0d06730fd563dc9e137431e41a 100644 (file)
@@ -416,7 +416,7 @@ class MySQLTableDefinitionParser(object):
             r"(?: +KEY_BLOCK_SIZE *[ =]? *(?P<keyblock>\S+))?"
             r"(?: +WITH PARSER +(?P<parser>\S+))?"
             r"(?: +COMMENT +(?P<comment>(\x27\x27|\x27([^\x27])*?\x27)+))?"
-            r"(?: +/\*(?P<version_sql>.+)\*/ +)?"
+            r"(?: +/\*(?P<version_sql>.+)\*/ *)?"
             r",?$" % quotes
         )
 
index 5b785a7a411867a3c7900e1dacb1946c76742ae2..3091a6a7dac3188bc7d891699046a18d53583cf3 100644 (file)
@@ -1148,6 +1148,10 @@ class RawReflectionTest(fixtures.TestBase):
         assert not regex.match(
             "  PRIMARY KEY (`id`) USING BTREE KEY_BLOCK_SIZE = = 16"
         )
+        # test #6659  (TiDB)
+        assert regex.match(
+            "  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */"
+        )
         assert regex.match("  KEY (`id`) USING BTREE COMMENT 'comment'")
         # `SHOW CREATE TABLE` returns COMMENT '''comment'
         # after creating table with COMMENT '\'comment'
@@ -1164,6 +1168,10 @@ class RawReflectionTest(fixtures.TestBase):
             "/*!50100 WITH PARSER `ngram` */ "
         )
 
+        m = regex.match("  PRIMARY KEY (`id`)")
+        eq_(m.group("type"), "PRIMARY")
+        eq_(m.group("columns"), "`id`")
+
     def test_key_reflection_columns(self):
         regex = self.parser._re_key
         exprs = self.parser._re_keyexprs