Dump SQLite to SQL
sqlite3 -escape off server/db/db.sqlite .dump > db.sqlEscape 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