Repository navigation
Data Model
amalps565 edited this page Sep 30, 2026
·
2 revisions
The schema is created by Flyway migrations in
backend/src/main/resources/db/migration(V1__schema.sql,V2__seed.sql).
erDiagram
USERS ||--o{ BOOKINGS : makes
FLOORS ||--o{ CELLS : contains
FLOORS ||--o{ BOOKINGS : "on"
CELLS ||--o{ BOOKINGS : "booked as desk"
USERS {
bigint id PK
text username UK
text password_hash
text display_name
}
FLOORS {
bigint id PK
text name
int rows
int cols
text neighbour_mode "ORTHOGONAL or ALL"
}
CELLS {
bigint id PK
bigint floor_id FK
int row
int col
text type "DESK, WALKWAY, WALL, ROOM"
text label
bigint last_seq "latest seq for this desk"
}
BOOKINGS {
bigint id PK
bigint desk_id FK
bigint floor_id FK
bigint user_id FK
date date
timestamptz created_at
}
| Table | Purpose | Constraints |
|---|---|---|
users |
Employees who can sign in | unique username
|
floors |
A floor's grid size and neighbour mode |
neighbour_mode in (ORTHOGONAL, ALL) |
cells |
Every cell of a floor's grid, desk or not | unique (floor_id, row, col); row and col within the floor's size |
bookings |
One desk booked by one user for one day | unique (desk_id, date); unique (user_id, date); desk_id must point to a DESK cell |
- Cancelling deletes the booking row. That keeps both unique constraints simple, with no need for a "cancelled" status.
-
floor_idonbookingsis kept alongsidedesk_idso the spacing check and the snapshot can query one floor and date directly. -
Versioning: a Postgres sequence,
desk_status_seq, gives every desk status change (book or cancel) an increasing number calledseq. The desk rows are locked while they change, so each desk'sseqvalues always increase in commit order. Clients useseqto drop stale updates. See Real-Time Updates. -
cells.last_seqholds the desk's latestseq. It's written in the same locked transaction as every book or cancel, and the snapshot returns it, so clients can safely drop updates they already reflect. -
Seed data (
V2__seed.sql): five users (alice,bob,carol,dave,erin, passwordpassword, bcrypt-hashed); Floor 3, 8 × 12,ORTHOGONAL, with column 6 a walkway and desks3-A1to3-H12; and Floor 4, 4 × 6,ALL, desks4-A1to4-D6. -
Indexes:
bookings(floor_id, date)for snapshots and spacing checks. The unique constraints cover desk and user lookups by date.
Repository · The CLAUDE.md files in the repo are the source of truth for rules and the API contract. If this wiki disagrees with them, the repo wins.