Skip to content

Commit

Permalink
Merge branch '1.20.4' into 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jul 5, 2024
2 parents 5616020 + 274c4fa commit c8aa910
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public ChunkHighlightDatabase(String worldId, String databaseName) {
boolean shouldRunMigrations = dbPath.toFile().exists();
connection = DriverManager.getConnection("jdbc:rfresh_sqlite:" + dbPath);
if (shouldRunMigrations) MIGRATOR.migrate(dbPath, databaseName, connection);
createMetadataTable();
} catch (Exception e) {
XaeroPlus.LOGGER.error("Error while creating chunk highlight database: {} for worldId: {}", databaseName, worldId, e);
throw new RuntimeException(e);
Expand All @@ -46,6 +47,15 @@ private String getTableName(ResourceKey<Level> dimension) {
return dimension.location().toString();
}

private void createMetadataTable() {
try (var statement = connection.createStatement()) {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS metadata (id INTEGER PRIMARY KEY, version INTEGER)");
statement.executeUpdate("INSERT OR REPLACE INTO metadata (id, version) VALUES (0, 1)");
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private void createHighlightsTableIfNotExists(ResourceKey<Level> dimension) {
try (var statement = connection.createStatement()) {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS \"" + getTableName(dimension) + "\" (x INTEGER, z INTEGER, foundTime INTEGER)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ public boolean shouldMigrate(String databaseName, Connection connection) {

@Override
public void doMigration(String databaseName, final Connection connection) {
// create metadata table
try {
try (var statement = connection.createStatement()) {
statement.executeUpdate("CREATE TABLE IF NOT EXISTS metadata (version INTEGER)");
statement.executeUpdate("INSERT INTO metadata (version) VALUES (1)");
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Failed creating metadata table for {} database", databaseName, e);
}

// migrate old tables and indexes
try {
try (var statement = connection.createStatement()) {
Expand Down

0 comments on commit c8aa910

Please sign in to comment.