svelte-turso-drizzle Svelte Themes

Svelte Turso Drizzle

Reference project for local + production workflow with Svelte, Turso & Drizzle.

Database Workflow (SvelteKit + Turso + Drizzle)

Local development

  • Init a local DB file (run this once at the very start of your project):
    turso dev --db-file .db/dev.db
    
  • Use the persistent local SQLite file:
    DATABASE_URL="file:local.db"
    
  • Apply schema changes to local DB:
    npm run db:push
    
  • Open Drizzle Studio (GUI):
    npm run db:studio
    
  • (Optional) Reset & re-seed local DB:
    npm run db:reset
    npm run db:seed
    

Production (Turso)

  • Use .env.production with your remote Turso credentials:
    DATABASE_URL="libsql://<db-name>-<org>.turso.io"
    DATABASE_AUTH_TOKEN="<token>"
    
  • Generate schema/migrations after changes are complete in schema.ts:
    npm run db:generate
    
  • Push migrations to prod:
    npm run db:migrate:prod
    

Key scripts

  • db:generate → generate migration files from schema
  • db:push → apply schema directly (local dev only)
  • db:migrate → apply migration files (local)
  • db:migrate:prod → apply migration files to prod (uses .env.production)
  • db:studio → open Drizzle Studio
  • db:seed → run seed script
  • db:reset → wipe + reapply schema locally

Rule of thumb

  • Local dev → use push for speed.
  • Prod → always use migrate so history is tracked.

Port in use fix

  • Kill the old process On macOS/Linux:
      lsof -i :8080
    
  • Find the PID (first column), then:
       kill -9 <PID>
    

Top categories

Loading Svelte Themes