forked from SteamWar/SteamWar
1451750bcb
- add Clikt-based `sw` entrypoint and subcommands - include database, user, dev, and profiler commands - wire CLI build and CI install/release steps
33 lines
977 B
Kotlin
33 lines
977 B
Kotlin
package de.steamwar.commands.database
|
|
|
|
import com.github.ajalt.clikt.core.CliktCommand
|
|
import com.github.ajalt.clikt.core.CliktError
|
|
import com.github.ajalt.clikt.core.requireObject
|
|
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.useDb
|
|
import java.io.File
|
|
|
|
class ResetCommand: CliktCommand() {
|
|
val db by requireObject<Database>()
|
|
|
|
override fun run() = useDb {
|
|
val schemaFile = File("/var/Schema.sql")
|
|
if (!schemaFile.exists()) {
|
|
throw CliktError("Schema file not found!")
|
|
}
|
|
|
|
val schema = schemaFile.readText()
|
|
|
|
val tables = execute("SHOW TABLES;") { it.getString(1) }
|
|
for (table in tables) {
|
|
execute("DROP TABLE IF EXISTS $table;") { }
|
|
}
|
|
|
|
execute(schema) { }
|
|
|
|
echo(TextColors.brightGreen(TextStyles.bold("Database reset!")))
|
|
}
|
|
} |