Skip to content

Commit c91e7f5

Browse files
committed
Log database rebuilds
1 parent 5e5ece8 commit c91e7f5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

shared/src/main/kotlin/org/javacs/kt/database/DatabaseService.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.javacs.kt.database
22

3+
import org.javacs.kt.LOG
34
import org.jetbrains.exposed.dao.IntEntity
45
import org.jetbrains.exposed.dao.IntEntityClass
56
import org.jetbrains.exposed.dao.id.EntityID
@@ -25,7 +26,7 @@ class DatabaseMetadataEntity(id: EntityID<Int>) : IntEntity(id) {
2526
class DatabaseService {
2627

2728
companion object {
28-
const val CURRENT_VERSION = 1
29+
const val LATEST_VERSION = 1
2930
const val DB_FILENAME = "kls_database.db"
3031
}
3132

@@ -38,20 +39,23 @@ class DatabaseService {
3839
val currentVersion = transaction(db) {
3940
SchemaUtils.createMissingTablesAndColumns(DatabaseMetadata)
4041

41-
DatabaseMetadataEntity.all().firstOrNull()?.version
42+
DatabaseMetadataEntity.all().firstOrNull()?.version ?: 0
4243
}
4344

44-
if ((currentVersion ?: 0) < CURRENT_VERSION) {
45-
deleteDb(storagePath)
45+
if (currentVersion < LATEST_VERSION) {
46+
LOG.info("Database has outdated version $currentVersion < $LATEST_VERSION and will be rebuilt...")
4647

48+
deleteDb(storagePath)
4749
db = getDbFromFile(storagePath)
4850

4951
transaction(db) {
5052
SchemaUtils.createMissingTablesAndColumns(DatabaseMetadata)
5153

5254
DatabaseMetadata.deleteAll()
53-
DatabaseMetadata.insert { it[version] = CURRENT_VERSION }
55+
DatabaseMetadata.insert { it[version] = LATEST_VERSION }
5456
}
57+
} else {
58+
LOG.info("Database has latest version $currentVersion and will be used as-is")
5559
}
5660
}
5761

0 commit comments

Comments
 (0)