Skip to main content

Database Feature

Enable persistent SQLite storage for your deployments with automatic migrations and volume management.

Enabling Database

Add to your runtm.yaml:
This automatically:
  • 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 in models/__init__.py:

Using the Database

In Route Handlers

In Services

Migrations

Automatic Migrations

The template runs migrations automatically on startup:
This creates tables that don’t exist. It’s safe to run multiple times.

Manual Migrations

For complex schema changes, use Alembic:

External PostgreSQL

For production workloads or horizontal scaling, use external PostgreSQL:
The application automatically uses DATABASE_URL if set, otherwise falls back to SQLite.

Volume Management

Volume Size

Default volume size is 1GB. Configure in manifest:

Data Location

Limitations

SQLite supports only single writer. For horizontal scaling (multiple machines), use external PostgreSQL.

Best Practices

Already configured by default. Allows concurrent reads during writes.
Commit quickly to avoid blocking other operations.
Add indexes for frequently queried columns.
For critical data, copy /data/app.db to external storage.

Troubleshooting

SQLite can only have one writer. Check for:
  • Long-running transactions
  • Multiple processes writing simultaneously
Consider using PostgreSQL for write-heavy workloads.
Verify the volume is mounted:
Look for volume creation messages.
Ensure models are imported in models/__init__.py and migrations.py imports them.