Skip to content

Commit

Permalink
fix: copy the whole database when encrypting, not just all collections
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkAtra committed Nov 16, 2024
1 parent bf2b5bb commit bbace9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ fun Nitrite.getNitriteMap(name: String): NitriteMap<NitriteId, Document> {
}

fun Nitrite.listAllCollectionNames(): List<String> {
return store.openMap<String, Attributes>(Constants.META_MAP_NAME, String::class.java, Attributes::class.java).keys()
.filter { key -> !key.startsWith("\$nitrite") }
return store.openMap<String, Attributes>(Constants.META_MAP_NAME, String::class.java, Attributes::class.java).keys().toList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package de.darkatra.vrising.discord.persistence

import de.darkatra.vrising.discord.BotProperties
import de.darkatra.vrising.discord.migration.SchemaEntityConverter
import de.darkatra.vrising.discord.migration.getNitriteMap
import de.darkatra.vrising.discord.migration.listAllCollectionNames
import de.darkatra.vrising.discord.persistence.model.converter.ErrorEntityConverter
import de.darkatra.vrising.discord.persistence.model.converter.PlayerActivityFeedEntityConverter
Expand All @@ -11,6 +10,8 @@ import de.darkatra.vrising.discord.persistence.model.converter.ServerEntityConve
import de.darkatra.vrising.discord.persistence.model.converter.StatusMonitorEntityConverter
import org.dizitart.no2.Nitrite
import org.dizitart.no2.NitriteBuilder
import org.dizitart.no2.collection.Document
import org.dizitart.no2.collection.NitriteId
import org.dizitart.no2.exceptions.NitriteIOException
import org.dizitart.no2.mvstore.MVStoreModule
import org.dizitart.no2.store.StoreModule
Expand Down Expand Up @@ -69,10 +70,10 @@ class DatabaseConfiguration(
val encryptedDatabase = getNitriteBuilder(getStoreModule(tempDatabaseFile, password)).openOrCreate(username, password)
for (collectionName in unencryptedDatabase.listAllCollectionNames()) {

val oldCollection = unencryptedDatabase.getNitriteMap(collectionName)
val newCollection = encryptedDatabase.getNitriteMap(collectionName)
val oldCollection = unencryptedDatabase.store.openMap<NitriteId, Any>(collectionName, NitriteId::class.java, Document::class.java)
val newCollection = encryptedDatabase.store.openMap<NitriteId, Any>(collectionName, NitriteId::class.java, Document::class.java)

oldCollection.values().forEach { document -> newCollection.put(document.id, document) }
oldCollection.entries().forEach { entry -> newCollection.put(entry.first, entry.second) }
}
unencryptedDatabase.close()
encryptedDatabase.close()
Expand Down

0 comments on commit bbace9b

Please sign in to comment.