Staging Schema Reference — import.*
The import.* schema is the stateless staging contract between the Stage processes (per-customer) and the import runner (standard). Rows land here exactly as the customer extract produced them; the import resolves xuids, applies load modes, and writes master.*.
Canonical DDL: files/DDL/import_schema.sql.
Loading Conventions
- NULL — a literal unquoted
\N in CSVs; an empty field is DATA (matches the the customer stager and the customer seed scripts).
- Headers are validated against
information_schema — no hand-maintained column lists; unknown files fail loudly.
- Bulk load — streaming
COPY FROM STDIN (stage_csv_obj), never per-row INSERT; ANALYZE after big loads.
- xuid-based joins — every business key enters staging as
*_xuid strings; the import resolves them to numeric ids (unresolvable rows are rejected loudly, counted in import_table_result).
Objects (dependency order = the import's execution order)
Type lookups (upsert on xuid)
| Staging table |
Target |
Notes |
import.item_type |
master.item_type |
|
import.site_type |
master.site_type |
|
import.demand_type |
master.demand_type |
Joined by name downstream |
import.route_type |
master.route_type |
Carries planning_type + source/destination_condition_code — the stock-condition pair. Unknown planning types and unresolvable condition codes are rejected, never silently paired |
import.causal_usage_type |
master.causal_usage_type |
|
import.zone |
master.site (site_class='zone') |
Top-level zones insert before sub-zones (data-modifying CTE); xuid collisions with physical sites are rejected |
Dimension masters (upsert on xuid)
| Staging table |
Target |
Key staging columns |
import.item |
master.item |
item_type_xuid, unit_cost, priority_class, strategic_weight, revenue_weight, criticality_weight, expiry_period_weeks |
import.site |
master.site |
site_type_xuid, site_class (managed/install_site), zone_xuid, region_xuid, max_capacity_qty, working_days_per_week, lon/lat |
import.customer |
master.customer |
code (PK), customer_type, country, contact |
import.channel |
master_channel |
|
import.causal_asset_type |
master.causal_asset_type |
AOG cost inputs |
import.maintenance_event |
master.maintenance_event |
Event vocabulary |
Demand & forecasts
| Staging table |
Target |
Mode |
Notes |
import.demand_actuals |
master.demand_orders (Layer 0) |
truncate_replace default (upsert via import_settings.demand_actuals_load_mode) |
Rejects rows with blank order_id/line_id, negative qty, or unresolvable condition_code. is_open NULL → resolved to date >= planning Monday. Carries customer_code, priority_class, received_date |
import.forecast_external |
master.forecast_external |
truncate_replace |
Customer forecasts as master data; Monday-normalizes dates; rejects negative qty |
import.feature_values |
master_feature_values |
upsert/append |
CF:{name} features; data_date versioning — versions coexist; global features have both xuids NULL |
Network & stock
| Staging table |
Target |
Mode |
Notes |
import.route |
master.route |
upsert |
Lane master data (see the route columns) |
import.route_quota_override |
master.route_quota_override |
upsert |
Per-lane weekly quota/coverage change points (Monday-normalized effective_date) |
import.bill_of_material |
master.bill_of_material |
upsert |
Period-effectivity windows |
import.on_hand |
master.on_hand |
upsert |
condition_code resolves to condition_id (unresolvable codes are rejected, not silently good) |
import.item_location |
master.item_location |
upsert |
Per (item, site) economics: order cost, holding rate, unit cost, balancing_excess_ratio |
import.item_supersession |
master.item_supersession |
upsert |
Donor → successor |
import.firm_supply_orders |
master_supply_orders_firm |
upsert |
Open ERP commitments; natural key (item, site, source, order_type, arrival_dt); po_number/line_number document identity |
import.sales_return |
master.sales_return |
upsert |
Natural key (item, site, return_date) |
Capacity & calendars
| Staging table |
Target |
Mode |
Notes |
import.capacity |
master.capacity |
replace-per-resource-set |
Dated ranges; Monday-normalizes both endpoints; NULL scenario = all scenarios |
import.capacity_day_off |
master.capacity_day_off |
upsert |
Day-off patterns per resource |
import.route_resource |
master.route_resource |
upsert |
Natural key (route_id, resource_id, resource_type) + qty_per_unit |
import.calendar / import.calendar_entry |
master.calendar(_entry) |
upsert |
Working-day calendars |
Causal & maintenance inputs
| Staging table |
Target |
import.causal_asset |
master_causal_asset |
import.causal_bom |
master_causal_bom |
import.causal_failure_rate |
master_causal_failure_rate |
import.causal_asset_coverage / import.causal_asset_deployment / import.causal_asset_usage |
the causal asset model |
import.causal_fleet_plan |
the causal fleet plan |
import.maintenance_bom |
master_maintenance_bom |
Ledgers (ClickHouse-native targets)
| Staging table |
Target |
Mode |
Notes |
import.supply_movement |
CH MASTER_supply_movement |
truncate |
All order types; end_date NULL = in-flight (kept, excluded from stats) |
import.purchase_receipt |
CH MASTER_supply_orders_hist |
truncate_replace (staging twin swap) |
Closed-PO snapshots; restates the full receipt history per reload |
Audit & Utility Tables
| Table |
Role |
import.import_run |
One row per job: run_kind (stage/import), source, scenario_id, status, row counts, triggered_by |
import.import_table_result |
Per-table outcome: rows staged/loaded/rejected, load_mode, duration |
import.import_rejection_sample |
Opt-in (import_settings.capture_rejections) sample of rejected rows with reasons (≤ 20/table) |
Templates & Interactive Upload
GET /api/import/stage/templates/{object} — headers from the catalog + the NULL convention note (for building CSVs by hand).
POST /api/import/stage/{object} — interactive single-object CSV upload (admin; mode=replace|append with temp-twin dedupe).
GET /api/import/stage/settings / PUT …/settings — the tenant's Stage process config (stage_settings).
GET /api/import/runs?run_kind=stage — stage-run audit trail.