Skip to main content

Schema Migrations (Alembic)

Fonrex uses Alembic to manage database schema evolutions. Migrations run in an isolated environment prior to API service startup to ensure schema consistency.

Migration History

Revision IDDescriptionKey Changes
001_initialInitial schemaassets, prices_eod, fundamentals
008_realtimeRealtime streamingprices_intraday hypertable, realtime_subscriptions
009_isin_listingsAsset & listing refactorasset_listings, asset_mappings, partial ISIN unique index
010_news_articlesNews aggregationnews_articles table with url unique constraint
011_provider_monitoringProvider health suiteprovider_health_log hypertable, provider_health_daily, provider_alerts

Migration Execution Flow

  1. At container startup, entrypoint.sh executes alembic upgrade head.
  2. main.py checks current schema status via database/migrations.py.
  3. If the stored revision in alembic_version does not match head, main.py marks app.state.db_available = False to prevent queries against incomplete schemas.

Creating a New Migration

To add a new table or column, generate a migration script inside the running container:

docker compose exec fonrex-api alembic revision -m "add_column_to_table"

Edit the generated file in alembic/versions/ and apply it:

docker compose exec fonrex-api alembic upgrade head