This guide will help you migrate your Reencodarr data from PostgreSQL to SQLite.
- Ensure your PostgreSQL database is running and accessible
- Back up your PostgreSQL database first:
pg_dump reencodarr_dev > backup.sql - Make sure you have the updated
mix.exswithecto_sqlite3dependency
Run the configuration update script to switch your Elixir configuration to SQLite:
elixir scripts/update_config_for_sqlite.exsThis will update:
lib/reencodarr/repo.ex- Change adapter to SQLite3config/dev.exs- SQLite development configurationconfig/test.exs- SQLite test configuration
mix deps.getThe migration script will:
- Connect to your existing PostgreSQL database
- Create a new SQLite database with the correct schema
- Copy all data from PostgreSQL to SQLite, converting formats as needed
- Handle JSON fields, arrays, and enum types properly
elixir scripts/migrate_to_sqlite.exsYou can customize the migration with these environment variables:
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=postgres
export POSTGRES_HOST=localhost
export POSTGRES_DB=reencodarr_dev
export POSTGRES_PORT=5432
export SQLITE_DB=priv/reencodarr.dbStart your application to test the migration:
mix phx.serverVisit http://localhost:4000 and verify:
- All your videos are listed
- Libraries are present
- VMAF data is intact
- Configuration settings are preserved
For production, update your config/runtime.exs to use the DATABASE_PATH environment variable:
export DATABASE_PATH=/app/data/reencodarr.dbThe migration handles these PostgreSQL to SQLite conversions:
| PostgreSQL Type | SQLite Type | Notes |
|---|---|---|
text[] (arrays) |
TEXT |
Converted to JSON strings |
jsonb |
TEXT |
Stored as JSON strings |
| Enums | TEXT |
Converted to string values |
bigint |
INTEGER |
Native SQLite integer |
boolean |
BOOLEAN |
SQLite boolean support |
SQLite doesn't support all PostgreSQL features, but the migration handles this by:
- Arrays: Converting to JSON text (e.g.,
audio_codecs) - JSONB: Converting to JSON text (e.g.,
mediainfo) - Enums: Converting to text strings (e.g., video
state) - Foreign Keys: Preserved as constraints
- Indexes: Recreated for performance
If you need to rollback to PostgreSQL:
- Restore your PostgreSQL backup:
psql reencodarr_dev < backup.sql - Revert configuration changes:
git checkout HEAD -- lib/reencodarr/repo.ex config/dev.exs config/test.exs
- Update
mix.exsto usepostgrexinstead ofecto_sqlite3 - Run
mix deps.get
- Ensure PostgreSQL is running and accessible
- Check your database connection settings
- Verify the database name matches your development environment
- Ensure the
priv/directory is writable - Check that no other processes are using the SQLite file
- Compare record counts:
SELECT COUNT(*) FROM table_namein both databases - Check for any custom data types that may need special handling
- SQLite uses WAL mode for better concurrency
- Cache size is optimized for development workloads
- Consider
PRAGMA optimizefor production databases
After migration, your data will be stored in:
- Development:
priv/reencodarr_dev.db - Test:
:memory:(temporary) - Production:
$DATABASE_PATH(configurable)
The migration preserves all:
- Video records and metadata
- VMAF analysis results
- Library configurations
- Service API settings
- Failure tracking data