我一直在研究如何使用gh-ost,它似乎还没有集成到像flyway/liquibase这样的工具中。gh-ost必须像这样运行:
./gh-ost --host=XXX--user=XXXX--password=XXXX--database=XXX--table=XXX --alter="ADD COLUMN XXX INT NOT NULL DEFAULT '0'"表名和"alter“sql命令似乎是gh-ost命令参数的一部分。
有没有什么方法可以使用像flyway/liquibase这样的工具所提供的最大好处(在线模式迁移)?
发布于 2017-09-05 11:51:39
它看起来并不是微不足道的。使用Flyway,您可以使用Custom Migration resolvers & executors在gh-ost命令中包装特殊文件。为了进行概念验证,您可以使用java类迁移来调用操作系统来运行Gh-ost命令。
发布于 2018-12-12 18:47:54
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
}
}https://stackoverflow.com/questions/45921207
复制相似问题