taozhi8833998 / node-sql-parser

Parse simple SQL statements into an abstract syntax tree (AST) with the visited tableList and convert it back to SQL
https://taozhi8833998.github.io/node-sql-parser/
Apache License 2.0
780 stars 174 forks source link

Errors when parsing column modification with before/after in the suffix #1864

Closed zwallacedev closed 4 months ago

zwallacedev commented 4 months ago

Describe the bug When using "ALTER TABLE product MODIFY COLUMN type enum('one','two') NOT NULL AFTER name", parser throws error: SyntaxError: Expected "#", ",", "--", "/*", ";", "AS", "AUTO_INCREMENT", "CHARACTER", "CHECK", "COLLATE", "COLUMN_FORMAT", "COMMENT", "CONSTRAINT", "DEFAULT", "GENERATED", "GO", "KEY", "NOT NULL", "NULL", "ON", "PRIMARY", "REFERENCES", "STORAGE", "UNIQUE", [ \t\n\r], or end of input but "A" found.

Database Engine MySQL

To Reproduce

Expected behavior This should parse correctly, and it should accept "AFTER" as part of the suffix.

Additional context The "After" is not important, but I am using this to run against a large set of migrations that may or may not have before/after column modifications in there.

zwallacedev commented 4 months ago

FWIW - I cloned the repo locally, and I was attempting to run the tests on this, but when running npm install, I was getting errors as well:

npm ERR! code CERT_HAS_EXPIRED
npm ERR! errno CERT_HAS_EXPIRED
npm ERR! request to https://registry.npm.taobao.org/url/download/url-0.11.0.tgz failed, reason: certificate has expired

npm ERR! A complete log of this run can be found in: /Users/nearpoduser/.npm/_logs/2024-04-11T00_14_47_539Z-debug-0.log
taozhi8833998 commented 4 months ago

@zwallacedev Sorry for the expired link. I have fixed the issue and the npm install error, you can get the latest codes later.

zwallacedev commented 4 months ago

Thank you so much! I will do my best to add some contribution to your project. This has been super useful for me 👍