File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
shared/src/main/kotlin/org/javacs/kt/database Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 1
1
package org.javacs.kt.database
2
2
3
+ import org.javacs.kt.LOG
3
4
import org.jetbrains.exposed.dao.IntEntity
4
5
import org.jetbrains.exposed.dao.IntEntityClass
5
6
import org.jetbrains.exposed.dao.id.EntityID
@@ -25,7 +26,7 @@ class DatabaseMetadataEntity(id: EntityID<Int>) : IntEntity(id) {
25
26
class DatabaseService {
26
27
27
28
companion object {
28
- const val CURRENT_VERSION = 1
29
+ const val LATEST_VERSION = 1
29
30
const val DB_FILENAME = " kls_database.db"
30
31
}
31
32
@@ -38,20 +39,23 @@ class DatabaseService {
38
39
val currentVersion = transaction(db) {
39
40
SchemaUtils .createMissingTablesAndColumns(DatabaseMetadata )
40
41
41
- DatabaseMetadataEntity .all().firstOrNull()?.version
42
+ DatabaseMetadataEntity .all().firstOrNull()?.version ? : 0
42
43
}
43
44
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... " )
46
47
48
+ deleteDb(storagePath)
47
49
db = getDbFromFile(storagePath)
48
50
49
51
transaction(db) {
50
52
SchemaUtils .createMissingTablesAndColumns(DatabaseMetadata )
51
53
52
54
DatabaseMetadata .deleteAll()
53
- DatabaseMetadata .insert { it[version] = CURRENT_VERSION }
55
+ DatabaseMetadata .insert { it[version] = LATEST_VERSION }
54
56
}
57
+ } else {
58
+ LOG .info(" Database has latest version $currentVersion and will be used as-is" )
55
59
}
56
60
}
57
61
You can’t perform that action at this time.
0 commit comments