Staging
Two different things live under the name "staging":
- The dbt staging layer: 30 views in
epm_staging, materialized over the Airbyte raw tables. - The
epm_stagingdatabase also holds the reference tables konsol writes through from its doctypes (see Reference Data) and thesync_watermark.
Staging views (30 models)
epm_raw (Airbyte) → stg_<erp>__* (adapters) → stg_* (canonical, UNION ALL) → epm_bronze → epm_silver → epm_gold
Which adapters are built, and which the canonical models union, is one switch: var('erp_sources') in dbt_project.yml. The default is empty (konsolidat#207): no connector is built, the trial-balance upload is the canonical source, and each canonical model compiles to empty_relation(...), a row-less select with the same column names and types. Each adapter model carries {{ config(enabled = '<erp>' in var('erp_sources', [])) }} in its body (a +enabled in dbt_project.yml cannot see the project's own vars).
Canonical interface (7, models/staging/canonical/)
Every adapter must produce these column sets. The canonical models select only the canonical columns; adapter-specific columns (reporting_currency_amount, general_journal_entry_recid, budget_register_entry_recid, include_in_cash_flow) are joined from the adapter by bronze.
| Model | Purpose | Notes |
|---|---|---|
stg_gl_entries | GL lines | Harmonises the declared dimensions through epm_staging.dimension_mappings (dim_harmonize_*): an entity-specific Published mapping beats the ERP-wide default (entity = '') beats pass-through. Drops lines with no entity_id (konsolidat#105). Carries partner_data_area_id (konsol#159) |
stg_trial_balance | Fiscal-year trial-balance snapshots | |
stg_accounts | ERP chart of accounts | |
stg_legal_entities | Company master | |
stg_exchange_rates | FX quotes as TRUE rates | Scaling resolved in the adapter (#138) |
stg_budget_entries | Budget lines | Harmonises the budget dimensions only |
stg_fiscal_periods | Fiscal calendar years |
Columns are typed, not all String as the original design said: for example stg_gl_entries.record_id is Nullable(Int64), amount Nullable(Decimal(38, 9)), _loaded_at DateTime64(3). The full list is the empty_relation([...]) block at the top of each canonical model. Design: Canonical Staging Schema.
D365 F&O adapter (16, models/staging/d365_fo/)
Source d365_raw (database epm_raw). Seven feed the canonical models; nine are D365-only helpers that bronze reads directly.
| Model | Raw table | Canonical target |
|---|---|---|
stg_d365_fo__gl_entries | general_journal_account_entry_bi_entities + general_journal_entry_bi_entities | stg_gl_entries (partner_data_area_id is NULL: D365's partner is not mapped yet) |
stg_d365_fo__trial_balance | trial_balance_fiscal_year_snapshots | stg_trial_balance |
stg_d365_fo__accounts | main_accounts | stg_accounts |
stg_d365_fo__legal_entities | legal_entities + ledgers | stg_legal_entities |
stg_d365_fo__exchange_rates | exchange_rates | stg_exchange_rates; divides Rate by the ConversionFactor enum (Ten, Hundred, Thousand, TenThousand); assert_conversion_factor_known fails the build on an unknown value |
stg_d365_fo__budget_entries | budget_register_entries | stg_budget_entries |
stg_d365_fo__fiscal_periods | fiscal_calendar_years | stg_fiscal_periods |
stg_d365_fo__gl_journal_entries | general_journal_entry_bi_entities | bronze_general_journal_entries |
stg_d365_fo__budget_register_entries | budget_register_entries | bronze_budget_register_entries |
stg_d365_fo__main_account_categories | main_account_categories | bronze_main_account_categories |
stg_d365_fo__consolidation_groups | consolidate_account_groups | bronze_consolidation_account_groups |
stg_d365_fo__exchange_rate_types | exchange_rate_types | bronze_exchange_rate_types |
stg_d365_fo__financial_dimensions | dimension_attributes | bronze_financial_dimensions |
stg_d365_fo__financial_dimension_values | financial_dimension_values | bronze_financial_dimension_values |
stg_d365_fo__fiscal_calendars | fiscal_calendar_years | bronze_fiscal_calendars |
stg_d365_fo__fiscal_calendar_years | fiscal_calendar_years | bronze_fiscal_calendar_years |
ERPNext adapter (7, models/staging/erpnext/)
Source erpnext_raw (database epm_raw). One model per canonical target.
| Model | Raw table | Notes |
|---|---|---|
stg_erpnext__gl_entries | gl_entry | record_id is a hash of name; amount = debit - credit; cancelled entries dropped; cost_center → dim_cost_center, project → dim_business_unit |
stg_erpnext__trial_balance | gl_entry | Aggregated per entity, account and fiscal year (ERPNext has no snapshot doctype); opening_balance 0 |
stg_erpnext__accounts | account | root_type Income reads as Revenue via map_account_type() |
stg_erpnext__legal_entities | company | |
stg_erpnext__exchange_rates | currency_exchange | |
stg_erpnext__budget_entries | budget | |
stg_erpnext__fiscal_periods | fiscal_year |
Tests on staging
tests/staging/: test_canonical_gl_entries_schema, test_canonical_gl_entries_not_null, test_canonical_gl_journals_balance (a voucher that does not net to zero fails the build), test_erp_source_valid (erp_source in d365_fo, d365_bc, sap_s4, sap_ecc, sap_b1, erpnext), test_dimension_mappings_unique. Plus assert_d365_gl_vouchers_balance and assert_is_credit_retired in tests/.
ClickHouse databases
Created by clickhouse/init-db.sql on a fresh volume (konsol's ensure_reference_tables() and ensure_raw_tables() create the konsol-owned tables on an existing one):
| Database | Written by | Contents |
|---|---|---|
epm_raw | Airbyte; konsol | Raw ERP tables (d365_raw, erpnext_raw sources); trial_balance_submissions and trial_balance_submission_control (Trial Balance Submission doctype) |
epm_staging | dbt; konsol | The 30 staging views; konsol's write-through reference tables (main_accounts, entities, fiscal_periods, group_exchange_rates, dimension_mappings, cash_flow_categories, reporting_hierarchies, consolidation_hierarchy, consolidation_ancestry, ownership_periods, historical_equity_rates, intercompany_accounts, ic_elimination_rules, ic_balances, consolidation_adjustments, scenario_definitions, the six deal tables); sync_watermark |
epm_bronze | dbt | The 16 bronze tables |
epm_silver | dbt | The 10 silver tables |
epm_gold | dbt; konsol | The 45 gold models; konsol's consolidation_groups, currencies, scenario_definitions, spread_profiles, budget_annual_input, budget_monthly_input, entity_fiscal_calendars |
init-db.sql also creates an epm database. The epm_allocated database of the removed cost-allocation feature is dropped by konsol's migrate when empty (konsolidat#226).
The sync watermark
epm_staging.sync_watermark has one row per successful konsol sync: table_name, synced_at, row_count, source_max_modified, reconcile_run_id ('' for a write-through; konsolidat#246). dbt's on-run-start creates the table and runs sync_watermark_upgrade() so a fresh install can parse. assert_staging_not_stale fails the build when a watermarked table is EMPTIED (the sync wrote rows, the table has none), LAGGING (missing from the latest settled reconcile run; option #246-1, Deepak Pai, 11 Oct 2026), or NO_RECONCILE_RUN for longer than watermark_lag_hours (default 24) after the column arrived.
The "write-back tables (planned)" an earlier version of this page listed (a staging budget-submissions table and a staging consolidation-adjustments table) were never built. Budgets are entered in konsol (Budget Sheet, Budget Annual Input) and land in epm_gold.budget_monthly_input / budget_annual_input; top-side journals are the Consolidation Journal doctype, landing in epm_staging.consolidation_adjustments.