Files
PacketStation/docs/SCHEMA.md
T
spencermandClaude Fable 5.1 97b0973130 Phase 1: identity, sessions, audit, frontend shell
AD sign-in over LDAPS (search with the service account, bind as the user,
nested groups through LDAP_MATCHING_RULE_IN_CHAIN, disabled accounts refused),
roles as the union of PS-* groups mapped by a table derived from the seeded
departments. Server-side sessions with idle, lock and absolute timeouts, Origin
and X-Requested-With check, step-up unlock. Optional Argon2id PIN set with the
domain password; PIN sign-in by employee ID on registered devices only; five
wrong attempts disable the PIN, three wrong at unlock or signature end the
session. Rate limits per account and per address before any bind. Devices,
signatures table and sign helper, audit rows for every identity event, SSE over
LISTEN/NOTIFY with presence. Account settings and Admin APIs and screens
(AD view, devices, PIN clearing, group map with missing-group flags, refresh
from AD now). CLI ad-groups --list and ad-refresh. Migration 0002.

Frontend: real sign-in (password tab, PIN keypad on registered devices), lock
screen, role switcher, Account settings, Admin shell, screen placeholders.

CI: Samba AD DC container (PSTEST.LOCAL) with a generated CA, 49 of the 50
groups plus one extra, 17 test users; wired into the CI compose overlay and
the Gitea workflow; Playwright sign-in scenario.

Verified on docker-1: 171 server tests green inside the CI stack against
PostgreSQL and the Samba DC, 48 frontend tests, 8 Playwright scenarios against
the live stack (password and PIN sign-in, lock and unlock, Admin group map).
Findings recorded in the docs: the DC needs CAP_SYS_ADMIN, a hidden tab locks
only after a minute as the old build did,
and the app uses the alias ps-app for Playwright because "app" is on
Chromium's HSTS preload list.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-10-16 07:40:29 -06:00

5.0 KiB

Packet Station schema

Status: phase 1 built (identity and organisation seed). Phases 2 and 3 add the rest. The DDL is in server/packetstation/migrations/; this file explains it. See PLAN.md, "Schema".

Conventions

Identity bigints, except users, keyed on the AD objectGUID. Postgres enums for workflow states. Every timestamp is timestamptz in UTC. Soft delete uses removed_at, removed_by and removed_reason. Append-only tables give the app role insert and select only, plus a trigger that refuses updates and deletes.

Database roles

A superuser for bootstrap, the migrate role ps_migrate (owns the schema, runs migrations) and the app role ps_app. The plan's deployment section also names a worker role ps_worker. Phase 0 creates only the first three; whether the worker gets its own role is still to settle.

Identity (phase 1, migration 0002)

Enums: role_kind (admin, clerical, clerical_supervisor, warehouse, warehouse_supervisor, qc, qc_supervisor, pm, shop_worker, shop_lead, shop_supervisor), session_kind (password, pin), sig_factor (password, pin), dept_kind (support, shop).

  • users: id uuid is the AD objectGUID, stable across renames. Caches sam_account (unique, case-insensitive), upn, display_name, emp_no (text; indexed but not unique, because a duplicate must be storable and flagged), email, welder_stamp, active, directory_flags jsonb (disabled, missing or duplicate employee ID), ad_synced_at, last_signin_at. A user whose AD account is disabled or gone keeps the row, marked inactive.
  • user_roles: (user_id, role, dept_code) rebuilt at every sign-in, at the 15-minute role refresh and by the AD refresh. Office roles carry their department code, admin carries null, shop roles carry the two-digit code. Only the highest shop level per department is stored.
  • sessions: token_hash (HMAC-SHA256 of the cookie token with the session key), kind, device_id for PIN sessions, expires_at (absolute), last_seen_at (idle), locked_since, revoked_at and revoked_reason, ip, user_agent, roles_snapshot jsonb ({"roles": [...], "groups": [...]}), roles_checked_at, stepup_failures, hidden_since (the last hidden-tab report, cleared by the next request).
  • devices: registered shop devices. name, token_hash of the device cookie, registered_by, last_seen_at, revoked_at, revoked_by.
  • user_pins: one row per user with a PIN. Argon2id hash, failed_count (across sign-in, unlock and signature), disabled_at, set_at. Never readable by Admin in clear; Admin may delete the row.
  • signin_attempts: append-only. account (lower(login), emp:<emp_no> or user:<uuid>), ip, kind (password, pin, unlock, signature, pin_set), ok, reason, user_id, session_id. Both rate limits count the failed rows here.
  • signatures: append-only. Who (user_id, account and display_name snapshots), the session_id and session_kind, the factor, action, meaning, packet_id, subject_type, subject_id and a content_hash (sha256 of the canonical JSON of what was signed). Later phases reference it from every sign-off row.

Append-only tables use the ps_append_only trigger from 0001 and revoke UPDATE, DELETE and TRUNCATE from ps_app.

Organisation (phase 1 seed, phase 2 completes)

  • departments: code (text PK, CL, WH, QC, PM, 01 to 14), slug (the AD group short name, unique), name, kind, sort, active, supervisor_group (false only for PM). A trigger refuses changes to code and slug. Seeded with the 18 departments from the brief and the old depts.js.
  • stations: (dept_code, name, sort, active), seeded with the old station lists (Stall 1 to 6, Station 1 to 4, Hydro Bay 1 and 2, Blast Booth, Paint Booth 1 and 2).
  • user_station_limits: phase 2.

The 50 AD group names are derived from departments plus PS-Admins: PS-<slug> and PS-<slug>-Supervisor for support departments, PS-<code>-<slug>-<Worker|Lead|Supervisor> for shop departments. packetstation ad-groups --list prints them.

Projects and units (phase 2)

projects, project_aliases, project_renumbers, units.

Packets (phase 2)

The packet header and its child tables: work orders, pages, BOM lines, shorts, welds, heat tags, stages, warehouse, transitions, Q.C., seals, log.

Change orders (phases 2 and 3)

change_orders, co_items, co_required_depts, co_verifications.

Documents (phases 2, 4 and 6)

assets, packet_docs, qc_docs, ITPs.

Audit, settings, jobs (phases 1 and 3)

audit_events with a hash chain, settings, job_requests, job_runs, job_schedule, worker_heartbeat.

Notifications (phase 9)

Rules, recipients, exclusions, outbox, sent log, state.

VISUAL and drawing caches (phase 3)

visual_batches, visual_rows, visual_materials, order links, labor, change rows, ignored work orders, resource map, drawing_lookups.

Versioning

packets.version goes up in every transaction that touches the packet or a child. It is the ETag and the NOTIFY payload.