gh-ost icon indicating copy to clipboard operation
gh-ost copied to clipboard

[parser] support create-table flag

Open najisawas opened this issue 2 years ago • 3 comments

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 avatar Mar 02 '24 20:03 najisawas

#1384

najisawas avatar Mar 02 '24 20:03 najisawas

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

najisawas avatar Mar 02 '24 20:03 najisawas

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

meiji163 avatar Dec 19 '24 02:12 meiji163