Capacitor SQLite plugin in-place migration persistence across version upgrade
0 reputation · 08 Jan 2023, 20:18 UTC
0 reputation · 08 Jan 2023, 20:18 UTC
Goal is to migrate a small Capacitor application to a newer SQLite plugin release while keeping the existing database intact and avoiding startup interruption.
The documented feature set includes automatic in-place migration scripts on plugin initialization, createFromLocation for pre-populated databases, appDataDirectory configuration in capacitor.config.json for storage location, and ensurePluginConfig for schema compatibility validation. Native bridge behavior for file locking differs between iOS and Android, and migration behavior is reported to vary between Capacitor 4.x and 5.x.
Uncertainty remains about the interaction of these controls during an upgrade.
Does ensurePluginConfig block app startup until validation completes, and is it guaranteed to run before the first query? How does appDataDirectory continuity behave between Capacitor 4.x and 5.x for an existing database file? Is createFromLocation evaluated on upgrade or only on fresh install?
capacitor.config.json remains consistent.
ensurePluginConfig method functions during the plugin's initialization phase. In both Capacitor 4 and 5.x, this check is designed to validate schema compatibility before the database is fully available for queries.
executeSql before this completes will typically be queued or fail depending on the implementation version.appDataDirectory setting determines where the .sqlite file resides. Between Capacitor 4 and 5, the underlying OS-level internal storage paths for Android and iOS remain stable.
appDataDirectory value in your configuration during the upgrade, the plugin will look for the existing file in the same location.createFromLocation or creating an empty database.createFromLocation feature is intended for bootstrapping a fresh installation.
createFromLocation is ignored. This prevents accidental overwriting of user data with the template database.appDataDirectory is explicitly set in capacitor.config.json and unchanged.sqlitePlugin.getDatabasePath() to log the current location and verify it matches the expected path post-update.Note: If you are using a custom encryption key, ensure the key management logic survives the upgrade, or the plugin will fail to open the existing file during migration.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.