From PostgreSQL to SQLite in Rails
summary
Migrates a Rails app from PostgreSQL to embedded SQLite (Escalite) and reports it works: schema and types converted with ActiveRecord custom types, arrays moved to JSON, solid stack gems used alongside, data migrated with an open-source script, tests pass, downtime about one to two hours, and requests halve while costs drop dramatically. Notes trade-offs: migrated entire Rails app in ~3 days, cut infra costs from ~$650/mo to $77/mo, single-writer SQLite concurrency limits, backups via Litestream to S3/R2.
AI-written summary · about
chapters (27)
- 0:00Introduction
- 1:10Why switch to SQLite
- 3:01Benefits of embedded database
- 5:09Dropping Docker and simplifying deployment
- 6:35Cost savings and infrastructure changes
- 8:24Migration process overview
- 9:48Incremental migration strategy
- 10:52Handling unsupported PostgreSQL types
- 14:49Migrating PostgreSQL arrays to JSON
- 15:58Adopting Solid Cache and Solid Jobs
- 16:39Dropping constraints before migration
- 17:25Final data migration steps
- 18:11SQLite extensions and custom functions
- 23:29Custom Ruby functions in SQLite
- 25:17Sorting differences between PostgreSQL and SQLite
- 26:20Concurrency limitations in SQLite
- 28:52Data migrations and row locking
- 30:16Foreign key error challenges
- 31:20Scaling SQLite and replication options
- 34:12Trade-offs and final verdict
- 35:00Q&A: Backups and replication
- 37:06Q&A: Migration with Solid Queue
- 37:47Q&A: Local PostgreSQL vs SQLite
- 39:31Q&A: Migration timeline and regrets
- 41:00Q&A: Database size and records
- 41:41Q&A: N+1 queries and memory overhead
- 43:28Q&A: Data migration and downtime
