From 3291809f2fc392c9a3f43c9917599a1826d0b325 Mon Sep 17 00:00:00 2001 From: taozhi8833998 Date: Fri, 15 Dec 2023 10:19:59 +0800 Subject: [PATCH] fix: alter table drop index with identified in mysql --- pegjs/mariadb.pegjs | 2 +- pegjs/mysql.pegjs | 2 +- test/mysql-mariadb.spec.js | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pegjs/mariadb.pegjs b/pegjs/mariadb.pegjs index 253ed4dd..d3e018fd 100644 --- a/pegjs/mariadb.pegjs +++ b/pegjs/mariadb.pegjs @@ -913,7 +913,7 @@ ALTER_DROP_KEY_INDEX type: 'alter', } } - / KW_DROP __ k:(('FOREIGN'i? __ KW_KEY) / (KW_INDEX)) __ c:ident_name { + / KW_DROP __ k:(('FOREIGN'i? __ KW_KEY) / (KW_INDEX)) __ c:ident { const resource = Array.isArray(k) ? 'key' : 'index' return { action: 'drop', diff --git a/pegjs/mysql.pegjs b/pegjs/mysql.pegjs index 73544bf0..47ccf5e0 100644 --- a/pegjs/mysql.pegjs +++ b/pegjs/mysql.pegjs @@ -1203,7 +1203,7 @@ ALTER_DROP_KEY_INDEX type: 'alter', } } - / KW_DROP __ k:(('FOREIGN'i? __ KW_KEY) / (KW_INDEX)) __ c:ident_name { + / KW_DROP __ k:(('FOREIGN'i? __ KW_KEY) / (KW_INDEX)) __ c:ident { const resource = Array.isArray(k) ? 'key' : 'index' return { action: 'drop', diff --git a/test/mysql-mariadb.spec.js b/test/mysql-mariadb.spec.js index 1020cbdb..72770136 100644 --- a/test/mysql-mariadb.spec.js +++ b/test/mysql-mariadb.spec.js @@ -880,12 +880,19 @@ describe('mysql', () => { ] }, { - title: 'alter drop index or key', + title: 'alter drop index', sql: [ 'ALTER TABLE table_name DROP INDEX index_name', 'ALTER TABLE `table_name` DROP INDEX index_name' ] }, + { + title: 'alter drop key', + sql: [ + 'ALTER TABLE table_name DROP key `key_name`', + 'ALTER TABLE `table_name` DROP KEY `key_name`' + ] + }, ] SQL_LIST.forEach(sqlInfo => { const { title, sql } = sqlInfo