Leave management system database schema

Twelve tables. The design rests on requests, leave_days and allowances: every booking is a request, every half-day it takes is a leave_days row whose unique key makes double booking impossible, and each person has one allowance row per year. Day amounts are stored as integer half-days, and balances are computed from the requests every time instead of being kept as a running total.

  • 12 tables, 7 indexes
  • Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite 0.6.1),
  • 275 seed rows from the blueprint
  • The blueprint's test build passed 32 of 32 acceptance checks

Copy the SQLDownload SQLDownload seed data

By Sam Claassen · From the Time-Off Tracker blueprint · MIT licensed · Markdown version

Time-off tracker entity-relationship diagram

settingsidPK+ 2 more columnsteamsidPK+ 1 more columnpeopleidPKteam_id→ teamsapprover_id→ people+ 8 more columnsleave_typesidPK+ 7 more columnspublic_holidaysidPK+ 2 more columnsallowancesidPKperson_id→ people+ 5 more columnsyear_closesyearPKclosed_by→ people+ 2 more columnsrequestsidPKperson_id→ peopleleave_type_id→ leave_typescreated_by→ peopledecided_by→ peoplecancelled_by→ people+ 15 more columnsleave_daysidPKrequest_id→ requestsperson_id→ people+ 2 more columnseventsidPKrequest_id→ requestsperson_id→ peopleactor_id→ people+ 4 more columnsnotificationsidPKperson_id→ peoplerequest_id→ requests+ 8 more columnsdigest_runsweek_startPK+ 1 more columnsettingsidPK+ 2 more columnsteamsidPK+ 1 more columnpeopleidPKteam_id→ teamsapprover_id→ people+ 8 more columnsleave_typesidPK+ 7 more columnspublic_holidaysidPK+ 2 more columnsallowancesidPKperson_id→ people+ 5 more columnsyear_closesyearPKclosed_by→ people+ 2 more columnsrequestsidPKperson_id→ peopleleave_type_id→ leave_typescreated_by→ peopledecided_by→ peoplecancelled_by→ people+ 15 more columnsleave_daysidPKrequest_id→ requestsperson_id→ people+ 2 more columnseventsidPKrequest_id→ requestsperson_id→ peopleactor_id→ people+ 4 more columnsnotificationsidPKperson_id→ peoplerequest_id→ requests+ 8 more columnsdigest_runsweek_startPK+ 1 more column
Each box is a table with its key columns. A line runs from a table up to a table it references, with the forked end on the side that has many rows; a dashed line is an optional reference.

Relationships

  • people.team_id references teams.id: each people row points to exactly one teams row, and one teams row can have many people rows pointing to it.
  • people.approver_id references people.id: each people row points to at most one another people row, and one people row can have many people rows pointing to it.
  • allowances.person_id references people.id: each allowances row points to exactly one people row, and one people row can have many allowances rows pointing to it.
  • year_closes.closed_by references people.id: each year_closes row points to exactly one people row, and one people row can have many year_closes rows pointing to it.
  • requests.person_id references people.id: each requests row points to exactly one people row, and one people row can have many requests rows pointing to it.
  • requests.leave_type_id references leave_types.id: each requests row points to exactly one leave_types row, and one leave_types row can have many requests rows pointing to it.
  • requests.created_by references people.id: each requests row points to exactly one people row, and one people row can have many requests rows pointing to it.
  • requests.decided_by references people.id: each requests row points to at most one people row, and one people row can have many requests rows pointing to it.
  • requests.cancelled_by references people.id: each requests row points to at most one people row, and one people row can have many requests rows pointing to it.
  • leave_days.request_id references requests.id: each leave_days row points to exactly one requests row, and one requests row can have many leave_days rows pointing to it.
  • leave_days.person_id references people.id: each leave_days row points to exactly one people row, and one people row can have many leave_days rows pointing to it.
  • events.request_id references requests.id: each events row points to at most one requests row, and one requests row can have many events rows pointing to it.
  • events.person_id references people.id: each events row points to exactly one people row, and one people row can have many events rows pointing to it.
  • events.actor_id references people.id: each events row points to at most one people row, and one people row can have many events rows pointing to it.
  • notifications.person_id references people.id: each notifications row points to exactly one people row, and one people row can have many notifications rows pointing to it.
  • notifications.request_id references requests.id: each notifications row points to at most one requests row, and one requests row can have many notifications rows pointing to it.

Time-off tracker tables

The schema has 12 tables. Every column below is read from the SQL file itself. Also described as: PTO tracker database design, employee leave management database tables, vacation tracker SQL schema.

TableImplementsWhat a row is
settingsSettingsThe single company row: name and the carry-over cap in half-days.
teamsTeamA team or department people belong to.
peoplePersonSomeone who can sign in, with their team, approver, working week, yearly allowance, borrow limit and calendar feed token.
leave_typesLeaveTypeA kind of leave, with whether it counts against the allowance and whether it needs approval.
public_holidaysPublicHolidayA company public holiday, which is never charged.
allowancesAllowanceOne person's entitlement, carry-over and adjustment for one leave year.
year_closesYearCloseA closed leave year and the carry-over cap that was used to close it.
requestsRequestOne booking of leave, with its half-day amount, status and decision or cancellation details.
leave_daysLeaveDayOne morning or afternoon session taken by a pending or approved request.
eventsEventOne append-only history entry about a request or an allowance.
notificationsNotificationOne email in the outbox, with its send status and attempt count.
digest_runsDigestRunOne weekly digest run, keyed by the Monday it covers so it runs only once.

settings

The single settings row for the company.

ColumnTypeNullDefaultKeyNotes
idINTEGERno1Primary keyalways 1, so there can only be one rowCheck: id = 1
company_nameTEXTno
carry_over_capINTEGERno10half-days; 10 = 5 days; 0 = nothing carries overCheck: carry_over_cap >= 0

teams

A team (department) people belong to.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
nameTEXTnoUnique

people

A person who can sign in and book leave.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
nameTEXTno
emailTEXTnoUniquestored lower-caseCheck: email = LOWER(email)
team_idTEXTnoReferences teams.id
approver_idTEXTyesReferences people.idnull: admins decide (R9)
is_adminBOOLEANnoFALSE
working_daysTEXTno'1,2,3,4,5'comma-separated ISO weekdays, 1 = Monday to 7 = Sunday, at least oneCheck: working_days <> ''
annual_allowanceINTEGERno40half-days; copied to entitlement when a year's allowance row is createdCheck: annual_allowance >= 0
borrow_limitINTEGERno0half-days available may go below zeroCheck: borrow_limit >= 0
calendar_tokenTEXTnoUniquerandom secret in the calendar feed URL (section 13)Check: LENGTH(calendar_token) >= 32
activeBOOLEANnoTRUE
  • Table check: approver_id IS NULL OR approver_id <> id
  • App rule (R9, R15): only active people can be picked as approvers.
  • App rule (R15): there must always be at least one active admin.

leave_types

A kind of leave, such as Annual leave or Sick leave.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
nameTEXTnoUnique
codeTEXTnoUniqueshown on the calendar, e.g. ALCheck: LENGTH(code) = 2
colorTEXTnohex, e.g. #2f7d6dCheck: color LIKE '#%'
counts_against_allowanceBOOLEANno
needs_approvalBOOLEANnofalse: requests are approved straight away
positionINTEGERnodisplay order
activeBOOLEANnoinactive types can't be picked for new requests

public_holidays

A company public holiday. Never charged against the allowance.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
dateDATEnoUnique
nameTEXTno

allowances

One person's allowance for one leave year (the calendar year). A missing row means entitlement = annual_allowance, carried_over 0, adjustment 0.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
person_idTEXTnoReferences people.id
yearINTEGERno
entitlementINTEGERnohalf-daysCheck: entitlement >= 0
carried_overINTEGERno0half-days, may be negative; written only when the previous year is closed
adjustmentINTEGERno0half-days, may be negative
adjustment_noteTEXTyesrequired when adjustment is not 0
  • Unique together: person_id, year
  • Table check: adjustment = 0 OR (adjustment_note IS NOT NULL AND adjustment_note <> '')
  • App rule (section 5): write a row only when something is saved for that year; viewing never creates one.
  • App rule (R7): balances are computed from requests every time; no running total is stored.

year_closes

A closed leave year. A row means the year is closed and nothing in it may change (R14).

ColumnTypeNullDefaultKeyNotes
yearINTEGERnoPrimary key
carry_over_capINTEGERnohalf-days; the cap used for this closeCheck: carry_over_cap >= 0
closed_byTEXTnoReferences people.id
closed_atTIMESTAMPnoCURRENT_TIMESTAMP

requests

One booking of leave. Never edited: to change dates, cancel and request again.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
person_idTEXTnoReferences people.idwhose leave it is
leave_type_idTEXTnoReferences leave_types.id
yearINTEGERnothe year of start_date
start_dateDATEno
start_halfTEXTnopm: first day is afternoon onlyCheck: start_half IN ('am', 'pm')
end_dateDATEno
end_halfTEXTnoam: last day is morning onlyCheck: end_half IN ('am', 'pm')
daysINTEGERnohalf-days taken (section 6)Check: days > 0
counts_against_allowanceBOOLEANnocopied from the leave type at creation
statusTEXTnoCheck: status IN ('pending', 'approved', 'declined', 'cancelled')
noteTEXTyestrimmedCheck: note IS NULL OR LENGTH(note) <= 500
created_byTEXTnoReferences people.idthe person, or the admin who recorded it
decided_byTEXTyesReferences people.idset by approve and decline
decided_atTIMESTAMPyes
decision_noteTEXTyesoptional when approved; the reason when declined
cancelled_byTEXTyesReferences people.id
cancelled_atTIMESTAMPyes
cancel_reasonTEXTyesrequired when an admin cancels someone else's leave
created_atTIMESTAMPnoCURRENT_TIMESTAMP
updated_atTIMESTAMPnoCURRENT_TIMESTAMP
  • Table check: end_date >= start_date
  • Table check: NOT (start_date = end_date AND start_half = 'pm' AND end_half = 'am')
  • Table check: decided_by IS NULL OR decided_by <> person_id
  • Table check: status <> 'declined' OR (decided_by IS NOT NULL AND decided_at IS NOT NULL AND COALESCE(LENGTH(decision_note), 0) >= 3)
  • Table check: status <> 'cancelled' OR (cancelled_by IS NOT NULL AND cancelled_at IS NOT NULL)
  • Table check: status <> 'cancelled' OR cancelled_by = person_id OR COALESCE(LENGTH(cancel_reason), 0) >= 3
  • Index requests_person_year on (person_id, year)
  • Index requests_status on (status)
  • App rule (R2): end_date is in the same year as start_date, and year is that year.
  • App rule (section 8): status moves pending -> approved | declined | cancelled, approved -> cancelled; declined and cancelled are final.
  • App rule (R5, R8): save the request, its leave_days and its event in one transaction that locks the person's allowance row.
  • App rule (R12): days, the leave_days rows and counts_against_allowance are set once at creation.

leave_days

One half-day session (am or pm) taken by a pending or approved request.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
request_idTEXTnoReferences requests.id
person_idTEXTnoReferences people.idsame as the request's person
dateDATEno
halfTEXTnoCheck: half IN ('am', 'pm')
  • Unique together: person_id, date, half
  • Index leave_days_date on (date)
  • Index leave_days_request on (request_id)
  • App rule (section 5): rows are written with the request and deleted when it is declined or cancelled.

events

One entry in the history of a request or an allowance. Append-only.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
request_idTEXTyesReferences requests.idnull for allowance changes and carry-over
person_idTEXTnoReferences people.idwhose leave or allowance it is about
actor_idTEXTyesReferences people.idnull for system actions
typeTEXTnoCheck: type IN ('requested', 'recorded', 'approved', 'declined', 'cancelled', 'allowance_changed', 'carried_over')
noteTEXTyes
dataTEXTyesJSON text, e.g. old and new values for an allowance change
created_atTIMESTAMPnoCURRENT_TIMESTAMP
  • Index events_request on (request_id)
  • Index events_person on (person_id)
  • App rule (R13): every request action and allowance change writes exactly one event; never updated or deleted.

notifications

One email in the outbox, queued in the same transaction as the action that caused it.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
person_idTEXTnoReferences people.idrecipient
request_idTEXTyesReferences requests.id
kindTEXTnoCheck: kind IN ('needs_approval', 'booked', 'recorded', 'approved', 'declined', 'cancelled', 'weekly_digest', 'year_closed')
subjectTEXTno
bodyTEXTno
statusTEXTno'queued'logged: no email provider configuredCheck: status IN ('queued', 'sent', 'logged', 'failed')
attemptsINTEGERno0Check: attempts >= 0
errorTEXTyes
created_atTIMESTAMPnoCURRENT_TIMESTAMP
sent_atTIMESTAMPyes
  • Index notifications_status on (status)
  • App rule (section 11): queued and failed notifications are retried until they have had 5 attempts.

digest_runs

One weekly digest run. The unique week_start stops a second run for the same week.

ColumnTypeNullDefaultKeyNotes
week_startDATEnoPrimary keythe Monday of the week the digest covers
created_atTIMESTAMPnoCURRENT_TIMESTAMP

The SQL

The whole schema in one file. It runs top to bottom, unmodified, on SQLite and PostgreSQL. Download pto-tracker.sql or copy it from here.

pto-tracker.sql
-- Time-Off Tracker database schema
-- Source: https://personalsoftwarefactory.com/blueprints/pto-tracker (data model, section 5 of the blueprint)
-- Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite). All timestamps are UTC.
-- License: MIT. Free to copy and adapt.
--
-- Every day amount is an integer number of half-days: 1 day = 2, half a day = 1.
-- Leave dates are calendar dates (YYYY-MM-DD) in the team time zone, with no time.

-- The single settings row for the company.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY DEFAULT 1 CHECK (id = 1), -- always 1, so there can only be one row
  company_name TEXT NOT NULL,
  carry_over_cap INTEGER NOT NULL DEFAULT 10 CHECK (carry_over_cap >= 0) -- half-days; 10 = 5 days; 0 = nothing carries over
);

-- A team (department) people belong to.
CREATE TABLE teams (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL UNIQUE
);

-- A person who can sign in and book leave.
-- App rule (R9, R15): only active people can be picked as approvers.
-- App rule (R15): there must always be at least one active admin.
CREATE TABLE people (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT NOT NULL UNIQUE CHECK (email = LOWER(email)), -- stored lower-case
  team_id TEXT NOT NULL REFERENCES teams(id),
  approver_id TEXT REFERENCES people(id), -- null: admins decide (R9)
  is_admin BOOLEAN NOT NULL DEFAULT FALSE,
  working_days TEXT NOT NULL DEFAULT '1,2,3,4,5' CHECK (working_days <> ''), -- comma-separated ISO weekdays, 1 = Monday to 7 = Sunday, at least one
  annual_allowance INTEGER NOT NULL DEFAULT 40 CHECK (annual_allowance >= 0), -- half-days; copied to entitlement when a year's allowance row is created
  borrow_limit INTEGER NOT NULL DEFAULT 0 CHECK (borrow_limit >= 0), -- half-days available may go below zero
  calendar_token TEXT NOT NULL UNIQUE CHECK (LENGTH(calendar_token) >= 32), -- random secret in the calendar feed URL (section 13)
  active BOOLEAN NOT NULL DEFAULT TRUE,
  CHECK (approver_id IS NULL OR approver_id <> id) -- never their own approver (R15)
);

-- A kind of leave, such as Annual leave or Sick leave.
CREATE TABLE leave_types (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL UNIQUE,
  code TEXT NOT NULL UNIQUE CHECK (LENGTH(code) = 2), -- shown on the calendar, e.g. AL
  color TEXT NOT NULL CHECK (color LIKE '#%'), -- hex, e.g. #2f7d6d
  counts_against_allowance BOOLEAN NOT NULL,
  needs_approval BOOLEAN NOT NULL, -- false: requests are approved straight away
  position INTEGER NOT NULL, -- display order
  active BOOLEAN NOT NULL -- inactive types can't be picked for new requests
);

-- A company public holiday. Never charged against the allowance.
CREATE TABLE public_holidays (
  id TEXT PRIMARY KEY,
  date DATE NOT NULL UNIQUE,
  name TEXT NOT NULL
);

-- One person's allowance for one leave year (the calendar year).
-- A missing row means entitlement = annual_allowance, carried_over 0, adjustment 0.
-- App rule (section 5): write a row only when something is saved for that year; viewing never creates one.
-- App rule (R7): balances are computed from requests every time; no running total is stored.
CREATE TABLE allowances (
  id TEXT PRIMARY KEY,
  person_id TEXT NOT NULL REFERENCES people(id),
  year INTEGER NOT NULL,
  entitlement INTEGER NOT NULL CHECK (entitlement >= 0), -- half-days
  carried_over INTEGER NOT NULL DEFAULT 0, -- half-days, may be negative; written only when the previous year is closed
  adjustment INTEGER NOT NULL DEFAULT 0, -- half-days, may be negative
  adjustment_note TEXT, -- required when adjustment is not 0
  UNIQUE (person_id, year),
  CHECK (adjustment = 0 OR (adjustment_note IS NOT NULL AND adjustment_note <> ''))
);

-- A closed leave year. A row means the year is closed and nothing in it may change (R14).
CREATE TABLE year_closes (
  year INTEGER PRIMARY KEY,
  carry_over_cap INTEGER NOT NULL CHECK (carry_over_cap >= 0), -- half-days; the cap used for this close
  closed_by TEXT NOT NULL REFERENCES people(id),
  closed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

-- One booking of leave. Never edited: to change dates, cancel and request again.
-- App rule (R2): end_date is in the same year as start_date, and year is that year.
-- App rule (section 8): status moves pending -> approved | declined | cancelled, approved -> cancelled; declined and cancelled are final.
-- App rule (R5, R8): save the request, its leave_days and its event in one transaction that locks the person's allowance row.
-- App rule (R12): days, the leave_days rows and counts_against_allowance are set once at creation.
CREATE TABLE requests (
  id TEXT PRIMARY KEY,
  person_id TEXT NOT NULL REFERENCES people(id), -- whose leave it is
  leave_type_id TEXT NOT NULL REFERENCES leave_types(id),
  year INTEGER NOT NULL, -- the year of start_date
  start_date DATE NOT NULL,
  start_half TEXT NOT NULL CHECK (start_half IN ('am', 'pm')), -- pm: first day is afternoon only
  end_date DATE NOT NULL,
  end_half TEXT NOT NULL CHECK (end_half IN ('am', 'pm')), -- am: last day is morning only
  days INTEGER NOT NULL CHECK (days > 0), -- half-days taken (section 6)
  counts_against_allowance BOOLEAN NOT NULL, -- copied from the leave type at creation
  status TEXT NOT NULL CHECK (status IN ('pending', 'approved', 'declined', 'cancelled')),
  note TEXT CHECK (note IS NULL OR LENGTH(note) <= 500), -- trimmed
  created_by TEXT NOT NULL REFERENCES people(id), -- the person, or the admin who recorded it
  decided_by TEXT REFERENCES people(id), -- set by approve and decline
  decided_at TIMESTAMP,
  decision_note TEXT, -- optional when approved; the reason when declined
  cancelled_by TEXT REFERENCES people(id),
  cancelled_at TIMESTAMP,
  cancel_reason TEXT, -- required when an admin cancels someone else's leave
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CHECK (end_date >= start_date), -- R2
  CHECK (NOT (start_date = end_date AND start_half = 'pm' AND end_half = 'am')), -- R3: one day can't run afternoon to morning
  CHECK (decided_by IS NULL OR decided_by <> person_id), -- R9: nobody decides their own request
  CHECK (status <> 'declined' OR (decided_by IS NOT NULL AND decided_at IS NOT NULL AND COALESCE(LENGTH(decision_note), 0) >= 3)), -- R10
  CHECK (status <> 'cancelled' OR (cancelled_by IS NOT NULL AND cancelled_at IS NOT NULL)),
  CHECK (status <> 'cancelled' OR cancelled_by = person_id OR COALESCE(LENGTH(cancel_reason), 0) >= 3) -- R11
);

CREATE INDEX requests_person_year ON requests (person_id, year);
CREATE INDEX requests_status ON requests (status);

-- One half-day session (am or pm) taken by a pending or approved request.
-- App rule (section 5): rows are written with the request and deleted when it is declined or cancelled.
CREATE TABLE leave_days (
  id TEXT PRIMARY KEY,
  request_id TEXT NOT NULL REFERENCES requests(id),
  person_id TEXT NOT NULL REFERENCES people(id), -- same as the request's person
  date DATE NOT NULL,
  half TEXT NOT NULL CHECK (half IN ('am', 'pm')),
  UNIQUE (person_id, date, half) -- makes double booking impossible (R5)
);

CREATE INDEX leave_days_date ON leave_days (date);
CREATE INDEX leave_days_request ON leave_days (request_id);

-- One entry in the history of a request or an allowance. Append-only.
-- App rule (R13): every request action and allowance change writes exactly one event; never updated or deleted.
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  request_id TEXT REFERENCES requests(id), -- null for allowance changes and carry-over
  person_id TEXT NOT NULL REFERENCES people(id), -- whose leave or allowance it is about
  actor_id TEXT REFERENCES people(id), -- null for system actions
  type TEXT NOT NULL CHECK (type IN ('requested', 'recorded', 'approved', 'declined', 'cancelled', 'allowance_changed', 'carried_over')),
  note TEXT,
  data TEXT, -- JSON text, e.g. old and new values for an allowance change
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX events_request ON events (request_id);
CREATE INDEX events_person ON events (person_id);

-- One email in the outbox, queued in the same transaction as the action that caused it.
-- App rule (section 11): queued and failed notifications are retried until they have had 5 attempts.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  person_id TEXT NOT NULL REFERENCES people(id), -- recipient
  request_id TEXT REFERENCES requests(id),
  kind TEXT NOT NULL CHECK (kind IN ('needs_approval', 'booked', 'recorded', 'approved', 'declined', 'cancelled', 'weekly_digest', 'year_closed')),
  subject TEXT NOT NULL,
  body TEXT NOT NULL,
  status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'sent', 'logged', 'failed')), -- logged: no email provider configured
  attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts >= 0),
  error TEXT,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  sent_at TIMESTAMP
);

CREATE INDEX notifications_status ON notifications (status);

-- One weekly digest run. The unique week_start stops a second run for the same week.
CREATE TABLE digest_runs (
  week_start DATE PRIMARY KEY, -- the Monday of the week the digest covers
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

Seed data

Loads section 15 in full: the Fernhill Studio settings row (cap 10 half-days), 3 teams, 7 people, 3 leave types, 8 public holidays, a 2026 and a 2027 allowance row for each person, the 18 requests, the 187 half-day leave_days rows that the pending and approved requests take, and the 34 history events their statuses imply. Times are 09:00 for requests and 10:00 for decisions in America/New_York, stored in UTC; the spec gives no time for the two cancellations, so they use 10:00 too. The spec gives no IDs or calendar tokens, so the seed uses readable placeholder IDs and placeholder tokens; replace the tokens before real use. The outbox, closed years and digest runs are empty because the spec seeds none.

Download pto-tracker-seed.sql (275 rows). It loads with foreign keys enforced on both engines.

Load it

SQLite, into a new file:

sqlite3
curl -s https://personalsoftwarefactory.com/schemas/pto-tracker.sql https://personalsoftwarefactory.com/schemas/pto-tracker-seed.sql | sqlite3 pto_tracker.db

PostgreSQL, into a new database:

psql
createdb pto_tracker && curl -s https://personalsoftwarefactory.com/schemas/pto-tracker.sql https://personalsoftwarefactory.com/schemas/pto-tracker-seed.sql | psql -v ON_ERROR_STOP=1 pto_tracker

SQLite only enforces foreign keys when the connection asks for it: run PRAGMA foreign_keys = ON; when your app opens the database.

Design decisions

Day amounts are integer half-days

Section 5 stores every day amount as an integer number of half-days: 1 day is 2, half a day is 1. Alex's Mon 21 to Thu 24 Dec request with a morning-only last day is stored as 7, not 3.5. Decimal days invite rounding errors in balance sums, and integers make the borrow limit and carry-over cap comparisons exact.

One row per half-day session blocks double booking

leave_days has a unique key on (person_id, date, half), as section 5 and R5 require. Two overlapping requests for the same person cannot both be saved, even if they arrive at the same moment, because the second insert fails. Rows exist only for pending and approved requests and are deleted on decline or cancel, so those never block a new booking.

Balances are computed, never stored

R7 and section 7 say balances are computed from the rows every time. allowances holds only entitlement, carried_over and adjustment; approved, pending and available are sums over requests. A running total that actions add to and subtract from drifts as soon as one action fails halfway, and then the person and the system disagree.

Allowance rows are written on save, never on view

From the build test · field report

When a year has no allowances row, the app uses the person's annual_allowance with zero carry-over and adjustment, and writes the row only when something is saved for that year (section 5). Our build test found that creating the row whenever a balance was needed meant just viewing last year created rows, which then blocked closing the current year; the spec now says viewing never writes.

Day counts are frozen on the request

requests stores days and counts_against_allowance at creation, copied from the day count and the leave type (R12). Adding a public holiday or changing someone's working days later does not change existing bookings. Without the copy, editing a holiday would silently change past balances.

Single-row decision rules are CHECK constraints

Rules that fit in one row are enforced by the database: nobody decides their own request (R9), a decline needs a reason of at least 3 characters (R10), an admin cancelling someone else's leave needs a reason of at least 3 characters (R11), and a one-day request cannot run from afternoon to morning (R3). The status transitions, the allowance limit (R8) and closed years (R14) span several rows and stay in the app, named in comments.

Working days are a short text list

Section 5 describes working_days as a list of ISO weekday numbers with a default of Monday to Friday and at least one day. A TEXT column such as '1,2,3,4' keeps that default and the at-least-one rule in the table, and the day count in section 6 reads the whole list at once. A child table would lose both rules to app code.

Example queries

The queries behind the tool's main screens. Each returned the same rows on both engines against the seed data.

Balances for a year, in half-days

SQL
SELECT
  p.name,
  a.entitlement + a.carried_over + a.adjustment AS total,
  COALESCE(SUM(CASE WHEN r.status = 'approved' THEN r.days END), 0) AS approved,
  COALESCE(SUM(CASE WHEN r.status = 'pending' THEN r.days END), 0) AS pending,
  a.entitlement + a.carried_over + a.adjustment - COALESCE(SUM(r.days), 0) AS available
FROM allowances a
JOIN people p ON p.id = a.person_id
LEFT JOIN requests r ON r.person_id = a.person_id AND r.year = a.year AND r.counts_against_allowance = TRUE AND r.status IN ('approved', 'pending')
WHERE a.year = 2026
GROUP BY p.name, a.entitlement, a.carried_over, a.adjustment
ORDER BY p.name;

On the seed data: 7 rows. Maya Rivera has total 40, approved 10, pending 10 and available 20 half-days (20, 5, 5 and 10 days); Priya Nair has available -2.

Who is out on a given day

SQL
SELECT DISTINCT p.name, t.name AS team, lt.name AS leave_type, r.start_date, r.end_date
FROM leave_days d
JOIN requests r ON r.id = d.request_id
JOIN people p ON p.id = d.person_id
JOIN teams t ON t.id = p.team_id
JOIN leave_types lt ON lt.id = r.leave_type_id
WHERE d.date = '2026-10-13' AND r.status = 'approved' AND p.active = TRUE
ORDER BY p.name;

On the seed data: 1 row, Tom Bennett, Design, Annual leave, 2026-10-13 to 2026-10-16.

Out next week, approved and pending listed apart

SQL
SELECT p.name, r.status, MIN(d.date) AS first_day, MAX(d.date) AS last_day
FROM leave_days d
JOIN requests r ON r.id = d.request_id
JOIN people p ON p.id = d.person_id
WHERE d.date >= '2026-10-19' AND d.date <= '2026-10-25' AND p.active = TRUE
GROUP BY p.name, r.id, r.status
ORDER BY r.status, p.name;

On the seed data: 2 rows. Jo Park approved for 2026-10-22 to 2026-10-23, and Maya Rivera pending for 2026-10-19 to 2026-10-23.

Requests waiting for one approver, oldest first

SQL
SELECT p.name, lt.name AS leave_type, r.start_date, r.end_date, r.days
FROM requests r
JOIN people p ON p.id = r.person_id
JOIN people ap ON ap.id = p.approver_id
JOIN leave_types lt ON lt.id = r.leave_type_id
WHERE r.status = 'pending' AND ap.id = 'person-alex' AND ap.active = TRUE AND r.person_id <> ap.id
ORDER BY r.created_at;

On the seed data: 2 rows for Alex Morgan, Rosa Quinn's 2027-01-04 to 2027-01-08 request first, then Maya Rivera's 2026-10-19 to 2026-10-23.

Year-end carry-over preview

SQL
SELECT
  b.name,
  b.remaining,
  CASE WHEN b.remaining <= 0 THEN b.remaining WHEN b.remaining < s.carry_over_cap THEN b.remaining ELSE s.carry_over_cap END AS carried,
  b.remaining - CASE WHEN b.remaining <= 0 THEN b.remaining WHEN b.remaining < s.carry_over_cap THEN b.remaining ELSE s.carry_over_cap END AS forfeited
FROM (SELECT p.name, a.entitlement + a.carried_over + a.adjustment - COALESCE(SUM(r.days), 0) AS remaining FROM allowances a JOIN people p ON p.id = a.person_id LEFT JOIN requests r ON r.person_id = a.person_id AND r.year = a.year AND r.counts_against_allowance = TRUE AND r.status IN ('approved', 'pending') WHERE a.year = 2026 AND p.active = TRUE GROUP BY p.name, a.entitlement, a.carried_over, a.adjustment) b
CROSS JOIN settings s
ORDER BY b.name;

On the seed data: 7 rows, matching the section 9 table in half-days. Rosa Quinn has 30 remaining, 10 carried and 20 forfeited; Priya Nair carries -2 (her borrowed day is paid back). The app refuses the actual close while any 2026 request is pending.

What was not tested

  • MySQL, MariaDB, SQL Server and Oracle. The file avoids engine-specific syntax, but it was not run on them.
  • Other versions of SQLite and PostgreSQL than the two named above.
  • PostgreSQL as a server. The PostgreSQL run used PGlite, which is PostgreSQL compiled to run in-process.
  • Production load. The check loads the seed rows and runs the example queries; it says nothing about performance with real volumes.
  • Migrations. This is a schema for a new database, not a path from an existing one.

The blueprint this schema comes from

Tables are the easy half. This schema is section 5 of the Time-Off Tracker blueprint, a free spec that also has the business rules, the screens, 4 phased build prompts and 32 acceptance checks for building the whole tool with an AI app builder. We built it from those prompts and the result passed 32 of 32 acceptance checks in a browser.

Follow new blueprints

Every new blueprint and build test appears in the feed and in the public GitHub repository. No account, no email list.