migrate icon indicating copy to clipboard operation
migrate copied to clipboard

Supporting gh-ost or other online schma change tools for MySQL

Open fzyzcjy opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe. As we all know, making schema changes for MySQL can be painful, so some big names made tools to ease the problem, such as github's gh-ost.

Describe the solution you'd like let golang-migrate support gh-ost.

Describe alternatives you've considered manually do it. but it is not wise as we already have such a wonderful tool - the golang migrate!

Additional context N/A

fzyzcjy avatar Jun 07 '21 13:06 fzyzcjy

+1 to this. I am working on adding gh-ost to our migration workflow and would love to see this built-in to migrate if possible.

I recently created a custom build of migrate that handles this, and am wondering if it makes sense to merge this functionality back in here? I'd be happy to put together a PR for this if that is the case.

With OSC tools like this the way it usually works is that ALTER TABLE statements are passed to the OSC tool, and other statements (ADD/DROP TABLE, etc) are run directly against the database (as their performance impact is negligible).

For my build I added an alter-handler option to the MySQL driver, that accepts the path to a script/executable that should be run to apply ALTER TABLE statements. If this option is specified, multi-statement migrations are split (similar to how the Postgres driver does it), and statements are evaluated one-by-one. ALTER TABLE statements are passed to the script specified in the alter-handler option (with environment variables containing the SQL, and DB connection parameters), and all other statements are run using the default migrate database connection.

Note: I was inspired by how skeema handles this via their alter-wrapper command line option.

jkirkwood avatar Jun 21 '21 14:06 jkirkwood

@jkirkwood I have to do something similar to what you have described: forward all the ALTER TABLE to go-ost while the other migrations are still handle by the go-migrate. Any chance you can share what you ended up doing?

ricleal avatar Oct 29 '23 23:10 ricleal

@jkirkwood @ricleal any updates on this ?

DeathBorn avatar Jan 24 '24 12:01 DeathBorn

Not from me. My project was deprioritized...

ricleal avatar Jan 25 '24 16:01 ricleal