I was facing issue while trying to migrate my data...
# webassembly
a
I was facing issue while trying to migrate my database to a newer version in kotlin/wasm target. For android target AndroidSqliteDriver handles all the migration seamlessly but that is not the case with kotlin/wasm. I am able to achieve migration with the below code but is there any cleaner way to achieve migration in kotlin/wasm than the following?
Copy code
actual suspend fun provideDbDriver(): SqlDriver {
    val worker = createWorker()
    val driver: SqlDriver = WebWorkerDriver(worker)
    createSchema(driver)
    return driver
}

internal fun createWorker(): Worker =
    js("""new Worker(new URL("sqldelight-sqlite-wasm-worker/sqlitewasm.worker.js", import.meta.url))""")

suspend fun createSchema(driver: SqlDriver) {
    AppDB.Schema.create(driver).await()
    val currentDBVersion : Long? = getString(LocalStorageKeys.WASM_DB_VERSION)?.toLongOrNull()
    if (currentDBVersion != null && currentDBVersion != AppDB.Schema.version) {
        AppDB.Schema.migrate(driver,currentDBVersion,AppDB.Schema.version, AfterVersion(1) {
            saveString(LocalStorageKeys.WASM_DB_VERSION, "2")
        }).await()
    } else {
        saveString(LocalStorageKeys.WASM_DB_VERSION,AppDB.Schema.version.toString())
    }
}