From ed4488dc897e8dbf91c023fe992b91f6e13e78f2 Mon Sep 17 00:00:00 2001 From: Potatoboy9999 <51728317+PotatoPresident@users.noreply.github.com> Date: Mon, 15 Jun 2026 21:41:29 -0700 Subject: [PATCH] Add config option for running database schema updates (defaults to false) --- gradle.properties | 2 +- .../quiltservertools/ledger/config/DatabaseSpec.kt | 1 + .../ledger/database/DatabaseManager.kt | 10 ++++++---- src/main/resources/ledger.toml | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index d2b369ee..d3c26029 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ kotlin.code.style=official org.gradle.jvmargs=-Xmx2G # Mod Properties -modVersion = 1.3.21 +modVersion = 1.3.22 mavenGroup = com.github.quiltservertools modId = ledger modName = Ledger diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/config/DatabaseSpec.kt b/src/main/kotlin/com/github/quiltservertools/ledger/config/DatabaseSpec.kt index d5b7656b..51aeeccf 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/config/DatabaseSpec.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/config/DatabaseSpec.kt @@ -15,6 +15,7 @@ object DatabaseSpec : ConfigSpec() { val batchDelay by optional(10) val logSQL by optional(false) val location by optional(null) + val updateSchema by optional(false) } fun Config.getDatabasePath(): Path { diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt b/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt index b2d47d9d..bb6a5f58 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt @@ -122,10 +122,12 @@ object DatabaseManager { Tables.Sources, Tables.Worlds, ) - try { - exec("CREATE INDEX IF NOT EXISTS actions_time ON actions(time)") - } catch (e: java.sql.SQLException) { - logWarn("Could not create actions_time index (MySQL 8.0.12+ required if using MySQL): ${e.message}") + if (config[DatabaseSpec.updateSchema]) { + try { + exec("CREATE INDEX IF NOT EXISTS actions_time ON actions(time)") + } catch (e: java.sql.SQLException) { + logWarn("Could not create actions_time index (MySQL 8.0.12+ required if using MySQL): ${e.message}") + } } logInfo("Tables created") } diff --git a/src/main/resources/ledger.toml b/src/main/resources/ledger.toml index d3aaa47d..499b3dd7 100644 --- a/src/main/resources/ledger.toml +++ b/src/main/resources/ledger.toml @@ -11,6 +11,8 @@ batchSize = 1000 batchDelay = 10 # The location of the database file. Defaults to the world folder if not specified #location = "./custom-dir" +# Allow the database format to be updated on startup (can be slow) +updateSchema = false [search] # Number of actions to show per page