Skip to content

Commit ed4488d

Browse files
Add config option for running database schema updates (defaults to false)
1 parent a5c4624 commit ed4488d

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ kotlin.code.style=official
22
org.gradle.jvmargs=-Xmx2G
33

44
# Mod Properties
5-
modVersion = 1.3.21
5+
modVersion = 1.3.22
66
mavenGroup = com.github.quiltservertools
77
modId = ledger
88
modName = Ledger

src/main/kotlin/com/github/quiltservertools/ledger/config/DatabaseSpec.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ object DatabaseSpec : ConfigSpec() {
1515
val batchDelay by optional<Int>(10)
1616
val logSQL by optional<Boolean>(false)
1717
val location by optional<String?>(null)
18+
val updateSchema by optional<Boolean>(false)
1819
}
1920

2021
fun Config.getDatabasePath(): Path {

src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ object DatabaseManager {
122122
Tables.Sources,
123123
Tables.Worlds,
124124
)
125-
try {
126-
exec("CREATE INDEX IF NOT EXISTS actions_time ON actions(time)")
127-
} catch (e: java.sql.SQLException) {
128-
logWarn("Could not create actions_time index (MySQL 8.0.12+ required if using MySQL): ${e.message}")
125+
if (config[DatabaseSpec.updateSchema]) {
126+
try {
127+
exec("CREATE INDEX IF NOT EXISTS actions_time ON actions(time)")
128+
} catch (e: java.sql.SQLException) {
129+
logWarn("Could not create actions_time index (MySQL 8.0.12+ required if using MySQL): ${e.message}")
130+
}
129131
}
130132
logInfo("Tables created")
131133
}

src/main/resources/ledger.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ batchSize = 1000
1111
batchDelay = 10
1212
# The location of the database file. Defaults to the world folder if not specified
1313
#location = "./custom-dir"
14+
# Allow the database format to be updated on startup (can be slow)
15+
updateSchema = false
1416

1517
[search]
1618
# Number of actions to show per page

0 commit comments

Comments
 (0)