Skip to content

Commit

Permalink
fix: migrate server status monitor collection due to a package name c…
Browse files Browse the repository at this point in the history
…hange
  • Loading branch information
DarkAtra committed Jun 16, 2024
1 parent 2784f37 commit 48bebd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ class DatabaseMigrationService(
document["recentErrors"] = emptyList<Any>()
}
}
),
DatabaseMigration(
description = "Migrate the existing ServerStatusMonitor collection to the new collection name introduced by a package change.",
isApplicable = { currentSchemaVersion -> currentSchemaVersion.major < 2 || (currentSchemaVersion.major == 2 && currentSchemaVersion.minor <= 10 && currentSchemaVersion.patch <= 1) },
databaseAction = { database ->
val oldCollection = database.getCollection("de.darkatra.vrising.discord.serverstatus.model.ServerStatusMonitor")
val newCollection = database.getCollection(ObjectUtils.findObjectStoreName(ServerStatusMonitor::class.java))
oldCollection.find().forEach { document ->
newCollection.insert(document)
}
oldCollection.remove(ObjectFilters.ALL)
}
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ class DatabaseMigrationServiceTest {
repository.insert(Schema(appVersion = "V2.3.0"))
repository.insert(Schema(appVersion = "V2.9.0"))
repository.insert(Schema(appVersion = "V2.10.0"))
repository.insert(Schema(appVersion = "V2.10.2"))

val databaseMigrationService = DatabaseMigrationService(
database = database,
appVersionFromPom = "2.10.0"
appVersionFromPom = "2.10.2"
)

assertThat(databaseMigrationService.migrateToLatestVersion()).isFalse()

val schemas = repository.find().toList()
assertThat(schemas).hasSize(8)
assertThat(schemas).hasSize(9)
}

@Test
Expand Down

0 comments on commit 48bebd7

Please sign in to comment.