Reputation: 33
I've been investigating how to use gh-ost and it seems that is not yet integrated with tools like flyway/liquibase. gh-ost has to be run like this:
./gh-ost --host=XXX--user=XXXX--password=XXXX--database=XXX--table=XXX --alter="ADD COLUMN XXX INT NOT NULL DEFAULT '0'"
It seems that the table name and the "alter" sql commands are part of gh-ost command parameters.
Is there any way I can use gh-ost benefits(online schema migration) with what a tool like flyway/liquibase has to offer?
Upvotes: 1
Views: 939
Reputation: 33
private Flyway flyway = new Flyway();
GhostMigrationResolver ghostMigrationResolver = new GhostMigrationResolver();
flyway.setResolvers(ghostMigrationResolver);
public class GhostMigrationResolver extends BaseMigrationResolver {
private Set<String> ghostScriptFiles = new HashSet<>();
public void addGhostScript(String ghostUpdateScript) {
ghostScriptFiles.add(ghostUpdateScript);
}
@Override
public Collection<ResolvedMigration> resolveMigrations() {
Set<ResolvedMigration> resolvedMigrations = new HashSet<>();
for (String ghostScriptFile : ghostScriptFiles) {
GhostResolvedMigration ghostResolvedMigration = new GhostResolvedMigration();
ghostResolvedMigration.setScript(ghostScriptFile);
GhostExecutor executor = new GhostExecutor();
executor.setGhostScriptFile(ghostScriptFile);
ghostResolvedMigration.setExecutor(executor);
ghostResolvedMigration.setDescription(ghostScriptFile);
ghostResolvedMigration.setVersion(MigrationVersion.fromVersion(ghostScriptFile.substring(1, ghostScriptFile.indexOf("__"))));
ghostResolvedMigration.setType(MigrationType.CUSTOM);
resolvedMigrations.add(ghostResolvedMigration);
}
return resolvedMigrations;
}
}
public class GhostExecutor implements MigrationExecutor {
@Override
public void execute(Connection connection) throws SQLException {
//call ghost here
}
}
Upvotes: 2
Reputation: 851
It doesn't look trivial. With Flyway, you could use the Custom Migration resolvers & executors to wrap special files in the gh-ost command. For a proof-of-concept you could use a java class migration to call out to the operating system to run the Gh-ost command.
Upvotes: 0