Skip to content

Instantly share code, notes, and snippets.

@isDipesh
Created December 22, 2025 06:25
Show Gist options
  • Select an option

  • Save isDipesh/5f73c537a01cc04b69168f2b16c19ed1 to your computer and use it in GitHub Desktop.

Select an option

Save isDipesh/5f73c537a01cc04b69168f2b16c19ed1 to your computer and use it in GitHub Desktop.
Importing SQLite to Cloudflare D1

Importing SQLite to Cloudflare D1

Dump SQLite to Sql

sqlite3 -escape off server/db/db.sqlite .dump > db.sql

Escape off prevents unistr in newer versions of sqlite, which D1 does not support.

Cleanup SQL Dump

  • Remove BEGIN TRANSACTION; and COMMIT; from the file
  • Remove PRAGMA statements
  • Remove sqlite_sequence table creation if exists
  • Remove all table creations, if tables are already created
  • Remove index creations, if indices are already created
  • Remove migrations table (like __drizzle_migrations) value inserts, if migration is already run

Import to D1

pnpm wrangler d1 execute <d1-database-name> --remote --file=db.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment