Skip to main content

Staging

Two different things live under the name "staging":

  1. The dbt staging layer: 30 views in epm_staging, materialized over the Airbyte raw tables.
  2. The epm_staging database also holds the reference tables konsol writes through from its doctypes (see Reference Data) and the sync_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.

ModelPurposeNotes
stg_gl_entriesGL linesHarmonises 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_balanceFiscal-year trial-balance snapshots
stg_accountsERP chart of accounts
stg_legal_entitiesCompany master
stg_exchange_ratesFX quotes as TRUE ratesScaling resolved in the adapter (#138)
stg_budget_entriesBudget linesHarmonises the budget dimensions only
stg_fiscal_periodsFiscal 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.

ModelRaw tableCanonical target
stg_d365_fo__gl_entriesgeneral_journal_account_entry_bi_entities + general_journal_entry_bi_entitiesstg_gl_entries (partner_data_area_id is NULL: D365's partner is not mapped yet)
stg_d365_fo__trial_balancetrial_balance_fiscal_year_snapshotsstg_trial_balance
stg_d365_fo__accountsmain_accountsstg_accounts
stg_d365_fo__legal_entitieslegal_entities + ledgersstg_legal_entities
stg_d365_fo__exchange_ratesexchange_ratesstg_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_entriesbudget_register_entriesstg_budget_entries
stg_d365_fo__fiscal_periodsfiscal_calendar_yearsstg_fiscal_periods
stg_d365_fo__gl_journal_entriesgeneral_journal_entry_bi_entitiesbronze_general_journal_entries
stg_d365_fo__budget_register_entriesbudget_register_entriesbronze_budget_register_entries
stg_d365_fo__main_account_categoriesmain_account_categoriesbronze_main_account_categories
stg_d365_fo__consolidation_groupsconsolidate_account_groupsbronze_consolidation_account_groups
stg_d365_fo__exchange_rate_typesexchange_rate_typesbronze_exchange_rate_types
stg_d365_fo__financial_dimensionsdimension_attributesbronze_financial_dimensions
stg_d365_fo__financial_dimension_valuesfinancial_dimension_valuesbronze_financial_dimension_values
stg_d365_fo__fiscal_calendarsfiscal_calendar_yearsbronze_fiscal_calendars
stg_d365_fo__fiscal_calendar_yearsfiscal_calendar_yearsbronze_fiscal_calendar_years

ERPNext adapter (7, models/staging/erpnext/)​

Source erpnext_raw (database epm_raw). One model per canonical target.

ModelRaw tableNotes
stg_erpnext__gl_entriesgl_entryrecord_id is a hash of name; amount = debit - credit; cancelled entries dropped; cost_center → dim_cost_center, project → dim_business_unit
stg_erpnext__trial_balancegl_entryAggregated per entity, account and fiscal year (ERPNext has no snapshot doctype); opening_balance 0
stg_erpnext__accountsaccountroot_type Income reads as Revenue via map_account_type()
stg_erpnext__legal_entitiescompany
stg_erpnext__exchange_ratescurrency_exchange
stg_erpnext__budget_entriesbudget
stg_erpnext__fiscal_periodsfiscal_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):

DatabaseWritten byContents
epm_rawAirbyte; konsolRaw ERP tables (d365_raw, erpnext_raw sources); trial_balance_submissions and trial_balance_submission_control (Trial Balance Submission doctype)
epm_stagingdbt; konsolThe 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_bronzedbtThe 16 bronze tables
epm_silverdbtThe 10 silver tables
epm_golddbt; konsolThe 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.