Database Feature
Enable persistent SQLite storage for your deployments with automatic migrations and volume management.Enabling Database
Add to yourruntm.yaml:
- Creates a persistent Fly volume at
/data - Initializes SQLite with optimal settings
- Runs migrations on startup
How It Works
SQLite Configuration
The database is configured with optimal settings:Creating Models
Define Your Models
Register Models
Models must be imported inmodels/__init__.py:
Using the Database
In Route Handlers
In Services
Migrations
Automatic Migrations
The template runs migrations automatically on startup:Manual Migrations
For complex schema changes, use Alembic:External PostgreSQL
For production workloads or horizontal scaling, use external PostgreSQL:DATABASE_URL if set, otherwise falls back to SQLite.
Volume Management
Volume Size
Default volume size is 1GB. Configure in manifest:Data Location
Limitations
Best Practices
Use WAL mode
Use WAL mode
Already configured by default. Allows concurrent reads during writes.
Keep transactions short
Keep transactions short
Commit quickly to avoid blocking other operations.
Use indexes
Use indexes
Add indexes for frequently queried columns.
Backup regularly
Backup regularly
For critical data, copy
/data/app.db to external storage.Troubleshooting
'Database is locked' errors
'Database is locked' errors
SQLite can only have one writer. Check for:
- Long-running transactions
- Multiple processes writing simultaneously
Data not persisting
Data not persisting
Verify the volume is mounted:Look for volume creation messages.
Migrations not running
Migrations not running
Ensure models are imported in
models/__init__.py and migrations.py imports them.