Implementation:0xranx OpenContext IOS DB Migrations
| Knowledge Sources | |
|---|---|
| Domains | SQLite, Schema_Migration, iOS |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Database schema migration module for the iOS app, ensuring all DDL statements are applied and the stable_id column exists with backfilled UUID values.
Description
The migrations.js module in src-ios/db/ exports a single ensureSchema function that runs all DDL statements from schema.js, then checks if the stable_id column exists on the docs table via PRAGMA table_info(docs). If missing, it adds the column with ALTER TABLE and creates a unique index. Finally, it backfills any NULL or empty stable_id values by generating UUIDs via generateStableId(). This enables stable document links that survive renames.
Usage
Call ensureSchema during app initialization (called from initDb()) to guarantee the database schema is up-to-date.
Code Reference
Source Location
- Repository: 0xranx_OpenContext
- File: src-ios/db/migrations.js
- Lines: 1-46
Signature
async function ensureSchema({ run, all })
async function ensureStableIdColumn({ run, all })
async function backfillStableIds({ run, all })
Import
const { ensureSchema } = require('./db/migrations');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| run | Function | Yes | SQLite execute function (non-query) |
| all | Function | Yes | SQLite query function returning rows |
Outputs
| Name | Type | Description |
|---|---|---|
| (void) | Promise<void> | Schema is ensured; no return value |
Usage Examples
Schema Initialization
const { ensureSchema } = require('./db/migrations');
// During app boot
async function initDb() {
const db = await openDatabase();
const run = (sql, params = []) => db.executeSql(sql, params);
const all = (sql, params = []) => db.executeSql(sql, params).then(r => r.rows);
await ensureSchema({ run, all });
// Schema is now guaranteed to have stable_id column with backfilled UUIDs
}