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

[parser] support create-table flag #1383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

najisawas
Copy link

@najisawas najisawas commented Mar 2, 2024

Description

This PR adds a new flag called "--create-table", an alternative to the "--alter" flag. With "--create-table" you can redefine the table that you want gh-ost to migrate to, effectively supporting what would have required multiple ALTERs.

For example, If you need to restructure the secondary indexes on a MySQL table, you would need to do the following:

Assuming a and b are already columns in the table...

  • ADD COLUMN xINT, ADD COLUMN y VARCHAR(24),
    ADD INDEX a_x_idx (a, x),
    ADD INDEX y_idx (y),
    DROP INDEX a_b_idx

Now you can simply provide a "--create-table" flag like so

--create-table="( ..., x INT, y VARCHAR(24), ... KEY a_x_idx (a,x), KEY y_idx (y) ...)"

The PR is a bit large as it includes some refactors to maintain code cleanliness. I can separate out some of the refactors into separate PRs for ease of review

@najisawas
Copy link
Author

#1384

@najisawas
Copy link
Author

tests still need to be expanded, but wanted to publish an initial revision for visibility

@ramshad-sha ramshad-sha mentioned this pull request Mar 25, 2024
Closed
@meiji163
Copy link
Contributor

I hesitate to continue expanding the regex-based SQL parsing. If you need to compute the ALTER statement from two CREATE TABLE statements I recommend using https://github.com/planetscale/schemadiff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants