Skip to content

Overview

What it provides (orchestration/include/db)

Section titled “What it provides (orchestration/include/db)”
  • models/ — SQLModel table definitions: Company, CompanyPermit, CompanyUser, DashboardUser, Permit, ReportPeriod, Purchase, Sale, Inventory, Import, Export, ReportJob/JobStatus. (Import is loaded via importlib since import is a reserved keyword.)
  • alembic/ — migration environment (env.py, versions/) and alembic.ini, run via the db_migrations/db_rollback Airflow DAGs. See Orchestration → Database & Migrations for the migration workflow.
  • persist.py — bulk-insert helpers for writing cleaned Polars DataFrames to PostgreSQL from Airflow tasks, e.g.:
    from airflow.providers.postgres.hooks.postgres import PostgresHook
    from db.persist import persist_report
    hook = PostgresHook(postgres_conn_id="my-pg")
    engine = create_engine(hook.get_uri())
    persist_report(engine=engine, ...)
  • migrate.py — migration entry point used by the Airflow DAGs.

Dependencies: alembic, psycopg[binary], sqlmodel, uuid-utils. Built with uv_build, not hatchling.

Connections use PostgresHook/SQLAlchemy engines configured via Airflow connections, ultimately backed by the same Azure AD-token authentication model described in Architecture → Identity & Security (developer identity locally via AZURE_USERNAME/AZURE_PG_TOKEN, service identity in production).

packages/db (root workspace, packages/db/pyproject.toml, depends on utils) contains conn.py (commented-out SQLAlchemy URL builder), auth.py (commented-out Key Vault-backed credential fetcher), and PostgresDBHelper.py (commented-out psycopg context-manager helper) — all disabled. If this package is revived for use outside orchestration/, update this page accordingly; until then, treat orchestration/include/db as the source of truth for database access patterns.