The data model is the foundation of AClimate v3. It defines how information flows through the entire system — from ETL ingestion through API exposure to end-user interfaces.
Role of the ORM as Source of Truth
The aclimate_v3_orm package is the authoritative definition of the data model. It contains:
- SQLAlchemy models: Entity definitions with columns, types, constraints, and relationships
- Pydantic schemas: Serialization/deserialization contracts used by the API layer
- Alembic migrations: Version-controlled schema evolution
- Service layer: Business logic for CRUD operations
- Validations: Integrity rules and constraints
Data Model Conventions
- Naming: Snake_case for tables and columns (PostgreSQL convention)
- Primary Keys: Integer auto-increment (
id column) for most tables; BigInteger for high-volume tables (forecast)
- Timestamps: Every entity includes
register (created_at) and updated (updated_at) with timezone support
- Soft Delete: Entities are disabled via an
enable boolean column (not physically deleted)
- Foreign Keys: Explicit
ForeignKey constraints with indexed columns
- Relationships: Defined with SQLAlchemy
relationship() for ORM navigation
Schema Domains
The ORM entities are organized into functional domains:
| Prefix | Domain | Description |
|---|
mng_ | Management | Core configuration entities (countries, crops, soils, etc.) |
forecast_ | Forecast | Forecast runs, analogue data |
climate_historical_ | Climate Data | Historical climate observations and derived data |
historical_agroclimatic_ | Agroclimatic | Processed agroclimatic indicators |
phenological_stage_ | Phenology | Crop phenological stages and stress data |
user_ | Security | Users, roles, and access control |
Key Entities by Domain
Management (mng_*)
| Entity | Table | Description |
|---|
| MngCountry | mng_country | Countries with ISO2 codes |
| MngAdmin1 | mng_admin_1 | First-level administrative divisions |
| MngAdmin2 | mng_admin_2 | Second-level administrative divisions |
| MngLocation | mng_location | Geographic locations (stations, points) |
| MngCrop | mng_crop | Crop types |
| MngCultivar | mng_cultivar | Cultivar varieties per country |
| MngSoil | mng_soil | Soil types per country |
| MngSeason | mng_season | Growing seasons |
| MngSetup | mng_setup | Crop setup configurations |
| MngSource | mng_source | Data sources |
| MngDataSource | mng_data_source | Data source assignments per country |
| MngClimateMeasure | mng_climate_measure | Climate measure definitions |
| MngIndicator | mng_indicator | Indicator definitions |
| MngIndicatorCategory | mng_indicator_category | Indicator categories |
| MngIndicatorsFeatures | mng_indicators_features | Indicator-to-feature mappings |
| MngPhenologicalStage | mng_phenological_stage | Crop phenological stages |
| MngStress | mng_stress | Stress type definitions |
| MngConfigurationFile | mng_configuration_file | Configuration files |
Forecast Domain
| Entity | Table | Description |
|---|
| Forecast | forecast | Forecast runs per country |
| ForecastAnalogue | forecast_analogue | Analogue data for forecasts |
Climate Historical Domain
| Entity | Table | Description |
|---|
| ClimateHistoricalDaily | climate_historical_daily | Daily climate observations |
| ClimateHistoricalMonthly | climate_historical_monthly | Monthly aggregated climate data |
| ClimateHistoricalClimatology | climate_historical_climatology | Climatological normals |
| ClimateHistoricalIndicator | climate_historical_indicator | Derived climate indicators |
Other Domains
| Entity | Table | Description |
|---|
| HistoricalAgroclimaticIndicator | historical_agroclimatic_indicator | Processed agroclimatic indicators |
| PhenologicalStageStress | phenological_stage_stress | Stress mappings to phenological stages |
| User | user | System users |
| Role | role | User roles |
| UserAccess | user_access | User permissions per country |
Entity Relationship Highlights
- MngCountry → MngAdmin1 → MngAdmin2: Geographic hierarchy
- MngCountry → MngCultivar, MngSoil: Per-country configurations
- MngCountry → MngCountryIndicator, MngCountryClimateMeasure: Country-specific settings
- Forecast → ForecastAnalogue (one-to-many)
- MngCrop → MngCultivar → MngSetup: Crop configuration chain
- MngPhenologicalStage → PhenologicalStageStress → MngStress: Phenology-stress mapping
- User → Role → UserAccess: Security model
ORM ↔ API ↔ ETL Traceability
- Models (
models/): SQLAlchemy entity definitions → Database tables
- Schemas (
schemas/): Pydantic models → API request/response contracts
- Services (
services/): Business logic → Used by API and ETLs
- Validations (
validations/): Data integrity rules → Applied in services
- Enums (
enums/): Shared enumerations (source types, periods, modules, etc.)
- Migrations (
migrations/): Alembic versions → Schema evolution
Migrations Strategy
- Managed via Alembic with version-controlled migration scripts
- Each migration represents an atomic, reversible schema change
- Migrations are stored in
migrations/versions/
- The ORM package version aligns with database schema version