diff --git a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightDatabase.java b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightDatabase.java index 9129ab74..c85385c9 100644 --- a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightDatabase.java +++ b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightDatabase.java @@ -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); @@ -46,6 +47,15 @@ private String getTableName(ResourceKey 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 dimension) { try (var statement = connection.createStatement()) { statement.executeUpdate("CREATE TABLE IF NOT EXISTS \"" + getTableName(dimension) + "\" (x INTEGER, z INTEGER, foundTime INTEGER)"); diff --git a/common/src/main/java/xaeroplus/feature/render/highlights/db/V0ToV1Migration.java b/common/src/main/java/xaeroplus/feature/render/highlights/db/V0ToV1Migration.java index 0d1b0645..34bba188 100644 --- a/common/src/main/java/xaeroplus/feature/render/highlights/db/V0ToV1Migration.java +++ b/common/src/main/java/xaeroplus/feature/render/highlights/db/V0ToV1Migration.java @@ -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()) {