根据flyway的mysql数据库默认配置,flyway使用INNODB作为默认存储引擎来创建“schema_version表”。无论如何我可以将默认存储引擎设置为MyISAM ??我试图打开flyway的jar并从代码库进行更改。我还找到了创建schema_version表的.sql文件。但是在更改了该文件并再次打包后,我无法运行飞路。有任何配置更改???从哪里我可以改变它作为参数。 我正在使用flyway 4.0.3的社区版本
答案 0 :(得分:0)
我建议尽可能避免修改Flyway来源。
您可以在Flyway创建后简单地更改表引擎吗?如果这不可能,那么在使用Flyway之前,您可以自己创建schema_version表,从而有效地伪造基线。
答案 1 :(得分:0)
我有完全相同的问题。我的客户禁用了InnoDB引擎。 Flyway不允许您自定义引擎。它是硬编码的:
所以我必须自己执行这一步。这不是那么多工作:
private static void baselineWithDefaultStorageEngine(Flyway flyway) {
try (Connection con = flyway.getDataSource().getConnection()) {
if (!versionTableExisting(con, flyway)) {
createVersionTable(con);
setBaseline(con);
}
} catch (SQLException e) {
throw new RuntimeException("Konnte Flyway Baseline für " + flyway.getDataSource() + " nicht erstellen.", e);
}
}
private static void createVersionTable(Connection con) throws SQLException {
try(PreparedStatement stmt = con.prepareStatement("CREATE TABLE flyway_schema_history ( " +
"`installed_rank` INT NOT NULL, " +
"`version` VARCHAR(50), " +
"`description` VARCHAR(200) NOT NULL, " +
"`type` VARCHAR(20) NOT NULL, " +
"`script` VARCHAR(1000) NOT NULL, " +
"`checksum` INT, " +
"`installed_by` VARCHAR(100) NOT NULL, " +
"`installed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " +
"`execution_time` INT NOT NULL, " +
"`success` BOOL NOT NULL, " +
"CONSTRAINT `flyway_schema_history_pk` PRIMARY KEY (`installed_rank`), " +
"INDEX `flyway_schema_history_s_idx` (`success`) " +
");")) {
stmt.execute();
}
}
private static void setBaseline(Connection con) throws SQLException {
try (PreparedStatement stmt = con.prepareStatement("INSERT INTO `flyway_schema_history` " +
"(`installed_rank`, `version`, `description`, `type`, `script`, `installed_by`, `execution_time`, `success`) VALUES " +
"(?, ?, ?, ?, ?, ?, ?, ?)")) {
stmt.setInt(1, 1);
stmt.setInt(2, 1);
stmt.setString(3, "<< Flyway Baseline >>");
stmt.setString(4, "BASELINE");
stmt.setString(5, "<< Flyway Baseline >>");
stmt.setString(6, "root");
stmt.setInt(7, 0);
stmt.setInt(8, 1);
stmt.execute();
}
}
private static boolean versionTableExisting(Connection con, Flyway flyway) throws SQLException {
try (PreparedStatement stmt = con.prepareStatement("show tables like 'flyway_schema_history'")) {
try (ResultSet resultSet = stmt.executeQuery()) {
return resultSet.next();
}
}
}