Public
Like1
migrate-sqlite
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v18View latest version
Generic script to migrate tables, views, indexes, and triggers from your Val Town account-based (global) database to a val-scoped database.
You can copy-paste the migrate.ts file into any val you'd like to migrate.
- Tables — schema and all row data (manually specified in
TABLES) - Autoincrement sequences — automatically detected for tables using
AUTOINCREMENT - Views — manually specified in
VIEWS - Indexes — automatically discovered for tables in
TABLES - Triggers — automatically discovered for tables in
TABLES
Edit the two arrays at the top of migrate.ts:
const TABLES = ["my_table", "another_table"];
const VIEWS = ["my_view"];
Indexes and triggers associated with the listed tables are auto-discovered — no need to list them manually.
- Safe to re-run: uses
IF NOT EXISTSfor tables/views/indexes andDROP + CREATEfor triggers - Row inserts use
INSERT OR IGNOREto skip duplicates on re-runs - Table/column names are quoted to handle special characters
- Rows are inserted in chunks of 100
Townie (Normal mode, Claude Sonnet 4.6) was quite helpful in building this migrator. When running and testing your migration, the SQLite Explorer val (for global db) and built-in SQLite admin panel (for val db) are helpful.