Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlc: additional ALTER support #5705

Closed
jmhodges opened this issue Jan 13, 2020 · 2 comments
Closed

sqlc: additional ALTER support #5705

jmhodges opened this issue Jan 13, 2020 · 2 comments
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)

Comments

@jmhodges
Copy link
Contributor

jmhodges commented Jan 13, 2020

Feature Description

ALTER statements involving ADD, DROP, RENAME, and SET are currently parsed by sqlparser only enough to extract the table they involved. It's desirable for those ALTER statements to add information to the returned sqlparser.DDL about what columns or settings they're modifying.

Use Case(s)

sqlparser is being used by sqlc, a SQL to Go code generator, and needs this information to correctly generate code from database migrations and other code using ALTER statements.

@jmhodges
Copy link
Contributor Author

jmhodges commented Jan 13, 2020

This change would involve, at least, changes to sql.y and additions to the DDL struct for the new information.

(This was discussed in the vitess slack with @systay and @acharis. The understanding is that someone like me or @cmoog from outside vitess would do this work.)

jmhodges added a commit to jmhodges/vitess that referenced this issue Jan 29, 2020
This is a significant, but not complete expansion of the ALTER support in
sqlparser.

It adds support for these ALTER commands:

* `ADD COLUMN`
* `DROP COLUMN`
* `ADD INDEX`
* `DROP INDEX`
* `DROP FOREIGN KEY`
* `DROP PRIMARY KEY`
* `ADD PARTITION`
* `DROP PARTITION`
* `ADD CHECK` (as a no-op; it's parsed but never executed by mysql servers)

The main addition with this API is an additional field on `DDL` that is a slice
of newly created `AlterSpecs`. An `AlterSpec` represents one of the commands
that can occur in the same `ALTER` statement with other commands. This
differentiates them from the `ALTER` statement parse states already in `sql.y`
which are concerned with `ALTER` commands that must be the sole commands in the
statement.

The `ADD PARTITION` and `DROP PARTITION` states are the exception and are new
singleton commands that `sql.y` now supports.

This patch also includes some incidental updates to `go.mod` because of tooling
issues (described in vitessio#5755) and are duplicated in vitessio#5766

Updates vitessio#5705

Signed-off-by: Jeff Hodges <jeff@somethingsimilar.com>
@harshit-gangal harshit-gangal added Component: Parser Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature) labels Nov 2, 2020
@harshit-gangal harshit-gangal changed the title additional ALTER support sqlc: additional ALTER support Nov 2, 2020
@GuptaManan100
Copy link
Member

Support for this was added in #7199. If anything is missing and still needs to be added, kindly reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

No branches or pull requests

4 participants