Skip to content

Commit

Permalink
Fix meta breaking the whole thing
Browse files Browse the repository at this point in the history
  • Loading branch information
NoComment1105 committed Aug 22, 2023
1 parent 43feb32 commit c90065c
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ private fun <T : Any> MongoCollection<T>.find(vararg filters: Bson?): FindFlow<T

suspend fun <T : Any> MongoCollection<T>.findOne(filter: Bson): T? = find(filter).firstOrNull()

suspend fun <T : Any> MongoCollection<T>.findOne(vararg filters: Bson?): T? =
find(*filters).firstOrNull()
suspend fun <T : Any> MongoCollection<T>.findOne(vararg filters: Bson?): T? = find(*filters).firstOrNull()

suspend fun <T : Any> MongoCollection<T>.deleteOne() = deleteOne(Filters.empty())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MainMetaCollection : KordExKoinComponent {
* @since 4.0.0
*/
suspend fun get(): MainMetaData? =
collection.findOne()
collection.findOne(eq(MainMetaData::id.name, "mainMeta"))

/**
* Sets the metadata when the table is first created.
Expand Down Expand Up @@ -78,7 +78,7 @@ class ConfigMetaCollection : KordExKoinComponent {
* @since 4.0.0
*/
suspend fun get(): ConfigMetaData? =
collection.findOne()
collection.findOne(eq(ConfigMetaData::id.name, "configMeta"))

/**
* Sets the metadata when the table is first created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object Migrator : KordExKoinComponent {
6 -> ::configV6
7 -> ::configV7
else -> break
}(db.configDatabase, db.tempKordExDatabase)
}(db.configDatabase)

logger.info { "Migrated config database to version $nextVersion" }
} catch (t: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import com.mongodb.client.model.Updates
import com.mongodb.kotlin.client.coroutine.MongoDatabase
import org.hyacinthbots.lilybot.database.entities.LoggingConfigData

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
suspend fun configV1(configDb: MongoDatabase, tempKeDb: MongoDatabase) {
suspend fun configV1(configDb: MongoDatabase) {
with(configDb.getCollection<LoggingConfigData>("loggingConfigData")) {
updateMany(
Filters.exists(LoggingConfigData::enableMessageEditLogs.name, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import com.mongodb.client.model.Updates
import com.mongodb.kotlin.client.coroutine.MongoDatabase
import org.hyacinthbots.lilybot.database.entities.ModerationConfigData

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
suspend fun configV2(db: MongoDatabase, tempKeDb: MongoDatabase) {
suspend fun configV2(db: MongoDatabase) {
with(db.getCollection<ModerationConfigData>("moderationConfigData")) {
updateMany(
Filters.exists(ModerationConfigData::quickTimeoutLength.name, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import com.mongodb.client.model.Updates
import com.mongodb.kotlin.client.coroutine.MongoDatabase
import org.hyacinthbots.lilybot.database.entities.LoggingConfigData

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
suspend fun configV3(db: MongoDatabase, tempKeDb: MongoDatabase) {
suspend fun configV3(db: MongoDatabase) {
with(db.getCollection<LoggingConfigData>("loggingConfigData")) {
updateMany(
Filters.exists(LoggingConfigData::enablePublicMemberLogs.name, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.hyacinthbots.lilybot.database.migrations.config
import com.mongodb.kotlin.client.coroutine.MongoDatabase

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER", "RedundantSuspendModifier")
suspend fun configV4(db: MongoDatabase, tempKeDb: MongoDatabase) {
suspend fun configV4(db: MongoDatabase) {
// Support config has been removed.
// if (db.getCollection<SupportConfigData>().find().toList().isEmpty()) {
// db.dropCollection("supportConfigData")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package org.hyacinthbots.lilybot.database.migrations.config

import com.mongodb.kotlin.client.coroutine.MongoDatabase

suspend fun configV5(db: MongoDatabase, tempKeDb: MongoDatabase) {
suspend fun configV5(db: MongoDatabase) {
// val collection = db.getCollection<UtilityConfigDataOld>("utilityConfigData")
// val oldConfigs = collection.find().toList()
// val newConfigs = mutableListOf<UtilityConfigData>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import com.mongodb.client.model.Updates
import com.mongodb.kotlin.client.coroutine.MongoDatabase
import org.hyacinthbots.lilybot.database.entities.ModerationConfigData

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
suspend fun configV6(db: MongoDatabase, tempKeDb: MongoDatabase) {
suspend fun configV6(db: MongoDatabase) {
with(db.getCollection<ModerationConfigData>("moderationConfigData")) {
updateMany(
Filters.exists(ModerationConfigData::banDmMessage.name, false),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
package org.hyacinthbots.lilybot.database.migrations.config

import com.mongodb.kotlin.client.coroutine.MongoDatabase
import kotlinx.coroutines.flow.toList
import org.hyacinthbots.lilybot.database.entities.AdaptedData

suspend fun configV7(db: MongoDatabase, tempKeDb: MongoDatabase) {
// Done twice due to updates in the data-adapter
with(db.getCollection<AdaptedData>("ext-pluralkit")) {
val data = find().toList()

tempKeDb.createCollection("data-ext-pluralkit") // create new with correct name
tempKeDb.getCollection<AdaptedData>("data-ext-pluralkit").insertMany(data) // add the data
drop() // drop old
}

with(db.getCollection<AdaptedData>("data-ext-pluralkit")) {
val data = find().toList()

tempKeDb.createCollection("data-ext-pluralkit") // create new
tempKeDb.getCollection<AdaptedData>("data-ext-pluralkit").insertMany(data) // add the data
drop() // drop old
}
suspend fun configV7(db: MongoDatabase) {
db.getCollection<AdaptedData>("ext-pluralkit").drop()
db.getCollection<AdaptedData>("data-ext-pluralkit").drop()
}

0 comments on commit c90065c

Please sign in to comment.