]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
mysql reflection: Fix TiDB clustered PK comment compatibility 6660/head
authorDaniël van Eeden <git@myname.nl>
Tue, 22 Jun 2021 07:13:38 +0000 (09:13 +0200)
committerDaniël van Eeden <git@myname.nl>
Wed, 23 Jun 2021 13:57:32 +0000 (15:57 +0200)
commit98791a441b2e3d26aa7cef9d3e2907fac113e30f
tree796fad2aed72c4e723449ee30e7a3055c2822408
parent2f100a7d4bb143e1f8674a388d8d305be3051bd6
mysql reflection: Fix TiDB clustered PK comment compatibility

On TiDB there is a `clustered_index` feature. This adds a `CLUSTERED`
keyword to the PK definition. This is in a TiDB specific comment.

However as the comment isn't followed by a space (` `) the regex
used by SQL Alchemy fails to decode this line.

```
INFO:sqlalchemy.engine.Engine:SHOW CREATE TABLE `t`
INFO:sqlalchemy.engine.Engine:[raw sql] ()
DEBUG:sqlalchemy.engine.Engine:Col ('Table', 'Create Table')
DEBUG:sqlalchemy.engine.Engine:Row ('t', 'CREATE TABLE `t` (\n  `id` int(11) NOT NULL,\n  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin')
INFO:root:LINE:   PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
/home/dvaneeden/dev/sqlalchemy_tidb/./sqlalchemy_tidb.py:26: SAWarning: Unknown schema content: '  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */'
  metadata.reflect(engine, only=['t'])
```

```
mysql> show create table t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `id` int(11) NOT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.00 sec)

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v5.2.0-alpha-88-ged52601e6
Edition: Community
Git Commit Hash: ed52601e6eb560138db8cdccdfa1b5e2d33a11f0
Git Branch: master
UTC Build Time: 2021-06-16 13:03:48
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)
```
lib/sqlalchemy/dialects/mysql/reflection.py
test/dialect/mysql/test_reflection.py