• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
project logo

nbbaier

migrate-sqlite

Copy database tables from account-scoped to val-scoped SQLite
Remix of petermillspaugh/copy-sqlite-table
Public
Like
1
migrate-sqlite
Home
Code
2
README.md
migrate.ts
Environment variables
Branches
1
Pull requests
Remixes
History
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.
Sign up now
Code
/
README.md
Code
/
README.md
Search
…
Viewing readonly version of main branch: v13
View latest version
README.md

SQLite migration

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.

What it migrates

  1. Tables — schema and all row data (manually specified in TABLES)
  2. Autoincrement sequences — automatically detected for tables using AUTOINCREMENT
  3. Views — manually specified in VIEWS
  4. Indexes — automatically discovered for tables in TABLES
  5. Triggers — automatically discovered for tables in TABLES

Configuration

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.

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

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.

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.