Status: v1.1 · 2026-11-19, release v1.3 tables (positions, supervisor posts, proposals) added 2026-11-25 · PostgreSQL 17 · migrations managed by Flyway
is_synthetic = true; the UI footer says so.timestamptz stored in UTC. Business dates (work date, pay period) use America/Regina. A shift’s work_date is the local date it starts on.uuid primary keys (generated by the app), except audit_event (bigint identity, for ordering).version int. The API sends it back as an ETag.erDiagram
UNIT ||--o{ UNIT_REQUIREMENT : "needs"
QUALIFICATION ||--o{ UNIT_REQUIREMENT : "may require"
UNIT ||--o{ EMPLOYEE : "home unit"
POSITION ||--o{ EMPLOYEE : "holds"
ROTATION_PATTERN ||--o{ EMPLOYEE : "follows"
UNIT ||--o{ UNIT_SUPERVISION : "supervises"
UNIT ||--o{ UNIT_SUPERVISION : "is covered by"
EMPLOYEE ||--o{ EMPLOYEE_QUALIFICATION : "holds"
QUALIFICATION ||--o{ EMPLOYEE_QUALIFICATION : ""
EMPLOYEE ||--o{ SHIFT_ASSIGNMENT : "works"
UNIT ||--o{ SHIFT_ASSIGNMENT : "at"
SHIFT_TEMPLATE ||--o{ SHIFT_ASSIGNMENT : "shape"
SCHEDULE_PERIOD ||--o{ SHIFT_ASSIGNMENT : "published in"
OVERRIDE |o--o{ SHIFT_ASSIGNMENT : "justifies"
EMPLOYEE ||--o{ ABSENCE : "has"
UNIT ||--o{ OPEN_SHIFT : "has gap"
OPEN_SHIFT ||--o{ OVERTIME_OFFER : "offered as"
EMPLOYEE ||--o{ OVERTIME_OFFER : "receives"
EMPLOYEE ||--o{ PROPOSAL : "submits"
PROPOSAL ||--|{ PROPOSAL_ITEM : "contains"
PAY_PERIOD ||--o{ TIME_ENTRY : "groups"
EMPLOYEE ||--o{ TIME_ENTRY : "earns"
SHIFT_ASSIGNMENT |o--o{ TIME_ENTRY : "source of"
PAY_PERIOD ||--o{ PAYROLL_EXPORT : "exported as"
RULE_SET_VERSION ||--|{ RULE_ROW : "contains"
RULE_TABLE ||--o{ RULE_ROW : "defines columns for"
RULE_CHECK ||--|{ RULE_RESULT : "produces"
RULE_SET_VERSION ||--o{ RULE_CHECK : "evaluated with"
APP_USER ||--o{ APP_USER_ROLE : "has"
APP_USER ||--o{ USER_UNIT_SCOPE : "may manage"
APP_USER |o--|| EMPLOYEE : "is"
APP_USER ||--o{ AUDIT_EVENT : "acts in"
| Table | Key columns | Notes and constraints |
|---|---|---|
unit |
id, code (unique), name, kind (LIVING, ADMISSIONS, CONTROL, ESCORT, OTHER, SUPERVISION), allows_12h bool, allows_16h bool, active |
allows_12h / allows_16h implement rule S-03 (12- and 16-hour patterns need a local agreement). active is the hard off switch; dated closures live in unit_availability, not here. SUPERVISION (release v1.3) is a supervisor post: a unit that is staffed like any other, with its own unit_requirement rows, but whose officers are supervisors. |
qualification |
id, code (unique, e.g. CONTROL, ESCORT, FIRST_AID, ACTING_SUP), name |
ACTING_SUP (release v1.3) is the acting-supervisor qualification: an officer who holds it may work a supervisor post with a warning instead of a block (release v1.3, S2). |
unit_availability |
id, unit_id, disabled_from (first closed day), enabled_from (first open day again, null = no reopening date), reason, created_by, created_at |
One shared source: unit_active_on(unit, day) is true unless a window covers the day and unit.active is on. No row = open every day. Overlaps for a unit are refused with a plain message. |
unit_staffing |
unit_id PK, allocated_headcount 0-999, updated_at, updated_by |
The planner’s funded headcount per unit; absent = the active officers homed there. Audited. |
staffing_setting |
id (1), leave_allowance numeric (default 0.200), updated_at, updated_by |
The leave allowance shown in the staffing formula; editable and audited. |
unit_requirement |
id, unit_id, block (DAY 07–15, EVENING 15–23, NIGHT 23–07), min_staff, qualification_id null, min_with_qualification, effective_from, effective_to |
Coverage is measured by unit and block (ADR-013). Unique on (unit_id, block, effective_from). The release-6 card reads min_with_qualification > 0 rows for active unit-days; the planner does not enforce them. |
shift_template |
id, code, label, start_time, duration_minutes (480, 720, 960), regular_allowed bool, chip_style, active, effective_from, effective_to, rule_set_version_id |
Configurable (ADR-015). Defaults: D8 07:00–15:00, E8 15:00–23:00, N8 23:00–07:00, A12 00:00–12:00, P12 12:00–24:00; V6 adds the real D12 07:00–19:00 and N12 19:00–07:00 for the 120 crews. L16 20:00–12:00 is retired by V13 (active=false) and the 100 seed no longer creates it; an old database keeps its L16 rows and they still render. A “16 h shift” is now a 12 h shift plus an extension. Changing a template never alters existing assignments, which keep their own start_at/end_at. |
rotation_pattern |
id, code, name, cycle_days, pattern jsonb (e.g. {"template":"N12","on":4,"off":4,"anchor":"2027-01-04"}), anchor_date |
The 120 dataset uses D12_DAY_4ON4OFF, N12_NIGHT_4ON4OFF, D8_DAY_5ON2OFF, E8_EVENING_5ON2OFF, CASUAL_12, CASUAL_8; the planner reads the code to keep crews and templates separate. The 100 seed leaves it unused. |
employee |
id, employee_no (unique), first_name, last_name, classification (CO or CS, a foreign key to position), position_since (date, null), home_unit_id, rotation_pattern_id, fte numeric(3,2), seniority_date, active, is_synthetic, shift_pattern (ROTATING_5_2 default / 5_ON_2_OFF / 7_ON_3_OFF) |
fte drives the planner target (FTE × 80 h per period); FTE < 1.0 officers are a fill pool with no guaranteed hours. shift_pattern is the 8 h officer’s own pattern (V10); a 12 h officer’s 4-on/4-off cycle is derived from rotation_pattern, not copied. classification is the officer’s position (release v1.3): the column keeps its name, so no data moved, but it now points at the position table and an unknown code is refused by the database. position_since is seniority within the rank; it is null for an officer who is already in their rank, so seniority inside a rank is coalesce(position_since, seniority_date) and every officer ordering is unchanged. It cannot be earlier than seniority_date (a check constraint); “not in the future” is the writing service’s job, because a check constraint cannot read the clock. |
position |
code PK, name, rank_order int, is_supervisory bool |
The rank reference table (release v1.3): CO Correctional officer (1, not supervisory) and CS Correctional supervisor (2, supervisory). A new rank is a row, but it is also a code change: the api knows two ranks, and a rank it does not know is treated as the lowest, non-supervisory one, so it can never make the planner treat someone as a supervisor by accident. The rank’s name is editable text here and the api reads it from here. |
unit_supervision |
(supervision_unit_id, unit_id) PK |
Which line units a supervisor post covers (release v1.3): the first column is the SUPERVISION unit, the second the line unit it supervises. A trigger refuses a row whose first column is not a SUPERVISION unit, and a row whose second column is one, so a post cannot cover another post. A second trigger refuses a change to a unit’s kind while a link points at it, so a post cannot quietly stop being a post. Used for display only: the post’s own coverage is measured like any other unit’s. |
employee_qualification |
(employee_id, qualification_id) PK, valid_from, valid_to |
The planner does not enforce qualifications. The release-6 coverage card counts an officer as qualified whenever the row exists; it does not read valid_from/valid_to (the card says “start dates are not checked”). Expiry remains future work. |
Coverage rule (ADR-013, revised): coverage is measured hourly, in absolute time. The NIGHT block on date D runs 23:00 D to 07:00 D+1, so a 23:00 shift counts in the hours after midnight and the board and the plan use the same CoverageCalculator. Each block’s min_staff applies to every hour in the block; a block is covered when every hour meets it. A 12-hour 00:00–12:00 shift counts toward the last 7 hours of the previous night and the first 5 hours of its own Day block; N12 19:00–07:00 covers the whole Night block and the last 4 evening hours; D12 07:00–19:00 covers the whole Day block and the first 4 evening hours.
| Table | Key columns | Notes and constraints |
|---|---|---|
schedule_period |
id, unit_id, start_date, end_date, status (DRAFT, PUBLISHED), published_at, published_by |
Changes after publishing trigger notice checks (S-01, P-05). |
shift_assignment |
id, employee_id, unit_id, shift_template_id, schedule_period_id, start_at, end_at, work_date, kind (ROSTERED, EXTRA), source (ROTATION, MANUAL, OVERTIME_OFFER, PROPOSAL), status (PLANNED, CANCELLED), override_id null, created_by, created_at, version |
EXTRA = picked up beyond the roster (e.g. from an overtime offer). Overtime isn’t stored on the shift; it’s computed from hours in the pay period (P-01). CHECK (end_at > start_at). No double-booking: EXCLUDE USING gist (employee_id WITH =, tstzrange(start_at, end_at) WITH &&) WHERE (status <> 'CANCELLED') (needs btree_gist). Known limit: no trigger guards locked pay periods on this table. The locked-period wall here is the api’s 409 only, so a raw SQL UPDATE can still cancel a shift inside a locked period (dev-qa did this on its own stack). time_entry has both the 409 and a trigger. A pilot adds a trigger here, or separate owner and application database roles (ADR-018). |
absence |
id, employee_id, shift_assignment_id null, type (SICK, VACATION, OTHER), start_at, end_at, recorded_by, recorded_at |
Type only: no medical details (FOIP data minimization). |
override |
id, reason text CHECK (length(reason) >= 10), rule_codes text[], rule_set_version_id, created_by, created_at |
Every Block that was overridden links here. Reported in Reports and the audit log. |
open_shift |
id, unit_id, shift_template_id, start_at, end_at, reason (SICK_CALL, VACATION, EXTRA_COVERAGE, OTHER), status (OPEN, OFFERED, FILLED, CANCELLED), filled_assignment_id null, created_by |
|
overtime_offer |
id, open_shift_id, employee_id, rank, ordered bool, status (OFFERED, ACCEPTED, DECLINED, CONFIRMED, WITHDRAWN, EXPIRED), rule_snapshot jsonb, offered_by, offered_at, responded_at |
rule_snapshot keeps the eligibility result at offer time, for audit. Unique on (open_shift_id, employee_id). CONFIRMED was added by V4: the supervisor’s confirmation is a distinct state from the employee’s acceptance. |
proposal |
id, employee_id, note (at most 500 characters), status (WAITING, DECIDED, WITHDRAWN, EXPIRED), submitted_at, submitted_by, withdrawn_at, decided_by, decided_at, version, seq (send order, the tie-break for “newest first”) |
Shift planner (F9). Reshaped by migration V17 (v1.3 P1). “Partly approved” is derived from the items, never stored. |
proposal_item |
id, proposal_id, action (ADD, REMOVE, CHANGE), target_assignment_id null, shift_template_id, unit_id, start_at, end_at, decision (PENDING, ACCEPTED, DECLINED, WITHDRAWN, EXPIRED), rule_snapshot jsonb, plus employee_id (the proposer), work_date, sort_order, decided_by, decided_at, comment (at most 500; required on DECLINED), assignment_id, decision_snapshot, acknowledged_codes, out_of_ot_order, open_shift_id |
Only ADD is accepted in v1.3. A partial unique index allows one waiting item per officer and start. |
| Table | Key columns | Notes and constraints |
|---|---|---|
pay_period |
id, start_date, end_date (14 days), status (OPEN, LOCKED), locked_at, locked_by, unlock_reason |
Unique, non-overlapping date ranges. |
time_entry |
id, employee_id, pay_period_id, shift_assignment_id null, work_date, start_at, end_at, hours numeric(5,2), entry_type (SCHEDULED, ACTUAL), absence_type null, pay_code (REG, OT15, OT20, SICK, VAC, STAT), rule_set_version_id, recorded_by, created_at |
Pay codes come from the pay-classification rule table: the period’s actual hours, in time order, are REG up to the threshold (default 80 h) and overtime beyond it. Codes are recalculated for the whole period after any change and frozen on lock. A trigger rejects inserts and updates when the pay period is LOCKED. |
payroll_export |
id, pay_period_id, generated_at, generated_by, row_count, file_sha256 |
The file isn’t stored; the hash proves what was sent. |
| Table | Key columns | Notes and constraints |
|---|---|---|
rule_table |
id, code (REST, MAX_HOURS, CONSECUTIVE, LONG_SHIFTS, DAYS_OFF, PAY, OT_RANKING, SHIFT_LENGTHS, POSTS), name, template_ref, column_schema jsonb |
Defines the friendly columns an admin edits; template_ref points at the Drools template in the code. |
rule_set_version |
id, version int unique, status (DRAFT, SUBMITTED, APPROVED, PUBLISHED, SUPERSEDED, REJECTED), based_on_version, effective_from, change_reason, created_by, submitted_at, approved_by, approved_at, published_at, build_report jsonb, dry_run_report jsonb, drl_sha256 |
Maker/checker: CHECK (approved_by IS NULL OR created_by IS NULL OR approved_by <> created_by) (matches V1__schema.sql; the created_by IS NULL arm only makes explicit what a CHECK already allows, since a CHECK that evaluates to NULL passes; the API always sets created_by). Only one PUBLISHED row per effective date. |
rule_row |
id, rule_set_version_id, rule_table_id, code (e.g. U-03), enabled, params jsonb, severity (BLOCK, WARN, INFO), override_policy (EMERGENCY, ACKNOWLEDGE, NONE), message, source, is_placeholder, sort_order |
params validated against rule_table.column_schema. Unique on (rule_set_version_id, code). |
rule_check |
id, change_type, payload jsonb, rule_set_version_id, outcome (PASS, WARN, BLOCK), requested_by, created_at, saved bool |
Stored for every saved change (previews aren’t stored). |
rule_result |
id, rule_check_id, rule_code, outcome, message, facts jsonb, evidence_assignment_ids uuid[] |
E.g. facts = {"restHours": 0, "minHours": 8}. |
| Table | Key columns | Notes and constraints |
|---|---|---|
app_user |
id, username unique, display_name, employee_id null, active |
Mock sign-in picks from this table (see 09-access-control.md). |
app_user_role |
(user_id, role) PK |
Roles: EMPLOYEE, SUPERVISOR, RULES_ADMIN, RULES_APPROVER, AUDITOR, DISPLAY, PLANNER. |
user_unit_scope |
(user_id, unit_id) PK |
Which units a supervisor manages. |
audit_event |
id bigint identity, occurred_at, actor_user_id, action, entity_type, entity_id, before jsonb, after jsonb, rule_set_version_id null, override_id null, correlation_id |
Append-only: triggers raise an error on UPDATE, DELETE and TRUNCATE. The prototype has one database user, so there are no role grants yet; a pilot adds an application role with INSERT, SELECT only (ADR-018). |
| Table | Key columns | Notes and constraints |
|---|---|---|
officer_preference |
employee_id PK, shift_length (8/12/16), times_of_day text[] NOT NULL DEFAULT {} (each DAY/EVENING/NIGHT), days_off text[], max_days_off (default 2), updated_at, updated_by |
Soft wishes, not rules. Empty set = no time preference. The old single time_of_day column is dropped by V9; the API still accepts that field for one release. Seeded synthetically, not part of the roster checksum. |
plan_draft |
id, from_date, to_date, seed, pattern8h (ROTATING_5_2/5_ON_2_OFF/7_ON_3_OFF, nullable since V10), status (DRAFT/COMMITTED/DISCARDED), version, created_by, created_at, generated_ms, scorecard jsonb, warnings jsonb, warning_count, committed_at, committed_by, staff_types text[] (default {FULL_TIME,PART_TIME}, must contain FULL_TIME), part_time_fill (AFTER_FULL_TIME default / UP_TO_FTE), cross_unit_fill (OFF default / ON) |
One open draft (partial unique index ... where status = 'DRAFT'). version is the commit ETag. A null pattern8h means every 8 h officer used their own employee.shift_pattern; a non-null value is the one-release facility override a client sent. |
plan_draft_assignment |
id, draft_id, employee_id, unit_id, shift_template_id, work_date, start_at, end_at, kind, sort_order |
Unique on (draft_id, employee_id, start_at). Never read by the planning board; a draft is not a roster. Release 7 lets a PLANNER add/move/reassign/remove one row only while the plan is DRAFT; the live shift_assignment is untouched until commit. |
plan_draft_gap |
id, draft_id, unit_id, gap_date, block, required, placed, reason |
One row per short block-day, visible in the scorecard and the Gaps tab. |
shift_assignment.plan_draft_id |
uuid null, references plan_draft |
Set by commit, so planner-created rows are distinguishable from a supervisor’s edits. |
shift_assignment (employee_id, start_at) and (unit_id, start_at): rule context loading and the planning board.time_entry (pay_period_id, employee_id): reports and payroll export.overtime_offer (employee_id, status): “my offers”.audit_event (entity_type, entity_id) and (occurred_at).rule_row (rule_set_version_id, rule_table_id, sort_order).| Data | Approximate rows |
|---|---|
| Employees | 100 |
| Shift assignments (90 days) | ~4,800 |
Time entries (past days; the generator writes ACTUAL entries only, and scheduled hours come from the assignments) |
~3,400 (generator run, seed 20261001: 3,366) |
| Overtime offers | ~400 |
| Audit events | ~6,000 after seeding |
| 120 crew dataset (separate provider) | 130 employees: 120 officers (100 full-time + 20 casual) and, since release v1.3 S4, 10 supervisors; a quarter plan of 5,595 shifts on commit (5,103 officer + 492 supervisor), 38 short ESC evening block-days and no supervisor-post gaps; checksum ca73467d…a64a (the officers alone: 82b19cf8…32ca, the pre-S4 checksum) |
Tiny for PostgreSQL. The performance targets (NFR-05) come down to sensible indexes and loading only a ±7-day window of shifts for each rule check.
| Script | Contents |
|---|---|
V1__schema.sql |
Extensions (btree_gist, pgcrypto), types, tables, constraints, triggers (append-only audit, locked pay periods). No role grants: the prototype runs as one database user and the triggers are the proof of append-only audit; separate roles and grants are deferred to a pilot (ADR-018). |
V2__reference_data.sql |
Shift templates, blocks, qualifications, rule tables, rule set v1 from 05-union-rules.md |
V3__demo_units_and_users.sql |
Fictional units, unit requirements, demo users and roles |
V4__overtime_offer_confirmed.sql |
The supervisor’s confirmation state on an overtime offer |
V5__planner.sql |
Planner draft/assignment/gap tables, the PLANNER role, preferences, plan_draft_id |
V6__day_night_12h.sql |
D12/N12 templates and published rule-set v2 (U-02 additive kind list, U-10 19-07); no unit flags, so the 100 seed stays A12/P12/L16 at that point (L16 is retired in V13) |
V7__pay_period_dates_unique.sql |
Explicit unique index on pay_period(start_date,end_date); the exclusion constraint already refuses overlaps |
V8__planned_absence_unique.sql |
One planned absence per officer-day: a partial unique index on (employee_id, start_at, end_at) where shift_assignment_id IS NULL, after deduping existing rows; POST /planner/absences inserts with ON CONFLICT (P3-3) |
V9__preference_times_of_day.sql |
Multi-select time of day: adds times_of_day text[] NOT NULL DEFAULT '{}', backfills each old single value to the same one-element set (NONE/NULL to {}), checks every element is DAY/EVENING/NIGHT and drops time_of_day |
V10__officer_shift_pattern.sql |
Per-officer pattern: adds employee.shift_pattern text NOT NULL DEFAULT 'ROTATING_5_2' with the three-code check (existing rows and reset inserts take the default) and makes plan_draft.pattern8h nullable for per-officer drafts |
V11__unit_availability_and_staffing.sql |
Dated unit closures, the staffing allocation and leave setting, and the shared unit_active_on(unit, day) function; no existing row changes, so the 100/120 seeds are untouched |
V12__eight_hour_night_warning.sql |
Rule-set v3: the v2 rows plus U-16 (Warn/acknowledge) for an 8 h officer on a night shift; v2 stays as history |
V13__retire_l16_template.sql |
Sets shift_template.L16.active=false; no rows are deleted, so old L16 history survives and the new-use guard refuses it (ADR-029) |
V14__plan_draft_options.sql |
v1.2 plan options: plan_draft.staff_types and part_time_fill with CHECKs and defaults equal to the earlier generator, so every older draft reads as made with the defaults |
V15__plan_draft_cross_unit_fill.sql |
v1.2 third option: plan_draft.cross_unit_fill (OFF default / ON), and staff_types limited to the two canonical lists (no duplicates) |
V16__positions.sql (release v1.3 S1) |
The position table and its two rows, the foreign key from employee.classification, employee.position_since with its “not before the service date” check, the SUPERVISION unit kind, the unit_supervision link table with its two triggers (the parent must be a post, the child must be a line unit, and a unit’s kind cannot change under a link), and the ACTING_SUP qualification. No unit and no employee row changes, so every dataset checksum, plan fingerprint and payroll golden is unchanged. The file is __positions.sql: its version number is the order it merges in, so it takes the next free number when it merges and nothing else in this document carries the number |
V17__proposals.sql (release v1.3 P1) |
Reshapes the V1 proposal and proposal_item tables in place (they held no rows): proposal status WAITING/DECIDED/WITHDRAWN/EXPIRED (“partly approved” is derived, never stored), item decisions gain WITHDRAWN and EXPIRED, plus the decider, comment, created assignment and the snapshots the inbox shows (ADR-032). No checksum, golden or fingerprint reads these tables |
V18__rule_set_v4_posts.sql (release v1.3) |
The ninth rule table, POSTS “Who can work a post” (columns postKind, allowedPositions, actingQualification), and rule-set v4: the v3 rows plus R-01 (Block, no override; Warn/acknowledge with ACTING_SUP) and R-02 (Warn/acknowledge); v3 stays as history. No unit or employee row changes |
V19__supervision_posts.sql (release v1.3 S4) |
The two supervisor posts as SUPERVISION units, SUP-L “Supervision · Living units” and SUP-O “Supervision · Operations” (fixed ids …-000000000007/8, allows_12h), each with a 1/1/1 unit_requirement from 1 Oct 2026; the unit_supervision links (SUP-L covers A, B, C; SUP-O covers ADM, CTL, ESC); and user_unit_scope rows giving m.ellis and j.chen both posts. The supervisors themselves are seeded by the dataset providers, which also link the two sign-ins (app_user.employee_id) |
Java DemoDataGenerator (demo profile) |
100 officers, rotations, 90 days of assignments, absences (~4%: 2% sick, 2% vacation, ADR-020), overtime fills, actuals for days before “today”, and the planted test cases. Fixed seed, so it’s reproducible. Runs only if the database is empty. The 120 dataset (100 FT crews + 20 casuals; see DATASET120-SPEC) and the 150 dataset (120 FT + 30 casuals; ADR-028) are separate providers, selected by dataset: "120" / "150". |