Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext IOS DB Migrations

From Leeroopedia
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

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
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment