diff --git a/CHANGELOG.md b/CHANGELOG.md index ca6dfc14..4f57c950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## 1.0.0-BETA29 (unreleased) * Fix potential race condition between jobs in `connect()` and `disconnect()`. +* [iOS] Fixed issue where automatic driver migrations would fail with the error: +``` +Sqlite operation failure database is locked attempted to run migration and failed. closing connection +``` ## 1.0.0-BETA28 diff --git a/core/src/iosMain/kotlin/com/powersync/DatabaseDriverFactory.ios.kt b/core/src/iosMain/kotlin/com/powersync/DatabaseDriverFactory.ios.kt index e6041c5b..2066830f 100644 --- a/core/src/iosMain/kotlin/com/powersync/DatabaseDriverFactory.ios.kt +++ b/core/src/iosMain/kotlin/com/powersync/DatabaseDriverFactory.ios.kt @@ -1,8 +1,10 @@ package com.powersync +import app.cash.sqldelight.db.QueryResult import co.touchlab.sqliter.DatabaseConfiguration import co.touchlab.sqliter.DatabaseConfiguration.Logging import co.touchlab.sqliter.DatabaseConnection +import co.touchlab.sqliter.NO_VERSION_CHECK import co.touchlab.sqliter.interop.Logger import co.touchlab.sqliter.interop.SqliteErrorType import co.touchlab.sqliter.sqlite3.sqlite3_commit_hook @@ -68,7 +70,13 @@ public actual class DatabaseDriverFactory { configuration = DatabaseConfiguration( name = dbFilename, - version = schema.version.toInt(), + version = + if (!readOnly) { + schema.version.toInt() + } else { + // Don't do migrations on read only connections + NO_VERSION_CHECK + }, create = { connection -> wrapConnection(connection) { schema.create( @@ -106,6 +114,15 @@ public actual class DatabaseDriverFactory { driver.execute("PRAGMA query_only=true") } + // Ensure internal read pool has created a connection at this point. This makes connection + // initialization a bit more deterministic. + driver.executeQuery( + identifier = null, + sql = "SELECT 1", + mapper = { QueryResult.Value(it.getLong(0)) }, + parameters = 0, + ) + deferredDriver.setDriver(driver) return driver