MCPcopy Create free account
hub / github.com/expo/examples / migrateDbIfNeeded

Function migrateDbIfNeeded

with-libsql/App.tsx:216–239  ·  view source on GitHub ↗
(db: SQLiteDatabase)

Source from the content-addressed store, hash-verified

214}
215
216async function migrateDbIfNeeded(db: SQLiteDatabase) {
217 // Always sync libSQL first to prevent conflicts between local and remote databases
218 await db.syncLibSQL();
219
220 const DATABASE_VERSION = 1;
221 let { user_version: currentDbVersion } = await db.getFirstAsync<{
222 user_version: number;
223 }>('PRAGMA user_version');
224 if (currentDbVersion >= DATABASE_VERSION) {
225 return;
226 }
227 if (currentDbVersion === 0) {
228 // libSQL does not support WAL mode
229 // await db.execAsync(`PRAGMA journal_mode = 'wal';`);
230 await db.execAsync(
231 `CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY NOT NULL, done INT, value TEXT);`
232 );
233 currentDbVersion = 1;
234 }
235 // if (currentDbVersion === 1) {
236 // Add more migrations
237 // }
238 await db.execAsync(`PRAGMA user_version = ${DATABASE_VERSION}`);
239}
240
241//#endregion
242

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected