Skip to the content.

Data Model

Entity relationship diagram

erDiagram
    COUNTRIES ||--o{ POPULATION_OBSERVATIONS : has

    COUNTRIES {
        TEXT iso2_code PK
        TEXT country_name
        TEXT region_name
        TEXT income_level
        TEXT capital_city
        REAL longitude
        REAL latitude
        TEXT source_name
        TEXT fetched_at
    }

    POPULATION_OBSERVATIONS {
        TEXT iso2_code PK, FK
        INTEGER observation_year PK
        INTEGER population
        TEXT indicator_code
        TEXT source_name
        TEXT fetched_at
    }

    INGESTION_RUNS {
        INTEGER run_id PK
        TEXT started_at
        TEXT completed_at
        TEXT status
        INTEGER countries_requested
        INTEGER countries_loaded
        INTEGER observations_loaded
        INTEGER rejected_records
        TEXT error_message
    }

ingestion_runs is an operational audit table. It records the execution state of refresh operations but is intentionally not used as a foreign-key parent for source rows. Country and population rows retain their own source and retrieval timestamps so their provenance remains available independently of run-history retention.

Keys and cardinality

Integrity rules

The schema enforces:

Read model

Country API responses combine countries with the latest available population observation through a correlated subquery. Population history remains available as a separate time-series endpoint.

The summary and data-quality endpoints aggregate the same persisted tables rather than maintaining separate derived storage.