SqliteSchemaMigration

Non-destructive schema migration shared by every SQLite DB in the SDK (#306, #309).

Until 26.10.2 every SDK DB used (int) LibraryInfo.VERSION_CODE as its version and dropped all its tables in onUpgrade/onDowngrade, so every SDK update (and every rollback) wiped them: the unsent upload queue and map cache (#306), the user's favourites and recently viewed places, location-marketing campaign state, property metadata, diagnostics and map overlays (#309).

The fix, per DB: the version is a constant LEGACY_VERSION_CODE_CEILING + revision that changes only when a table's CREATE SQL changes, and onUpgrade/onDowngrade call reconcileColumns for each table (rows kept) and then onCreate (CREATE TABLE IF NOT EXISTS for any table that was missing).

Types

Link copied to clipboard
enum Result
Outcome of reconcileColumns.

Properties

Link copied to clipboard
Every DB already on a phone carries the VERSION_CODE of the SDK that last opened it: YY*1_000_000 + M*10_000 + V*1_000 (26.x, mapsted-version.gradle.kts) or the same formula over MAJOR.MINOR.REVISION (legacy 6.x).

Functions

Link copied to clipboard
open fun keepRows(@NonNull db: SQLiteDatabase, @NonNull dbName: String, oldVersion: Int, newVersion: Int, @NonNull createSqls: Array<String>)
Migrate every table of a DB without losing rows, for helpers whose own code cannot work with a table left in an older shape.
Link copied to clipboard
Bring an existing table's columns in line with createSql while keeping its rows.