The three fact tables accumulate transactional events over time and are the primary source of all dashboard metrics.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/kishnahai0806/SteelWorks/llms.txt
Use this file to discover all available pages before exploring further.
production_runs captures planned vs. actual output and downtime for every shift on every line. production_issues attaches at most one classified issue to a run. shipments records the movement of lots against sales orders, including status tracking for partial, on-hold, and backordered shipments. All three tables reference the dimension tables via ON DELETE RESTRICT foreign keys, except production_issues → production_runs which cascades deletes.
production_runs
One row per discrete production run, uniquely identified by the combination of date, shift, line, and lot. This is the central fact table — bothproduction_issues and many reporting queries pivot off it.
Synthetic primary key, generated automatically by the database.
Calendar date on which the run took place.
Foreign key to
calendar_weeks(calendar_week_id). Denormalized for efficient weekly aggregations without a date-to-week calculation at query time. Deletion of the parent week is blocked (ON DELETE RESTRICT).Foreign key to
shifts(shift_id). Identifies which shift (day, night, or swing) the run occurred on. Deletion of the parent shift is blocked (ON DELETE RESTRICT).Foreign key to
production_lines(production_line_id). Deletion of the parent line is blocked (ON DELETE RESTRICT).Foreign key to
lots(lot_id). Identifies which production lot was being processed during this run. Deletion of the parent lot is blocked (ON DELETE RESTRICT).Number of units scheduled for this run. Must be ≥ 0 (
ck_production_runs_units_planned_nonneg).Number of units actually produced. Must be ≥ 0 (
ck_production_runs_units_actual_nonneg). The difference units_planned − units_actual is the production variance used in dashboard charts.Total unplanned downtime recorded for the run, in minutes. Must be ≥ 0 (
ck_production_runs_downtime_nonneg).uq_production_runs_natural — UNIQUE (run_date, shift_id, production_line_id, lot_id) — prevents duplicate log entries for the same run slot. Inserts that would violate this constraint can use ON CONFLICT … DO NOTHING for idempotent loading.
Indexes on production_runs:
| Index | Columns | Purpose |
|---|---|---|
idx_production_runs_run_date | run_date | Date-range filtering |
idx_production_runs_line_date | (production_line_id, run_date) | Per-line date queries |
idx_production_runs_lot_id | lot_id | Lot drill-down |
idx_production_runs_week_id | calendar_week_id | Weekly aggregation |
production_issues
Records the primary issue for a production run. The one-to-one relationship withproduction_runs (enforced by a UNIQUE constraint on production_run_id) means a run either has one issue or none — there is no multi-issue record in this schema.
Synthetic primary key, generated automatically by the database.
Foreign key to
production_runs(production_run_id). When the parent run is deleted, its issue record is also deleted (ON DELETE CASCADE, constraint fk_production_issues_production_run_id). The UNIQUE constraint uq_production_issues_production_run_id enforces the one-issue-per-run rule.Foreign key to
issue_types(issue_type_id). Classifies the issue. Deletion of the parent issue type is blocked while any issue record references it (ON DELETE RESTRICT).Optional free-text notes entered by the shift supervisor describing the issue (e.g.,
"Tool wear observed; replaced cutting insert.").The
UNIQUE constraint on production_run_id enforces that each production run has at most one primary issue. To query issue data in reports, use the issue_occurrences view rather than joining production_issues directly — the view provides pre-joined issue_type_name, run_date, production_line_id, and lot_id columns.shipments
Records outbound shipment events for lots against sales orders. A single lot may appear in multiple shipment rows (e.g., split shipments, a partial followed by a completion, or an on-hold record). Theship_status column drives operational dashboards that track fulfillment health.
Synthetic primary key, generated automatically by the database.
Date the shipment was dispatched or the shipment event was recorded.
Foreign key to
calendar_weeks(calendar_week_id). Denormalized for weekly shipping reports. Deletion of the parent week is blocked (ON DELETE RESTRICT).Foreign key to
lots(lot_id). Identifies which lot is being shipped. Deletion of the parent lot is blocked (ON DELETE RESTRICT).Foreign key to
sales_orders(sales_order_id). Links the shipment to a customer order. Deletion of the parent order is blocked (ON DELETE RESTRICT).Two-letter US state code for the delivery destination. The constraint
ck_shipments_destination_state_len enforces char_length(destination_state) = 2.Optional foreign key to
carriers(carrier_id). May be NULL when no carrier has been assigned (e.g., for on-hold or backordered records). Deletion of the parent carrier is blocked when referenced (ON DELETE RESTRICT).Optional Bill of Lading number issued by the carrier (e.g.,
BOL-0001).Optional carrier tracking number or PRO number (e.g.,
1Z999, FDX123).Quantity of units included in this shipment record. Must be ≥ 0 (
ck_shipments_qty_nonneg). The constraint ck_shipments_backordered_qty additionally requires qty_shipped = 0 whenever ship_status = 'backordered'.Current status of the shipment. Must be one of the following values (enforced by
ck_shipments_ship_status):| Value | Meaning |
|---|---|
shipped | Fully dispatched and delivered |
partial | Partially shipped; additional shipment(s) expected |
on_hold | Held pending resolution (see hold_reason) |
backordered | No inventory available; qty_shipped must equal 0 |
Optional description of why the shipment is on hold (e.g.,
Quality hold, Customer requested delay). Typically populated when ship_status = 'on_hold'.Optional free-text notes about the shipment.
shipments:
ck_shipments_qty_nonneg—qty_shipped >= 0ck_shipments_destination_state_len—char_length(destination_state) = 2ck_shipments_ship_status—ship_status IN ('shipped', 'partial', 'on_hold', 'backordered')ck_shipments_backordered_qty—ship_status <> 'backordered' OR qty_shipped = 0
shipments:
| Index | Columns / Condition | Purpose |
|---|---|---|
idx_shipments_ship_date | ship_date | Date-range filtering |
idx_shipments_status | ship_status | Filter by fulfillment status |
idx_shipments_lot_id | lot_id | Lot-to-shipment join path |
idx_shipments_sales_order_id | sales_order_id | Order drill-down |
idx_shipments_destination_state_date | (destination_state, ship_date) | State + date composite reporting |
idx_shipments_on_hold | ship_date WHERE ship_status = 'on_hold' | Partial index for “on hold” dashboard panel |
Sample queries
The following queries are taken directly fromdb/sample_queries.sql and demonstrate common fact-table reporting patterns.
Weekly production summary by line
Aggregates planned units, actual units, and total downtime per ISO week per line. This powers the primary production summary panel in the dashboard.Top issue types in the last 30 days
Uses a CTE to anchor the window to the most recentrun_date in the table (rather than NOW()) so results are stable against the seed dataset.