-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow pausing specific server status monitors
* rollback to kotlin 1.6.21 as kord does not seem to support kotlin 1.7.0 yet
- Loading branch information
Showing
15 changed files
with
158 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
src/main/kotlin/de/darkatra/vrising/discord/DatabaseMigrationService.kt
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/de/darkatra/vrising/discord/DatabaseUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package de.darkatra.vrising.discord | ||
|
||
import org.dizitart.kno2.filters.and | ||
import org.dizitart.no2.objects.ObjectFilter | ||
|
||
operator fun ObjectFilter?.plus(other: ObjectFilter?): ObjectFilter? { | ||
if (this == null && other == null) { | ||
return null | ||
} | ||
if (this != null && other != null) { | ||
return this.and(other) | ||
} | ||
return this ?: other | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/de/darkatra/vrising/discord/ServerStatusMonitorStatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package de.darkatra.vrising.discord | ||
|
||
enum class ServerStatusMonitorStatus { | ||
INACTIVE, | ||
ACTIVE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/de/darkatra/vrising/discord/migration/DatabaseMigration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package de.darkatra.vrising.discord.migration | ||
|
||
import de.darkatra.vrising.discord.ServerStatusMonitorBuilder | ||
|
||
data class DatabaseMigration( | ||
val isApplicable: (currentSchemaVersion: SemanticVersion) -> Boolean, | ||
val action: (serverStatusMonitorBuilder: ServerStatusMonitorBuilder) -> Unit | ||
) |
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/de/darkatra/vrising/discord/migration/DatabaseMigrationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package de.darkatra.vrising.discord.migration | ||
|
||
import de.darkatra.vrising.discord.ServerStatusMonitorService | ||
import de.darkatra.vrising.discord.ServerStatusMonitorStatus | ||
import org.dizitart.no2.Nitrite | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class DatabaseMigrationService( | ||
database: Nitrite, | ||
private val serverStatusMonitorService: ServerStatusMonitorService, | ||
@Value("\${version}") | ||
private val currentAppVersion: String | ||
) { | ||
|
||
private val logger = LoggerFactory.getLogger(javaClass) | ||
private val repository = database.getRepository(Schema::class.java) | ||
|
||
private val migrations: List<DatabaseMigration> = listOf( | ||
DatabaseMigration( | ||
isApplicable = { currentSchemaVersion -> currentSchemaVersion.major == 1 && currentSchemaVersion.minor <= 3 }, | ||
action = { serverStatusMonitorBuilder -> serverStatusMonitorBuilder.displayPlayerGearLevel = true } | ||
), | ||
DatabaseMigration( | ||
isApplicable = { currentSchemaVersion -> currentSchemaVersion.major == 1 && currentSchemaVersion.minor <= 4 }, | ||
action = { serverStatusMonitorBuilder -> serverStatusMonitorBuilder.status = ServerStatusMonitorStatus.ACTIVE } | ||
) | ||
) | ||
|
||
fun migrateToLatestVersion() { | ||
|
||
// find the current version or default to V1.3.0 (the version before this feature was introduced) | ||
val currentSchemaVersion = repository.find().toList() | ||
.maxByOrNull(Schema::appVersion) | ||
?.let(Schema::appVersionAsSemanticVersion) | ||
?: SemanticVersion(major = 1, minor = 3, patch = 0) | ||
|
||
val migrationsToPerform = migrations.filter { migration -> migration.isApplicable(currentSchemaVersion) } | ||
if (migrationsToPerform.isNotEmpty()) { | ||
|
||
val (major, minor, patch) = currentSchemaVersion | ||
logger.info("Will migrate from V$major.$minor.$patch to V$currentAppVersion by performing ${migrationsToPerform.size} migrations.") | ||
|
||
serverStatusMonitorService.getServerStatusMonitors().forEach { serverStatusMonitor -> | ||
val serverStatusMonitorBuilder = serverStatusMonitor.builder() | ||
migrationsToPerform.forEach { migration -> migration.action(serverStatusMonitorBuilder) } | ||
serverStatusMonitorService.putServerStatusMonitor(serverStatusMonitorBuilder.build()) | ||
} | ||
|
||
repository.insert(Schema("V$currentAppVersion")) | ||
logger.info("Database migration from V$major.$minor.$patch to V$currentAppVersion was successful.") | ||
} else { | ||
logger.info("No migrations need to be performed.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/de/darkatra/vrising/discord/migration/SemanticVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.darkatra.vrising.discord.migration | ||
|
||
data class SemanticVersion( | ||
val major: Int, | ||
val minor: Int, | ||
val patch: Int | ||
) |