Fix Reset

Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
2026-07-05 13:45:59 +02:00
parent b278ca15f3
commit 7acd51fd61
2 changed files with 115 additions and 4 deletions
+8 -4
View File
@@ -7,6 +7,7 @@ import com.github.ajalt.mordant.rendering.TextColors
import com.github.ajalt.mordant.rendering.TextStyles
import de.steamwar.db.Database
import de.steamwar.db.execute
import de.steamwar.db.executeScript
import de.steamwar.db.useDb
import java.io.File
@@ -24,17 +25,20 @@ class ResetCommand : CliktCommand() {
execute("SET FOREIGN_KEY_CHECKS=0;") { }
val tables = execute("SHOW TABLES;") { it.getString(1) }
for (table in tables) {
val databaseObjects = execute("SHOW FULL TABLES;") { it.getString(1) to it.getString(2) }
for (view in databaseObjects.filter { it.second == "VIEW" }.map { it.first }) {
execute("DROP VIEW IF EXISTS `${view.replace("`", "``")}`;") { }
}
for (table in databaseObjects.filter { it.second == "BASE TABLE" }.map { it.first }) {
execute("DROP TABLE IF EXISTS `${table.replace("`", "``")}`;") { }
}
execute(schema) { }
executeScript(schema)
val seed = javaClass.getResource("/db/reset-seed.sql")
?: throw CliktError("Reset seed file not found!")
execute(seed.readText()) { }
executeScript(seed.readText())
execute("SET FOREIGN_KEY_CHECKS=1;") { }