Improve database upgrade logic

This commit is contained in:
Brokkonaut
2021-01-30 17:34:24 +01:00
parent f42649adc3
commit 033a53e338

View File

@ -730,23 +730,15 @@ class Updater {
} }
if (configVersion.compareTo(new ComparableVersion("1.16.0")) < 0) { if (configVersion.compareTo(new ComparableVersion("1.16.0")) < 0) {
for (final WorldConfig wcfg : getLoggedWorlds()) { try (Connection conn = logblock.getConnection()) {
final Connection conn = logblock.getConnection(); conn.setAutoCommit(true);
try { final Statement st = conn.createStatement();
conn.setAutoCommit(true); for (final WorldConfig wcfg : getLoggedWorlds()) {
final Statement st = conn.createStatement(); createIndexIfDoesNotExist(wcfg.table + "-entities", "entityid", "KEY `entityid` (entityid)", st, false);
st.execute("ALTER TABLE `" + wcfg.table + "-entities` ADD KEY entityid (entityid)");
logblock.getLogger().info("Added index for table " + wcfg.table + "-entities");
st.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Warning: Could not upgrade the database: " + ex.getMessage());
} finally {
try {
conn.close();
} catch (SQLException e) {
// ignored
}
} }
st.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Warning: Could not add index", ex);
} }
config.set("version", "1.16.0"); config.set("version", "1.16.0");
} }