Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkAtra committed Jul 6, 2024
1 parent 3c37daf commit 3c0846d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import java.nio.file.Path
import kotlin.io.path.absolutePathString

@Configuration
@EnableConfigurationProperties(BotProperties::class)
Expand All @@ -26,7 +25,7 @@ class DatabaseConfiguration(
fun buildNitriteDatabase(databaseFile: Path, username: String? = null, password: String? = null): Nitrite {

val storeModule = MVStoreModule.withConfig()
.filePath(databaseFile.absolutePathString())
.filePath(databaseFile.toAbsolutePath().toFile())
.compress(true)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@ import org.dizitart.no2.Nitrite
import org.dizitart.no2.filters.Filter
import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.absolutePathString
import kotlin.io.path.copyTo

object DatabaseConfigurationTestUtils {

val DATABASE_FILE_V1_2_x = File(DatabaseConfigurationTestUtils::class.java.getResource("/persistence/v1.2.db")!!.toURI())
val DATABASE_FILE_V2_10_5 = File(DatabaseConfigurationTestUtils::class.java.getResource("/persistence/v2.10.5.db")!!.toURI())
val DATABASE_FILE_V1_2_x = File(DatabaseConfigurationTestUtils::class.java.getResource("/persistence/v1.2.db")!!.toURI()).toPath()
val DATABASE_FILE_V2_10_5 = File(DatabaseConfigurationTestUtils::class.java.getResource("/persistence/v2.10.5.db")!!.toURI()).toPath()
private val logger = LoggerFactory.getLogger(javaClass)

fun getTestDatabase(fromTemplate: File? = null): Nitrite {
fun getTestDatabase(fromTemplate: Path? = null): Nitrite {

val databaseFile = File.createTempFile("v-rising-bot", ".db").also {
logger.info("Test Db location: " + it.absolutePath)
val databaseFile = Files.createTempFile("v-rising-bot", ".db").also {
logger.info("Test Db location: " + it.absolutePathString())
}

if (fromTemplate != null) {
logger.info("Loading template from '${fromTemplate.absolutePath}'.")
logger.info("Loading template from '${fromTemplate.absolutePathString()}'.")
fromTemplate.copyTo(databaseFile, overwrite = true)
}

return DatabaseConfiguration.buildNitriteDatabase(databaseFile.toPath())
return DatabaseConfiguration.buildNitriteDatabase(databaseFile)
}

fun clearDatabase(nitrite: Nitrite) {
Expand Down

0 comments on commit 3c0846d

Please sign in to comment.