Skip to content

Commit 262a8d9

Browse files
committed
Require the database to have the exact version required
This lets us perform backwards-incompatible changes without running the risk that an older version of the language server cannot read it properly.
1 parent 49df2b2 commit 262a8d9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DatabaseMetadataEntity(id: EntityID<Int>) : IntEntity(id) {
2626
class DatabaseService {
2727

2828
companion object {
29-
const val LATEST_VERSION = 3
29+
const val DB_VERSION = 3
3030
const val DB_FILENAME = "kls_database.db"
3131
}
3232

@@ -42,8 +42,8 @@ class DatabaseService {
4242
DatabaseMetadataEntity.all().firstOrNull()?.version ?: 0
4343
}
4444

45-
if (currentVersion < LATEST_VERSION) {
46-
LOG.info("Database has outdated version $currentVersion < $LATEST_VERSION and will be rebuilt...")
45+
if (currentVersion != DB_VERSION) {
46+
LOG.info("Database has version $currentVersion != $DB_VERSION (the required version), therefore it will be rebuilt...")
4747

4848
deleteDb(storagePath)
4949
db = getDbFromFile(storagePath)
@@ -52,10 +52,10 @@ class DatabaseService {
5252
SchemaUtils.createMissingTablesAndColumns(DatabaseMetadata)
5353

5454
DatabaseMetadata.deleteAll()
55-
DatabaseMetadata.insert { it[version] = LATEST_VERSION }
55+
DatabaseMetadata.insert { it[version] = DB_VERSION }
5656
}
5757
} else {
58-
LOG.info("Database has latest version $currentVersion and will be used as-is")
58+
LOG.info("Database has the correct version $currentVersion and will be used as-is")
5959
}
6060
}
6161

0 commit comments

Comments
 (0)