SQLite migration

Migrate tables, views, indexes, and triggers from your Val Town account-based (global) database to a val-scoped database.

Usage

Import migrate from this val and call it with your configuration:

import migrate from "https://esm.town/v/nbbaier/migrate-sqlite/migrate.ts"; await migrate({ tables: ["users", "posts"], views: ["active_users"], // optional });

What it migrates

  1. Tables — schema and all row data (specify in tables)
  2. Autoincrement sequences — automatically detected for tables using AUTOINCREMENT
  3. Views — specify in views (optional, defaults to [])
  4. Indexes — automatically discovered for the listed tables
  5. Triggers — automatically discovered for the listed tables

Notes

  • Safe to re-run: uses IF NOT EXISTS for tables/views/indexes and DROP + CREATE for triggers
  • Row inserts use INSERT OR IGNORE to skip duplicates on re-runs
  • Table/column names are quoted to handle special characters
  • Rows are inserted in chunks of 100

When running and testing your migration, the SQLite Explorer val (for global db) and built-in SQLite admin panel (for val db) are helpful.