# Timesheet management system database schema

Source: https://personalsoftwarefactory.com/schemas/timesheets
Updated: 2026-12-04

> Nine tables. weeks holds one timesheet per person per Monday with its status, the approver fixed at submission and a version for stale-action checks; entries hold minutes in 15-minute steps on one project and date. Rates live on projects and are copied onto entries only when a week is approved, so later rate changes never change approved hours. Budget burn counts only submitted and approved weeks.

- 9 tables, 3 indexes
- Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite 0.6.1) on 2026-12-04
- 62 seed rows from the blueprint
- The blueprint's test build passed 21 of 21 acceptance checks

Files: [timesheets.sql](https://personalsoftwarefactory.com/schemas/timesheets.sql) · [timesheets-seed.sql](https://personalsoftwarefactory.com/schemas/timesheets-seed.sql) · [the Timesheets blueprint](https://personalsoftwarefactory.com/blueprints/timesheets)

## Relationships

- people.manager_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.
- projects.client_id references clients.id: each projects row points to at most one clients row, and one clients row can have many projects rows pointing to it.
- projects.owner_id references people.id: each projects row points to exactly one people row, and one people row can have many projects rows pointing to it.
- assignments.project_id references projects.id: each assignments row points to exactly one projects row, and one projects row can have many assignments rows pointing to it.
- assignments.person_id references people.id: each assignments row points to exactly one people row, and one people row can have many assignments rows pointing to it.
- weeks.person_id references people.id: each weeks row points to exactly one people row, and one people row can have many weeks rows pointing to it.
- weeks.approved_by references people.id: each weeks row points to at most one people row, and one people row can have many weeks rows pointing to it.
- weeks.approver_id references people.id: each weeks row points to at most one people row, and one people row can have many weeks rows pointing to it.
- entries.project_id references projects.id: each entries row points to exactly one projects row, and one projects row can have many entries rows pointing to it.
- entries.week_id, person_id references weeks.id, person_id: each entries row points to exactly one weeks row, and one weeks row can have many entries 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.
- events.week_id references weeks.id: each events row points to at most one weeks row, and one weeks row can have many events rows pointing to it.
- events.project_id references projects.id: each events row points to at most one projects row, and one projects row can have many events rows pointing to it.
- notifications.person_id references people.id: each notifications row points to at most one people row, and one people row can have many notifications rows pointing to it.

## Tables

Also described as: employee timesheet database design, time tracking database tables, timesheet approval data model.

### people

A person who logs time, with their manager, admin flag and weekly capacity. Implements: Person.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | Check: `length(name) BETWEEN 1 AND 80` |
| `email` | TEXT | no |  | Unique | stored lowercase Check: `email = lower(email)` |
| `manager_id` | TEXT | yes |  | References people.id | never themselves Check: `manager_id <> id` |
| `is_admin` | BOOLEAN | no | `FALSE` |  |  |
| `active` | BOOLEAN | no | `TRUE` |  |  |
| `weekly_capacity_minutes` | INTEGER | no | `2400` |  | 0 to 168 hours; only for the "under hours" note in reminders Check: `weekly_capacity_minutes BETWEEN 0 AND 10080` |

- App rule: no manager loops. App rule (R12): nobody deactivates themselves or the last active admin.

### settings

The one row with the company name, sign-in domain, time zone and reminder day and time. Implements: Settings.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | INTEGER | no |  | Primary key | Check: `id = 1` |
| `company_name` | TEXT | no |  |  |  |
| `email_domain` | TEXT | no |  |  | sign-in is limited to this domain |
| `time_zone` | TEXT | no | `'America/New_York'` |  | IANA name; weeks run Monday to Sunday in this zone |
| `reminder_weekday` | TEXT | no | `'Friday'` |  | Check: `reminder_weekday IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')` |
| `reminder_time` | TEXT | no | `'15:00'` |  | 24-hour HH:MM in the team time zone |

### clients

A client that projects belong to. Implements: Client.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  | Unique | Check: `length(name) BETWEEN 1 AND 80` |
| `archived` | BOOLEAN | no | `FALSE` |  |  |

### projects

A project with its owner, billable rate, optional budget and budget warning times. Implements: Project.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `client_id` | TEXT | yes |  | References clients.id | NULL for internal projects |
| `name` | TEXT | no |  |  | Check: `length(name) BETWEEN 1 AND 80` |
| `owner_id` | TEXT | no |  | References people.id | sees all hours and gets budget warnings |
| `billable` | BOOLEAN | no |  |  |  |
| `rate_cents` | INTEGER | yes |  |  | per hour, $0.00 to $1,000.00; NULL for non-billable projects Check: `rate_cents BETWEEN 0 AND 100000` |
| `budget_minutes` | INTEGER | yes |  |  | 0.25 h steps; NULL means no budget Check: `budget_minutes > 0 AND budget_minutes % 15 = 0` |
| `archived` | BOOLEAN | no | `FALSE` |  |  |
| `warned_80_at` | TIMESTAMP | yes |  |  | when the 80% budget warning went (R10) |
| `warned_100_at` | TIMESTAMP | yes |  |  | when the 100% budget warning went (R10) |

- Unique together: `client_id`, `name`
- Table check: `(billable = TRUE AND rate_cents IS NOT NULL) OR (billable = FALSE AND rate_cents IS NULL)`
- Unique index `projects_internal_name_unique` on (name) where `client_id IS NULL`
- App rule: owner_id must be an active person.

### assignments

A person allowed to log time to a project. Implements: Assignment.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `project_id` | TEXT | no |  | Primary key (part); References projects.id |  |
| `person_id` | TEXT | no |  | Primary key (part); References people.id |  |

### weeks

One person's timesheet for one Monday-to-Sunday week, from draft to approved. Implements: Week.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `person_id` | TEXT | no |  | References people.id |  |
| `week_start` | DATE | no |  |  | the Monday |
| `status` | TEXT | no | `'draft'` |  | Check: `status IN ('draft', 'submitted', 'approved')` |
| `submitted_at` | TIMESTAMP | yes |  |  |  |
| `approved_at` | TIMESTAMP | yes |  |  |  |
| `approved_by` | TEXT | yes |  | References people.id |  |
| `approver_id` | TEXT | yes |  | References people.id | the only person who can approve or reject this submission |
| `empty_note` | TEXT | yes |  |  | e.g. "On leave" Check: `length(empty_note) BETWEEN 5 AND 200` |
| `reminded_on` | DATE | yes |  |  | the date of the last reminder about this week (R11) |
| `version` | INTEGER | no | `1` |  | R13: up by 1 on every change to the week or its entries Check: `version >= 1` |

- Unique together: `person_id`, `week_start`
- Unique together: `id`, `person_id`
- Table check: `approver_id <> person_id`
- Table check: `(status = 'draft' AND submitted_at IS NULL AND approver_id IS NULL AND approved_at IS NULL AND approved_by IS NULL) OR (status = 'submitted' AND submitted_at IS NOT NULL AND approver_id IS NOT NULL AND approved_at IS NULL AND approved_by IS NULL) OR (status = 'approved' AND submitted_at IS NOT NULL AND approver_id IS NOT NULL AND approved_at IS NOT NULL AND approved_by IS NOT NULL)`
- App rule: week_start is always a Monday. App rule (R6): approver_id is set at submission and never the person.
- App rule: submitting a week with no entries needs empty_note.

### entries

Minutes on one project on one date, with the rate copied at approval. Implements: Entry.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `week_id` | TEXT | no |  |  |  |
| `person_id` | TEXT | no |  |  |  |
| `project_id` | TEXT | no |  | References projects.id |  |
| `date` | DATE | no |  |  |  |
| `minutes` | INTEGER | no |  |  | Check: `minutes BETWEEN 15 AND 1440 AND minutes % 15 = 0` |
| `note` | TEXT | yes |  |  | Check: `length(note) <= 300` |
| `rate_cents` | INTEGER | yes |  |  | copied from the project when the week is approved (R9); NULL before Check: `rate_cents BETWEEN 0 AND 100000` |

- Index `entries_project_date` on (project_id, date)
- App rule (R1): the total of a person for one date is at most 1,440 minutes, and dates cannot be after today.
- App rule (R4): date falls inside its week.

### events

One action kept for the activity log, never edited or deleted. Implements: Event.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `actor_id` | TEXT | yes |  | References people.id | NULL for the system |
| `week_id` | TEXT | yes |  | References weeks.id |  |
| `project_id` | TEXT | yes |  | References projects.id |  |
| `type` | TEXT | no |  |  | Check: `type IN ('entry_added', 'entry_edited', 'entry_deleted', 'submitted', 'withdrawn', 'approved', 'rejected', 'approval_withdrawn', 'budget_warning', 'reminded', 'project_changed', 'person_changed', 'client_changed', 'settings_changed', 'approver_reassigned')` |
| `data` | TEXT | no | `'{}'` |  | JSON stored as text |
| `created_at` | TIMESTAMP | no |  |  |  |

### notifications

One email in the outbox with its status and attempt count. Implements: Notification.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `kind` | TEXT | no |  |  |  |
| `to_email` | TEXT | no |  |  |  |
| `person_id` | TEXT | yes |  | References people.id |  |
| `subject` | TEXT | no |  |  |  |
| `body` | TEXT | no |  |  |  |
| `status` | TEXT | no | `'pending'` |  | Check: `status IN ('pending', 'sent', 'logged', 'failed')` |
| `error` | TEXT | yes |  |  |  |
| `attempts` | INTEGER | no | `0` |  | up to 3 attempts in all Check: `attempts BETWEEN 0 AND 3` |
| `created_at` | TIMESTAMP | no |  |  |  |
| `sent_at` | TIMESTAMP | yes |  |  |  |

- Index `notifications_status` on (status)

## The SQL

```sql
-- Timesheets database schema
-- Source: https://personalsoftwarefactory.com/blueprints/timesheets (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.

-- A person who logs time. manager_id is the approver of their weeks (R6).
-- App rule: no manager loops. App rule (R12): nobody deactivates themselves or the last active admin.
CREATE TABLE people (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (length(name) BETWEEN 1 AND 80),
  email TEXT NOT NULL UNIQUE CHECK (email = lower(email)), -- stored lowercase
  manager_id TEXT REFERENCES people(id) CHECK (manager_id <> id), -- never themselves
  is_admin BOOLEAN NOT NULL DEFAULT FALSE,
  active BOOLEAN NOT NULL DEFAULT TRUE,
  weekly_capacity_minutes INTEGER NOT NULL DEFAULT 2400 CHECK (weekly_capacity_minutes BETWEEN 0 AND 10080) -- 0 to 168 hours; only for the "under hours" note in reminders
);

-- The single settings row. id is fixed at 1 so the table can never hold a second row.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY CHECK (id = 1),
  company_name TEXT NOT NULL,
  email_domain TEXT NOT NULL, -- sign-in is limited to this domain
  time_zone TEXT NOT NULL DEFAULT 'America/New_York', -- IANA name; weeks run Monday to Sunday in this zone
  reminder_weekday TEXT NOT NULL DEFAULT 'Friday' CHECK (reminder_weekday IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')),
  reminder_time TEXT NOT NULL DEFAULT '15:00' -- 24-hour HH:MM in the team time zone
);

-- A client that projects bill to. Archiving a client archives its projects (R5).
CREATE TABLE clients (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL UNIQUE CHECK (length(name) BETWEEN 1 AND 80),
  archived BOOLEAN NOT NULL DEFAULT FALSE
);

-- A project people log time to. Internal projects have no client.
-- App rule: owner_id must be an active person.
CREATE TABLE projects (
  id TEXT PRIMARY KEY,
  client_id TEXT REFERENCES clients(id), -- NULL for internal projects
  name TEXT NOT NULL CHECK (length(name) BETWEEN 1 AND 80),
  owner_id TEXT NOT NULL REFERENCES people(id), -- sees all hours and gets budget warnings
  billable BOOLEAN NOT NULL,
  rate_cents INTEGER CHECK (rate_cents BETWEEN 0 AND 100000), -- per hour, $0.00 to $1,000.00; NULL for non-billable projects
  budget_minutes INTEGER CHECK (budget_minutes > 0 AND budget_minutes % 15 = 0), -- 0.25 h steps; NULL means no budget
  archived BOOLEAN NOT NULL DEFAULT FALSE,
  warned_80_at TIMESTAMP, -- when the 80% budget warning went (R10)
  warned_100_at TIMESTAMP, -- when the 100% budget warning went (R10)
  UNIQUE (client_id, name), -- unique within the client
  CHECK ((billable = TRUE AND rate_cents IS NOT NULL) OR (billable = FALSE AND rate_cents IS NULL))
);
CREATE UNIQUE INDEX projects_internal_name_unique ON projects (name) WHERE client_id IS NULL; -- unique among internal projects too

-- A person assigned to a project. Only assigned people can log time to it (R2).
CREATE TABLE assignments (
  project_id TEXT NOT NULL REFERENCES projects(id),
  person_id TEXT NOT NULL REFERENCES people(id),
  PRIMARY KEY (project_id, person_id)
);

-- The timesheet of one person for one week. A missing row means a draft week with no entries.
-- App rule: week_start is always a Monday. App rule (R6): approver_id is set at submission and never the person.
-- App rule: submitting a week with no entries needs empty_note.
CREATE TABLE weeks (
  id TEXT PRIMARY KEY,
  person_id TEXT NOT NULL REFERENCES people(id),
  week_start DATE NOT NULL, -- the Monday
  status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'submitted', 'approved')),
  submitted_at TIMESTAMP,
  approved_at TIMESTAMP,
  approved_by TEXT REFERENCES people(id),
  approver_id TEXT REFERENCES people(id), -- the only person who can approve or reject this submission
  empty_note TEXT CHECK (length(empty_note) BETWEEN 5 AND 200), -- e.g. "On leave"
  reminded_on DATE, -- the date of the last reminder about this week (R11)
  version INTEGER NOT NULL DEFAULT 1 CHECK (version >= 1), -- R13: up by 1 on every change to the week or its entries
  UNIQUE (person_id, week_start),
  UNIQUE (id, person_id), -- lets entries check that their person owns the week
  CHECK (approver_id <> person_id),
  CHECK ((status = 'draft' AND submitted_at IS NULL AND approver_id IS NULL AND approved_at IS NULL AND approved_by IS NULL)
      OR (status = 'submitted' AND submitted_at IS NOT NULL AND approver_id IS NOT NULL AND approved_at IS NULL AND approved_by IS NULL)
      OR (status = 'approved' AND submitted_at IS NOT NULL AND approver_id IS NOT NULL AND approved_at IS NOT NULL AND approved_by IS NOT NULL))
);

-- Time on one project on one day. Locked while its week is submitted or approved (R3).
-- App rule (R1): the total of a person for one date is at most 1,440 minutes, and dates cannot be after today.
-- App rule (R4): date falls inside its week.
CREATE TABLE entries (
  id TEXT PRIMARY KEY,
  week_id TEXT NOT NULL,
  person_id TEXT NOT NULL,
  project_id TEXT NOT NULL REFERENCES projects(id),
  date DATE NOT NULL,
  minutes INTEGER NOT NULL CHECK (minutes BETWEEN 15 AND 1440 AND minutes % 15 = 0),
  note TEXT CHECK (length(note) <= 300),
  rate_cents INTEGER CHECK (rate_cents BETWEEN 0 AND 100000), -- copied from the project when the week is approved (R9); NULL before
  FOREIGN KEY (week_id, person_id) REFERENCES weeks(id, person_id)
);
CREATE INDEX entries_project_date ON entries (project_id, date);

-- One action, kept for the activity log. Append-only (R14).
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  actor_id TEXT REFERENCES people(id), -- NULL for the system
  week_id TEXT REFERENCES weeks(id),
  project_id TEXT REFERENCES projects(id),
  type TEXT NOT NULL CHECK (type IN ('entry_added', 'entry_edited', 'entry_deleted', 'submitted', 'withdrawn', 'approved', 'rejected', 'approval_withdrawn', 'budget_warning', 'reminded', 'project_changed', 'person_changed', 'client_changed', 'settings_changed', 'approver_reassigned')),
  data TEXT NOT NULL DEFAULT '{}', -- JSON stored as text
  created_at TIMESTAMP NOT NULL
);

-- One email in the outbox. Written first, then sent; a failure never blocks the action.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  kind TEXT NOT NULL,
  to_email TEXT NOT NULL,
  person_id TEXT REFERENCES people(id),
  subject TEXT NOT NULL,
  body TEXT NOT NULL,
  status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'sent', 'logged', 'failed')),
  error TEXT,
  attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts BETWEEN 0 AND 3), -- up to 3 attempts in all
  created_at TIMESTAMP NOT NULL,
  sent_at TIMESTAMP
);
CREATE INDEX notifications_status ON notifications (status);
```

## Seed data

Loads section 14 as of Tue 13 Oct 2026: settings, 6 people, 2 clients, 3 projects, 12 assignments, 7 weeks and 31 entries, with Website redesign's 80% warning recorded as sent. Lee's week of Oct 5 is laid out exactly as given; the other weeks follow the stated rule (Monday to Friday, at most 8 h a day, projects in table order), which the Oct 5 example itself does not follow. No events or emails are loaded: the spec lists none.

## Load it

```sh
# SQLite
curl -s https://personalsoftwarefactory.com/schemas/timesheets.sql https://personalsoftwarefactory.com/schemas/timesheets-seed.sql | sqlite3 timesheets.db
# PostgreSQL
createdb timesheets && curl -s https://personalsoftwarefactory.com/schemas/timesheets.sql https://personalsoftwarefactory.com/schemas/timesheets-seed.sql | psql -v ON_ERROR_STOP=1 timesheets
```

## Design decisions

### Durations are integer minutes in 15-minute steps

entries.minutes is checked to 15 to 1,440 and a multiple of 15, as R1 says, and budgets are minutes in 0.25-hour steps (R8). Storing decimal hours would let 1.33 h through and make sums drift; the build test found the form also has to accept typed values, so the database is the last line that refuses 1:40. (This point comes from a gap the blueprint's build test found.)

### The rate is copied onto entries at approval

entries.rate_cents is NULL until the week is approved and then holds the project's rate at that moment (R9). Reports use the entry's rate when it is set and the project's current rate otherwise, so a rate change to $160 leaves Lee's approved week at $150. Withdrawing approval clears it again.

### Week status and its fields must agree

One CHECK ties status to submitted_at, approver_id, approved_at and approved_by: a draft has none, a submitted week has the first two, an approved week has all four. The build test found R13 never said what reject and withdraw clear; they now clear submitted_at and approver_id, and withdraw approval also clears approved_at and approved_by, which is what the CHECK expects. (This point comes from a gap the blueprint's build test found.)

### The approver is fixed at submission

weeks.approver_id is set when the week is submitted and is never the week's own person, enforced by a CHECK. The build test found it unclear whether a manager assigned later could decide a week; R6 now says only the approver recorded at submission can, so it is a column on the week, not a lookup of the current manager. (This point comes from a gap the blueprint's build test found.)

### Entries can't point at someone else's week

Entry has both week_id and person_id, so a composite foreign key from (week_id, person_id) to weeks(id, person_id) makes the two agree. Without it an entry could sit on Jo's week with Lee as its person, and R7's rule that nobody edits another person's entries would have nothing to stand on.

### Budget warnings are timestamps that never re-arm on their own

projects.warned_80_at and warned_100_at record when each warning went (R10). The build test found nothing said whether a warning can be sent again: rejections and withdrawals never re-arm it, and only changing budget_minutes clears a timestamp when burn under the new budget is below that level. (This point comes from a gap the blueprint's build test found.)

## Example queries

### Budget burn by project

```sql
SELECT COALESCE(c.name, 'Internal') AS client, p.name AS project, p.budget_minutes,
  COALESCE(SUM(CASE WHEN w.status IN ('submitted', 'approved') THEN e.minutes END), 0) AS used_minutes,
  COALESCE(SUM(CASE WHEN w.status = 'draft' THEN e.minutes END), 0) AS draft_minutes,
  CASE WHEN p.budget_minutes IS NULL THEN NULL
       ELSE COALESCE(SUM(CASE WHEN w.status IN ('submitted', 'approved') THEN e.minutes END), 0) * 100 / p.budget_minutes
  END AS burn_pct
FROM projects p
LEFT JOIN clients c ON c.id = p.client_id
LEFT JOIN entries e ON e.project_id = p.id
LEFT JOIN weeks w ON w.id = e.week_id
GROUP BY c.name, p.name, p.budget_minutes
ORDER BY client, project;
```

On the seed data: 3 rows; Acme Corp Website redesign has 5,760 minutes (96 h) used of 7,200, 80%, plus 360 draft minutes.

### Billable value of submitted and approved time

```sql
SELECT p.name AS project,
  SUM(e.minutes) AS billable_minutes,
  SUM((2 * e.minutes * COALESCE(e.rate_cents, p.rate_cents) + 60) / 120) AS value_cents
FROM entries e
JOIN weeks w ON w.id = e.week_id
JOIN projects p ON p.id = e.project_id
WHERE p.billable = TRUE AND w.status IN ('submitted', 'approved')
GROUP BY p.name
ORDER BY p.name;
```

On the seed data: 2 rows; Website redesign is 1,440,000 cents ($14,400.00) and Brand refresh 315,000 cents ($3,150.00).

### Approvals waiting for a manager

```sql
SELECT per.name AS person, w.week_start,
  COALESCE(SUM(e.minutes), 0) AS total_minutes,
  COALESCE(SUM(CASE WHEN p.billable = TRUE THEN e.minutes ELSE 0 END), 0) AS billable_minutes
FROM weeks w
JOIN people per ON per.id = w.person_id
JOIN people apr ON apr.id = w.approver_id
LEFT JOIN entries e ON e.week_id = w.id
LEFT JOIN projects p ON p.id = e.project_id
WHERE w.status = 'submitted' AND apr.email = 'maya@fernway.example'
GROUP BY per.name, w.week_start, w.submitted_at
ORDER BY w.submitted_at, per.name;
```

On the seed data, for Maya Chen: 1 row; Jo Park's week of 2026-10-05 with 2,280 minutes (38 h), 510 of them billable.

### Every timesheet with its status and total

```sql
SELECT per.name AS person, w.week_start, w.status,
  COALESCE(apr.name, '') AS approver,
  COALESCE(SUM(e.minutes), 0) AS total_minutes
FROM weeks w
JOIN people per ON per.id = w.person_id
LEFT JOIN people apr ON apr.id = w.approver_id
LEFT JOIN entries e ON e.week_id = w.id
GROUP BY per.name, w.week_start, w.status, apr.name
ORDER BY w.week_start, per.name;
```

On the seed data: 7 rows; Ben Cho's week of 2026-10-05 is a draft with 0 minutes.

### Approved entries export for a date range

```sql
SELECT e.date, COALESCE(c.name, 'Internal') AS client, p.name AS project, per.name AS person, e.minutes,
  e.rate_cents,
  CASE WHEN e.rate_cents IS NULL THEN NULL ELSE (2 * e.minutes * e.rate_cents + 60) / 120 END AS value_cents
FROM entries e
JOIN weeks w ON w.id = e.week_id
JOIN projects p ON p.id = e.project_id
LEFT JOIN clients c ON c.id = p.client_id
JOIN people per ON per.id = e.person_id
WHERE w.status = 'approved' AND e.date BETWEEN '2026-10-05' AND '2026-10-11'
ORDER BY e.date, client, project, person;
```

On the seed data, for 5 to 11 Oct 2026: 9 rows, all Lee Park's; the Website redesign entry on 2026-10-05 is 420 minutes worth 105,000 cents.

## 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 is section 5 of the [Timesheets blueprint](https://personalsoftwarefactory.com/blueprints/timesheets), which also has the business rules, the screens, the phased build prompts and the acceptance checks. Paste-ready spec: https://personalsoftwarefactory.com/blueprints/timesheets/blueprint.md
