Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ makeevrserg.java.ktarget=21
# Project
makeevrserg.project.name=SoulKeeper
makeevrserg.project.group=ru.astrainteractive.soulkeeper
makeevrserg.project.version.string=1.3.0
makeevrserg.project.version.string=1.4.0
makeevrserg.project.description=Keep your items after death
makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com
makeevrserg.project.url=https://github.com/Astra-Interactive/SoulKeeper
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jda-webhook = "0.8.4"
klibs-gradleplugin = "1.13.2"
klibs-kdi = "1.4.8"
klibs-kstorage = "4.5.0"
klibs-mikro = "1.20.0"
klibs-mikro = "1.22.0"
kotlin-benchmark = "0.4.16"
kotlin-coroutines = "1.10.2"
kotlin-datetime = "0.7.1-0.6.x-compat"
Expand All @@ -26,7 +26,7 @@ kotlin-serialization = "1.10.0"
kotlin-serialization-kaml = "0.104.0"
kotlin-version = "2.2.0"
ktor = "3.4.0"
minecraft-astralibs = "3.31.2"
minecraft-astralibs = "3.31.3"
minecraft-bstats = "3.2.1"
minecraft-bungee = "1.21-R0.5-SNAPSHOT"
minecraft-essentialsx = "2.21.2"
Expand Down Expand Up @@ -75,7 +75,7 @@ jda = { module = "net.dv8tion:JDA", version.ref = "jda" }
klibs-kdi = { module = "ru.astrainteractive.klibs:kdi-jvm", version.ref = "klibs-kdi" }
klibs-kstorage = { module = "ru.astrainteractive.klibs:kstorage", version.ref = "klibs-kstorage" }
klibs-mikro-core = { module = "ru.astrainteractive.klibs:mikro-core", version.ref = "klibs-mikro" }
klibs-mikro-extensions = { module = "ru.astrainteractive.klibs:mikro-extensions", version.ref = "klibs-mikro" }
klibs-mikro-extensions = { module = "ru.astrainteractive.klibs:mikro-extensions-jvm", version.ref = "klibs-mikro" }
kotlin-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlin-benchmark" }
kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutines" }
kotlin-coroutines-coreJvm = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "kotlin-coroutines" }
Expand Down
1 change: 1 addition & 0 deletions instances/neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
}

repositories {
mavenCentral()
mavenLocal()
}

Expand Down
4 changes: 4 additions & 0 deletions modules/dao/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ dependencies {
implementation(libs.klibs.mikro.extensions)
implementation(libs.klibs.mikro.core)
implementation(libs.klibs.kstorage)

testImplementation(libs.tests.kotlin.test)
testImplementation(libs.kotlin.coroutines.test)
testImplementation(libs.driver.jdbc)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package ru.astrainteractive.soulkeeper.module.souls.database.model
import kotlinx.serialization.Serializable
import ru.astrainteractive.astralibs.server.location.Location
import ru.astrainteractive.klibs.mikro.extensions.serialization.JInstantSerializer
import ru.astrainteractive.klibs.mikro.extensions.serialization.UUIDSerializer
import ru.astrainteractive.klibs.mikro.extensions.serialization.JUuidSerializer
import java.time.Instant
import java.util.UUID

@Serializable
data class DefaultSoul(
@Serializable(with = UUIDSerializer::class)
@Serializable(with = JUuidSerializer::class)
override val ownerUUID: UUID,
override val ownerLastName: String,
@Serializable(with = JInstantSerializer::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package ru.astrainteractive.soulkeeper.module.souls.di

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.retry
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.launch
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.TransactionManager
Expand All @@ -19,7 +19,7 @@ import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers
import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger
import ru.astrainteractive.klibs.mikro.core.logging.Logger
import ru.astrainteractive.klibs.mikro.exposed.model.DatabaseConfiguration
import ru.astrainteractive.klibs.mikro.exposed.util.connect
import ru.astrainteractive.klibs.mikro.exposed.util.connectAsFlow
import ru.astrainteractive.soulkeeper.module.souls.dao.SoulsDao
import ru.astrainteractive.soulkeeper.module.souls.dao.SoulsDaoImpl
import ru.astrainteractive.soulkeeper.module.souls.database.table.SoulItemsTable
Expand Down Expand Up @@ -61,22 +61,24 @@ interface SoulsDaoModule {
latestDbVersion = 2
)

override val databaseFlow: Flow<Database> = flow {
fileMigrations.forEach { migration -> migration.migrate() }
private val dbConfigurationFlow = flow {
if (!dataFolder.exists()) dataFolder.mkdirs()
val database = dataFolder.resolve("souls_v3")
val configuration = dataFolder.resolve("souls_v3")
.absolutePath
.let(DatabaseConfiguration::SQLite)
.connect()
TransactionManager.manager.defaultIsolationLevel = java.sql.Connection.TRANSACTION_SERIALIZABLE
databaseMigrator.migrate(database)

transaction(database) {
SchemaUtils.create(SoulTable)
SchemaUtils.create(SoulItemsTable)
}
emit(database)
emit(configuration)
}
override val databaseFlow: Flow<Database> = dbConfigurationFlow
.onStart { fileMigrations.forEach { migration -> migration.migrate() } }
.flatMapLatest { databaseConfiguration -> databaseConfiguration.connectAsFlow() }
.onEach { database -> databaseMigrator.migrate(database) }
.onEach { database ->
TransactionManager.manager.defaultIsolationLevel = java.sql.Connection.TRANSACTION_SERIALIZABLE
transaction(database) {
SchemaUtils.create(SoulTable)
SchemaUtils.create(SoulItemsTable)
}
}
.retry { throwable ->
error(throwable) { "Could not connect to database" }
delay(5000L)
Expand All @@ -90,11 +92,7 @@ interface SoulsDaoModule {
)

override val lifecycle: Lifecycle = Lifecycle.Lambda(
onDisable = {
GlobalScope.launch(dispatchers.IO) {
databaseFlow.firstOrNull()?.let(TransactionManager::closeAndUnregister)
}
}
onDisable = {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ru.astrainteractive.klibs.mikro.core.logging.Logger
class DatabaseMigrator(
private val migrations: List<DatabaseMigration>,
private val latestDbVersion: Int
) : Logger by JUtiltLogger("DatabaseMigrator") {
) : Logger by JUtiltLogger("SoulKeeper-DatabaseMigrator") {

suspend fun migrate(database: Database) {
val currentDbVersion = getCurrentVersion(database)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ru.astrainteractive.soulkeeper.module.souls.migration.core.DatabaseMigrat

class DropBrokenCreatedAtMigration :
DatabaseMigration,
Logger by JUtiltLogger("DropBrokenCreatedAtMigration") {
Logger by JUtiltLogger("SoulKeeper-DropBrokenCreatedAtMigration") {

override val requiredDbVersion: Int = 1
override suspend fun migrate(database: Database) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.time.Instant

class MakeCreatedAtNonNullMigration :
DatabaseMigration,
Logger by JUtiltLogger("MakeCreatedAtNonNullMigration") {
Logger by JUtiltLogger("SoulKeeper-MakeCreatedAtNonNullMigration") {

override val requiredDbVersion: Int = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.io.File
class H2ToSqliteMigration(
val dataFolder: File,
val dispatchers: KotlinDispatchers
) : FileMigration, Logger by JUtiltLogger("H2ToSqliteMigration") {
) : FileMigration, Logger by JUtiltLogger("SoulKeeper-H2ToSqliteMigration") {

override suspend fun migrate() = coroutineScope {
if (!dataFolder.resolve("souls_v2.mv.db").exists()) return@coroutineScope
Expand Down
7 changes: 1 addition & 6 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
pluginManagement {
repositories {
maven("https://maven.neoforged.net/releases") {
content {
excludeGroupByRegex("ru\\.astrainteractive.*")
}
}
maven("https://maven.neoforged.net/releases")
maven("https://plugins.gradle.org/m2/")
maven("https://jitpack.io")
gradlePluginPortal()
Expand All @@ -21,7 +17,6 @@ buildscript {

dependencyResolutionManagement {
repositories {
mavenLocal()
gradlePluginPortal()
mavenCentral()
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
Expand Down
Loading