Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit f1c090d

Browse files
committed
feat: add ExposedMigrationGenerator for simplified database migration handling
1 parent 71a0e1f commit f1c090d

File tree

4 files changed

+60
-28
lines changed

4 files changed

+60
-28
lines changed

surf-cloud-api/surf-cloud-api-server/src/main/kotlin/dev/slne/surf/cloud/api/server/exposed/columns/ComponentColumnType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ComponentColumnType : ColumnType<Component>() {
2020
}
2121

2222
override fun notNullValueToDB(value: Component): Any =
23-
GsonComponentSerializer.gson().serialize(value)
23+
GsonComponentSerializer.gson().serialize(value.compact())
2424
}
2525

2626
fun Table.component(name: String): Column<Component> = registerColumn(name, ComponentColumnType())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dev.slne.surf.cloud.api.server.exposed.migration
2+
3+
import MigrationUtils
4+
import dev.slne.surf.cloud.api.common.config.properties.requiredSystemProperty
5+
import org.jetbrains.exposed.sql.Database
6+
import org.jetbrains.exposed.sql.ExperimentalDatabaseMigrationApi
7+
import org.jetbrains.exposed.sql.Table
8+
import org.jetbrains.exposed.sql.transactions.transaction
9+
10+
11+
@OptIn(ExperimentalDatabaseMigrationApi::class)
12+
fun generateSimpleExposedMigration(
13+
vararg tables: Table,
14+
scriptName: String,
15+
scriptDirectory: String = "src/main/resources/db/migration"
16+
) {
17+
generateExposedMigration {
18+
transaction(database) {
19+
MigrationUtils.generateMigrationScript(
20+
*tables,
21+
scriptName = scriptName,
22+
scriptDirectory = scriptDirectory
23+
)
24+
}
25+
}
26+
}
27+
28+
fun generateExposedMigration(generator: ExposedMigrationGenerator.() -> Unit) {
29+
val database = Database.connect(
30+
url = requiredSystemProperty("migration", "dbUrl") { it }.value(),
31+
user = requiredSystemProperty("migration", "dbUser") { it }.value(),
32+
password = requiredSystemProperty("migration", "dbPassword") { it }.value()
33+
)
34+
35+
val migrationGenerator = ExposedMigrationGenerator(database)
36+
generator(migrationGenerator)
37+
}
38+
39+
class ExposedMigrationGenerator(val database: Database)

surf-cloud-standalone/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dev.slne.surf.surfapi.gradle.util.slneReleases
12
import java.util.*
23

34
plugins {
@@ -90,4 +91,10 @@ kotlin {
9091
compilerOptions {
9192
optIn.add("dev.slne.surf.cloud.api.common.util.annotation.InternalApi")
9293
}
94+
}
95+
96+
publishing {
97+
repositories {
98+
slneReleases()
99+
}
93100
}
Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
package dev.slne.surf.cloud.standalone
22

3-
import MigrationUtils
4-
import dev.slne.surf.cloud.api.common.config.properties.requiredSystemProperty
3+
import dev.slne.surf.cloud.api.server.exposed.migration.generateSimpleExposedMigration
54
import dev.slne.surf.cloud.standalone.player.db.exposed.punishment.table.*
6-
import org.jetbrains.exposed.sql.Database
7-
import org.jetbrains.exposed.sql.ExperimentalDatabaseMigrationApi
8-
import org.jetbrains.exposed.sql.transactions.transaction
95

10-
val database = Database.connect(
11-
url = requiredSystemProperty("migration", "dbUrl") { it }.value(),
12-
user = requiredSystemProperty("migration", "dbUser") { it }.value(),
13-
password = requiredSystemProperty("migration", "dbPassword") { it }.value()
14-
)
15-
16-
@OptIn(ExperimentalDatabaseMigrationApi::class)
176
fun main() {
18-
transaction(database) {
19-
MigrationUtils.generateMigrationScript(
20-
BanPunishmentTable,
21-
KickPunishmentTable,
22-
MutePunishmentTable,
23-
WarnPunishmentTable,
24-
BanPunishmentIpAddressTable,
25-
BanPunishmentNoteTable,
26-
KickPunishmentNoteTable,
27-
MutePunishmentNoteTable,
28-
WarnPunishmentNoteTable,
29-
scriptDirectory = "src/main/resources/db/migration",
30-
scriptName = "V5__replace_string_uuid_with_native_uuid",
31-
)
32-
}
7+
generateSimpleExposedMigration(
8+
BanPunishmentTable,
9+
KickPunishmentTable,
10+
MutePunishmentTable,
11+
WarnPunishmentTable,
12+
BanPunishmentIpAddressTable,
13+
BanPunishmentNoteTable,
14+
KickPunishmentNoteTable,
15+
MutePunishmentNoteTable,
16+
WarnPunishmentNoteTable,
17+
scriptName = "V5__replace_string_uuid_with_native_uuid"
18+
)
3319
}

0 commit comments

Comments
 (0)