# Client onboarding system database schema

Source: https://personalsoftwarefactory.com/schemas/client-onboarding-tracker
Updated: 2026-12-04

> Ten tables. projects and tasks carry the design: each project copies its template's tasks at creation, so later template edits never change it, and moves through kickoff, setup, training and live with every stage change recorded in handoffs. Progress, overdue counts and days in stage are computed from tasks and dates, never stored, and table CHECKs keep the hold, cancel, live and closed fields consistent with the status.

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

Files: [client-onboarding-tracker.sql](https://personalsoftwarefactory.com/schemas/client-onboarding-tracker.sql) · [client-onboarding-tracker-seed.sql](https://personalsoftwarefactory.com/schemas/client-onboarding-tracker-seed.sql) · [the Client Onboarding Tracker blueprint](https://personalsoftwarefactory.com/blueprints/client-onboarding-tracker)

## Relationships

- template_tasks.template_id references templates.id: each template_tasks row points to exactly one templates row, and one templates row can have many template_tasks rows pointing to it.
- template_tasks.default_owner_id references people.id: each template_tasks row points to at most one people row, and one people row can have many template_tasks rows pointing to it.
- projects.template_id references templates.id: each projects row points to exactly one templates row, and one templates 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.
- projects.created_by_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.
- tasks.project_id references projects.id: each tasks row points to exactly one projects row, and one projects row can have many tasks rows pointing to it.
- tasks.template_task_id references template_tasks.id: each tasks row points to at most one template_tasks row, and one template_tasks row can have many tasks rows pointing to it. On delete: set null.
- tasks.owner_id references people.id: each tasks row points to exactly one people row, and one people row can have many tasks rows pointing to it.
- tasks.closed_by_id references people.id: each tasks row points to at most one people row, and one people row can have many tasks rows pointing to it.
- handoffs.project_id references projects.id: each handoffs row points to exactly one projects row, and one projects row can have many handoffs rows pointing to it.
- handoffs.from_owner_id references people.id: each handoffs row points to exactly one people row, and one people row can have many handoffs rows pointing to it.
- handoffs.to_owner_id references people.id: each handoffs row points to exactly one people row, and one people row can have many handoffs rows pointing to it.
- handoffs.by_id references people.id: each handoffs row points to exactly one people row, and one people row can have many handoffs rows pointing to it.
- events.project_id references projects.id: each events row points to exactly one projects row, and one projects row can have many events rows pointing to it.
- events.task_id references tasks.id: each events row points to at most one tasks row, and one tasks 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.
- client_links.project_id references projects.id: each client_links row points to exactly one projects row, and one projects row can have many client_links rows pointing to it.
- client_links.created_by_id references people.id: each client_links row points to exactly one people row, and one people row can have many client_links 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.project_id references projects.id: each notifications row points to at most one projects row, and one projects row can have many notifications rows pointing to it.

## Tables

Also described as: customer onboarding tracker database design, client onboarding checklist tables, implementation project tracker schema.

### settings

The single row with the company name, team time zone and the last digest date. Implements: Settings.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | INTEGER | no |  | Primary key | one row only Check: `id = 1` |
| `company_name` | TEXT | no |  |  | shown on the client progress page Check: `LENGTH(company_name) BETWEEN 1 AND 100` |
| `time_zone` | TEXT | no | `'UTC'` |  | IANA name; "today" is the current date in this zone |
| `last_digest_on` | DATE | yes |  |  | set by the scheduled job |

### people

A team member who can own projects and tasks. Implements: Person.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | Check: `LENGTH(name) BETWEEN 1 AND 100` |
| `title` | TEXT | yes |  |  | optional, e.g. "Customer success lead" Check: `LENGTH(title) <= 100` |
| `email` | TEXT | no |  |  | Check: `LENGTH(email) <= 254` |
| `is_admin` | BOOLEAN | no | `FALSE` |  |  |
| `active` | BOOLEAN | no | `TRUE` |  |  |

- Unique index `people_email_uniq` on (LOWER(email))
- App rule (R16): people who own open tasks or projects that are active or on hold can't be deactivated; nobody deactivates themselves; the last active admin stays.

### templates

A reusable onboarding checklist. Implements: Template.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | Check: `LENGTH(name) BETWEEN 1 AND 80` |
| `description` | TEXT | yes |  |  | Check: `LENGTH(description) <= 500` |
| `active` | BOOLEAN | no | `TRUE` |  | inactive templates are hidden from New project |
| `created_at` | TIMESTAMP | no |  |  |  |
| `updated_at` | TIMESTAMP | no |  |  | compared at create time to refuse a stale preview (section 6) |

- Unique index `templates_name_uniq` on (LOWER(name))
- App rule (R10): a template starts projects only when it is active and has at least one task in each of kickoff, setup and training.

### template_tasks

One checklist item in a template, with its stage, default owner and day offset. Implements: TemplateTask.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `template_id` | TEXT | no |  | References templates.id |  |
| `stage` | TEXT | no |  |  | never live Check: `stage IN ('kickoff', 'setup', 'training')` |
| `position` | INTEGER | no |  |  | order within the stage |
| `title` | TEXT | no |  |  | Check: `LENGTH(title) BETWEEN 1 AND 160` |
| `description` | TEXT | yes |  |  | Check: `LENGTH(description) <= 1000` |
| `default_owner_id` | TEXT | yes |  | References people.id | empty means "the project owner" |
| `offset_days` | INTEGER | no |  |  | due this many calendar days after the start date Check: `offset_days BETWEEN 0 AND 365` |
| `visible_to_client` | BOOLEAN | no | `TRUE` |  | false marks the task Internal |

- Index `template_tasks_template_idx` on (template_id, stage, position)

### projects

One client engagement with its stage, status and current owner. Implements: Project.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `client_name` | TEXT | no |  |  | Check: `LENGTH(client_name) BETWEEN 1 AND 80` |
| `name` | TEXT | no |  |  | e.g. "Customer portal" Check: `LENGTH(name) BETWEEN 1 AND 100` |
| `template_id` | TEXT | no |  | References templates.id |  |
| `template_name` | TEXT | no |  |  | copy of the template's name at creation |
| `owner_id` | TEXT | no |  | References people.id | the current project owner |
| `created_by_id` | TEXT | no |  | References people.id |  |
| `start_date` | DATE | no |  |  |  |
| `stage` | TEXT | no |  |  | Check: `stage IN ('kickoff', 'setup', 'training', 'live')` |
| `status` | TEXT | no |  |  | a live project keeps status active Check: `status IN ('active', 'on_hold', 'cancelled')` |
| `stage_started_at` | TIMESTAMP | no |  |  | set at creation and at every handoff |
| `on_hold_since` | TIMESTAMP | yes |  |  | set while on hold, cleared on resume |
| `hold_reason` | TEXT | yes |  |  | Check: `LENGTH(hold_reason) BETWEEN 3 AND 1000` |
| `cancelled_at` | TIMESTAMP | yes |  |  |  |
| `cancel_reason` | TEXT | yes |  |  | Check: `LENGTH(cancel_reason) BETWEEN 3 AND 1000` |
| `live_at` | TIMESTAMP | yes |  |  | set by the handoff to live |
| `created_at` | TIMESTAMP | no |  |  |  |
| `updated_at` | TIMESTAMP | no |  |  |  |

- Table check: `(status = 'on_hold' AND on_hold_since IS NOT NULL AND hold_reason IS NOT NULL) OR (status <> 'on_hold' AND on_hold_since IS NULL AND hold_reason IS NULL)`
- Table check: `(status = 'cancelled' AND cancelled_at IS NOT NULL AND cancel_reason IS NOT NULL) OR (status <> 'cancelled' AND cancelled_at IS NULL AND cancel_reason IS NULL)`
- Table check: `(stage = 'live' AND live_at IS NOT NULL AND status = 'active') OR (stage <> 'live' AND live_at IS NULL)`
- Unique index `projects_client_name_uniq` on (LOWER(client_name), LOWER(name)) where `status <> 'cancelled'`
- Index `projects_owner_idx` on (owner_id)
- App rule (R3, R4): a handoff moves one stage forward, only when every task in the current stage is done or skipped.
- App rule (R5): live and cancelled are final; only comments (and, for live, the client link) change them.

### tasks

A project's copy of a template task, or a task added to one project. Implements: Task.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `project_id` | TEXT | no |  | References projects.id |  |
| `template_task_id` | TEXT | yes |  | References template_tasks.id, on delete set null | empty for tasks added by hand; cleared if the template task is removed |
| `stage` | TEXT | no |  |  | Check: `stage IN ('kickoff', 'setup', 'training')` |
| `position` | INTEGER | no |  |  | order within the stage |
| `title` | TEXT | no |  |  | Check: `LENGTH(title) BETWEEN 1 AND 160` |
| `description` | TEXT | yes |  |  | Check: `LENGTH(description) <= 1000` |
| `visible_to_client` | BOOLEAN | no |  |  |  |
| `owner_id` | TEXT | no |  | References people.id |  |
| `due_date` | DATE | no |  |  |  |
| `status` | TEXT | no |  |  | Check: `status IN ('open', 'done', 'skipped')` |
| `skip_reason` | TEXT | yes |  |  | required when skipped, cleared on unskip Check: `LENGTH(skip_reason) BETWEEN 3 AND 1000` |
| `closed_at` | TIMESTAMP | yes |  |  | set when done or skipped, cleared when reopened or unskipped |
| `closed_by_id` | TEXT | yes |  | References people.id |  |
| `created_at` | TIMESTAMP | no |  |  |  |
| `updated_at` | TIMESTAMP | no |  |  |  |

- Table check: `(status = 'skipped' AND skip_reason IS NOT NULL) OR (status <> 'skipped' AND skip_reason IS NULL)`
- Table check: `(status = 'open' AND closed_at IS NULL AND closed_by_id IS NULL) OR (status <> 'open' AND closed_at IS NOT NULL AND closed_by_id IS NOT NULL)`
- Index `tasks_project_idx` on (project_id, stage, position)
- Index `tasks_owner_idx` on (owner_id, status)
- App rule (R6): due_date is never before the project's start_date.
- App rule (R2): a task is completed or reopened only in the current stage of an active project.

### handoffs

One stage change in a project's history. Implements: Handoff.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `project_id` | TEXT | no |  | References projects.id |  |
| `from_stage` | TEXT | no |  |  | Check: `from_stage IN ('kickoff', 'setup', 'training')` |
| `to_stage` | TEXT | no |  |  | Check: `to_stage IN ('setup', 'training', 'live')` |
| `from_owner_id` | TEXT | no |  | References people.id |  |
| `to_owner_id` | TEXT | no |  | References people.id |  |
| `note` | TEXT | yes |  |  | optional Check: `LENGTH(note) <= 1000` |
| `by_id` | TEXT | no |  | References people.id |  |
| `created_at` | TIMESTAMP | no |  |  |  |

- Table check: `(from_stage = 'kickoff' AND to_stage = 'setup') OR (from_stage = 'setup' AND to_stage = 'training') OR (from_stage = 'training' AND to_stage = 'live')`
- Index `handoffs_created_idx` on (created_at)

### events

One append-only activity log entry. Implements: Event.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `project_id` | TEXT | no |  | References projects.id |  |
| `task_id` | TEXT | yes |  | References tasks.id |  |
| `actor_id` | TEXT | yes |  | References people.id | empty for system actions |
| `created_at` | TIMESTAMP | no |  |  |  |
| `type` | TEXT | no |  |  | Check: `type IN ('project_created', 'project_updated', 'owner_changed', 'task_added', 'task_updated', 'task_completed', 'task_reopened', 'task_skipped', 'task_unskipped', 'dates_shifted', 'handed_off', 'put_on_hold', 'resumed', 'cancelled', 'reassigned', 'commented', 'link_created', 'link_revoked')` |
| `comment` | TEXT | yes |  |  | comment text, handoff note, or skip, hold or cancel reason |
| `data` | TEXT | yes |  |  | JSON text, e.g. old and new due date, from and to owner, days shifted |

- Index `events_project_idx` on (project_id, created_at)

### client_links

A read-only progress link for the client, active until revoked. Implements: ClientLink.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `project_id` | TEXT | no |  | References projects.id |  |
| `token` | TEXT | no |  | Unique | at least 128 random bits, URL-safe; never logged |
| `created_by_id` | TEXT | no |  | References people.id |  |
| `created_at` | TIMESTAMP | no |  |  |  |
| `revoked_at` | TIMESTAMP | yes |  |  |  |
| `last_viewed_at` | TIMESTAMP | yes |  |  |  |

- Unique index `client_links_one_active` on (project_id) where `revoked_at IS NULL`
- App rule (section 12): the link stops working when revoked, when the project is cancelled, or more than 30 days after go-live.

### notifications

One outgoing email in the outbox. Implements: Notification.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `person_id` | TEXT | no |  | References people.id |  |
| `project_id` | TEXT | yes |  | References projects.id | empty for digests |
| `subject` | TEXT | no |  |  |  |
| `body` | TEXT | no |  |  |  |
| `kind` | TEXT | no |  |  | Check: `kind IN ('project_created', 'stage_started', 'handed_off', 'owner_changed', 'task_assigned', 'went_live', 'on_hold', 'resumed', 'cancelled', 'commented', 'digest')` |
| `status` | TEXT | no | `'queued'` |  | logged = no email provider configured Check: `status IN ('queued', 'sent', 'logged', 'failed')` |
| `attempts` | INTEGER | no | `0` |  | up to 5 attempts in total Check: `attempts BETWEEN 0 AND 5` |
| `created_at` | TIMESTAMP | no |  |  |  |
| `sent_at` | TIMESTAMP | yes |  |  |  |
| `error` | TEXT | yes |  |  |  |

- Index `notifications_status_idx` on (status, created_at)

## The SQL

```sql
-- Client Onboarding Tracker database schema
-- Source: https://personalsoftwarefactory.com/blueprints/client-onboarding-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.

-- The single settings row.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY CHECK (id = 1), -- one row only
  company_name TEXT NOT NULL CHECK (LENGTH(company_name) BETWEEN 1 AND 100), -- shown on the client progress page
  time_zone TEXT NOT NULL DEFAULT 'UTC', -- IANA name; "today" is the current date in this zone
  last_digest_on DATE -- set by the scheduled job
);

-- A team member who can own projects and tasks. Deactivated, never deleted.
-- App rule (R16): people who own open tasks or projects that are active or on hold can't be deactivated; nobody deactivates themselves; the last active admin stays.
CREATE TABLE people (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 1 AND 100),
  title TEXT CHECK (LENGTH(title) <= 100), -- optional, e.g. "Customer success lead"
  email TEXT NOT NULL CHECK (LENGTH(email) <= 254),
  is_admin BOOLEAN NOT NULL DEFAULT FALSE,
  active BOOLEAN NOT NULL DEFAULT TRUE
);
CREATE UNIQUE INDEX people_email_uniq ON people (LOWER(email)); -- unique, compared case-insensitively

-- A reusable onboarding checklist. Editing it never changes existing projects (R9).
-- App rule (R10): a template starts projects only when it is active and has at least one task in each of kickoff, setup and training.
CREATE TABLE templates (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 1 AND 80),
  description TEXT CHECK (LENGTH(description) <= 500),
  active BOOLEAN NOT NULL DEFAULT TRUE, -- inactive templates are hidden from New project
  created_at TIMESTAMP NOT NULL,
  updated_at TIMESTAMP NOT NULL -- compared at create time to refuse a stale preview (section 6)
);
CREATE UNIQUE INDEX templates_name_uniq ON templates (LOWER(name)); -- unique case-insensitively

-- One checklist item in a template.
CREATE TABLE template_tasks (
  id TEXT PRIMARY KEY,
  template_id TEXT NOT NULL REFERENCES templates(id),
  stage TEXT NOT NULL CHECK (stage IN ('kickoff', 'setup', 'training')), -- never live
  position INTEGER NOT NULL, -- order within the stage
  title TEXT NOT NULL CHECK (LENGTH(title) BETWEEN 1 AND 160),
  description TEXT CHECK (LENGTH(description) <= 1000),
  default_owner_id TEXT REFERENCES people(id), -- empty means "the project owner"
  offset_days INTEGER NOT NULL CHECK (offset_days BETWEEN 0 AND 365), -- due this many calendar days after the start date
  visible_to_client BOOLEAN NOT NULL DEFAULT TRUE -- false marks the task Internal
);
CREATE INDEX template_tasks_template_idx ON template_tasks (template_id, stage, position);

-- One client engagement moving through kickoff, setup, training and live.
-- App rule (R3, R4): a handoff moves one stage forward, only when every task in the current stage is done or skipped.
-- App rule (R5): live and cancelled are final; only comments (and, for live, the client link) change them.
CREATE TABLE projects (
  id TEXT PRIMARY KEY,
  client_name TEXT NOT NULL CHECK (LENGTH(client_name) BETWEEN 1 AND 80),
  name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 1 AND 100), -- e.g. "Customer portal"
  template_id TEXT NOT NULL REFERENCES templates(id),
  template_name TEXT NOT NULL, -- copy of the template's name at creation
  owner_id TEXT NOT NULL REFERENCES people(id), -- the current project owner
  created_by_id TEXT NOT NULL REFERENCES people(id),
  start_date DATE NOT NULL,
  stage TEXT NOT NULL CHECK (stage IN ('kickoff', 'setup', 'training', 'live')),
  status TEXT NOT NULL CHECK (status IN ('active', 'on_hold', 'cancelled')), -- a live project keeps status active
  stage_started_at TIMESTAMP NOT NULL, -- set at creation and at every handoff
  on_hold_since TIMESTAMP, -- set while on hold, cleared on resume
  hold_reason TEXT CHECK (LENGTH(hold_reason) BETWEEN 3 AND 1000),
  cancelled_at TIMESTAMP,
  cancel_reason TEXT CHECK (LENGTH(cancel_reason) BETWEEN 3 AND 1000),
  live_at TIMESTAMP, -- set by the handoff to live
  created_at TIMESTAMP NOT NULL,
  updated_at TIMESTAMP NOT NULL,
  CHECK ((status = 'on_hold' AND on_hold_since IS NOT NULL AND hold_reason IS NOT NULL) OR (status <> 'on_hold' AND on_hold_since IS NULL AND hold_reason IS NULL)),
  CHECK ((status = 'cancelled' AND cancelled_at IS NOT NULL AND cancel_reason IS NOT NULL) OR (status <> 'cancelled' AND cancelled_at IS NULL AND cancel_reason IS NULL)),
  CHECK ((stage = 'live' AND live_at IS NOT NULL AND status = 'active') OR (stage <> 'live' AND live_at IS NULL))
);
CREATE UNIQUE INDEX projects_client_name_uniq ON projects (LOWER(client_name), LOWER(name)) WHERE status <> 'cancelled'; -- unique among projects that are not cancelled
CREATE INDEX projects_owner_idx ON projects (owner_id);

-- A project's copy of a template task, or a task added to one project. Never deleted; skipped instead (R11).
-- App rule (R6): due_date is never before the project's start_date.
-- App rule (R2): a task is completed or reopened only in the current stage of an active project.
CREATE TABLE tasks (
  id TEXT PRIMARY KEY,
  project_id TEXT NOT NULL REFERENCES projects(id),
  template_task_id TEXT REFERENCES template_tasks(id) ON DELETE SET NULL, -- empty for tasks added by hand; cleared if the template task is removed
  stage TEXT NOT NULL CHECK (stage IN ('kickoff', 'setup', 'training')),
  position INTEGER NOT NULL, -- order within the stage
  title TEXT NOT NULL CHECK (LENGTH(title) BETWEEN 1 AND 160),
  description TEXT CHECK (LENGTH(description) <= 1000),
  visible_to_client BOOLEAN NOT NULL,
  owner_id TEXT NOT NULL REFERENCES people(id),
  due_date DATE NOT NULL,
  status TEXT NOT NULL CHECK (status IN ('open', 'done', 'skipped')),
  skip_reason TEXT CHECK (LENGTH(skip_reason) BETWEEN 3 AND 1000), -- required when skipped, cleared on unskip
  closed_at TIMESTAMP, -- set when done or skipped, cleared when reopened or unskipped
  closed_by_id TEXT REFERENCES people(id),
  created_at TIMESTAMP NOT NULL,
  updated_at TIMESTAMP NOT NULL,
  CHECK ((status = 'skipped' AND skip_reason IS NOT NULL) OR (status <> 'skipped' AND skip_reason IS NULL)),
  CHECK ((status = 'open' AND closed_at IS NULL AND closed_by_id IS NULL) OR (status <> 'open' AND closed_at IS NOT NULL AND closed_by_id IS NOT NULL))
);
CREATE INDEX tasks_project_idx ON tasks (project_id, stage, position);
CREATE INDEX tasks_owner_idx ON tasks (owner_id, status);

-- One stage change in a project's history.
CREATE TABLE handoffs (
  id TEXT PRIMARY KEY,
  project_id TEXT NOT NULL REFERENCES projects(id),
  from_stage TEXT NOT NULL CHECK (from_stage IN ('kickoff', 'setup', 'training')),
  to_stage TEXT NOT NULL CHECK (to_stage IN ('setup', 'training', 'live')),
  from_owner_id TEXT NOT NULL REFERENCES people(id),
  to_owner_id TEXT NOT NULL REFERENCES people(id),
  note TEXT CHECK (LENGTH(note) <= 1000), -- optional
  by_id TEXT NOT NULL REFERENCES people(id),
  created_at TIMESTAMP NOT NULL,
  CHECK ((from_stage = 'kickoff' AND to_stage = 'setup') OR (from_stage = 'setup' AND to_stage = 'training') OR (from_stage = 'training' AND to_stage = 'live')) -- R4: exactly one stage forward
);
CREATE INDEX handoffs_created_idx ON handoffs (created_at);

-- One activity log entry. Append-only: never updated or deleted (R14).
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  project_id TEXT NOT NULL REFERENCES projects(id),
  task_id TEXT REFERENCES tasks(id),
  actor_id TEXT REFERENCES people(id), -- empty for system actions
  created_at TIMESTAMP NOT NULL,
  type TEXT NOT NULL CHECK (type IN ('project_created', 'project_updated', 'owner_changed', 'task_added', 'task_updated', 'task_completed', 'task_reopened', 'task_skipped', 'task_unskipped', 'dates_shifted', 'handed_off', 'put_on_hold', 'resumed', 'cancelled', 'reassigned', 'commented', 'link_created', 'link_revoked')),
  comment TEXT, -- comment text, handoff note, or skip, hold or cancel reason
  data TEXT -- JSON text, e.g. old and new due date, from and to owner, days shifted
);
CREATE INDEX events_project_idx ON events (project_id, created_at);

-- A read-only progress link for the client. Views set last_viewed_at and write no event.
-- App rule (section 12): the link stops working when revoked, when the project is cancelled, or more than 30 days after go-live.
CREATE TABLE client_links (
  id TEXT PRIMARY KEY,
  project_id TEXT NOT NULL REFERENCES projects(id),
  token TEXT NOT NULL UNIQUE, -- at least 128 random bits, URL-safe; never logged
  created_by_id TEXT NOT NULL REFERENCES people(id),
  created_at TIMESTAMP NOT NULL,
  revoked_at TIMESTAMP,
  last_viewed_at TIMESTAMP
);
CREATE UNIQUE INDEX client_links_one_active ON client_links (project_id) WHERE revoked_at IS NULL; -- one active link per project

-- One outgoing email in the outbox.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  person_id TEXT NOT NULL REFERENCES people(id),
  project_id TEXT REFERENCES projects(id), -- empty for digests
  subject TEXT NOT NULL,
  body TEXT NOT NULL,
  kind TEXT NOT NULL CHECK (kind IN ('project_created', 'stage_started', 'handed_off', 'owner_changed', 'task_assigned', 'went_live', 'on_hold', 'resumed', 'cancelled', 'commented', 'digest')),
  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 BETWEEN 0 AND 5), -- up to 5 attempts in total
  created_at TIMESTAMP NOT NULL,
  sent_at TIMESTAMP,
  error TEXT
);
CREATE INDEX notifications_status_idx ON notifications (status, created_at);
```

## Seed data

Loads section 15 as on 2026-10-13, the date the spec's examples use: the settings row, 7 people, 2 templates with 7 template tasks, 4 projects with 24 tasks, 6 handoffs and 22 events (4 project_created, 12 task_completed, 6 handed_off). Left out: Sam's comment on Bluebird and its commented event, because the spec gives the day but no time. The spec gives no template creation time, so both templates use the first project's creation time. No client links or notifications, as the spec says.

## Load it

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

## Design decisions

### Projects copy their template

R9 says creating a project copies the template's tasks and stores the template's name, and editing a template never changes existing projects. tasks keep their own stage, position, title, description and visibility, and projects.template_name keeps the name at creation. template_task_id is only a back-reference, set to NULL if that template task is later removed.

### A handoff moves exactly one stage

R4 says a handoff moves one stage forward and never skips or moves back. handoffs has a CHECK that allows only kickoff to setup, setup to training and training to live. The gate itself (every task in the current stage done or skipped, R3) spans rows, so it stays in the app, checked in the same transaction as the stage change.

### Status fields are tied together with CHECKs

on_hold_since and hold_reason are set exactly when a project is on hold, cancelled_at and cancel_reason exactly when it is cancelled, and live_at exactly when the stage is live, which also requires status active (section 8 makes live final). On tasks, skip_reason is set only when skipped (R12) and closed_at and closed_by_id only when done or skipped. Reasons are 3 to 1,000 characters, a limit the build test found missing from section 5. (This point comes from a gap the blueprint's build test found.)

### Names are unique among projects that are not cancelled

Section 5 makes (client_name, name) unique, case-insensitively, among projects that are not cancelled. A partial unique index on LOWER(client_name), LOWER(name) WHERE status <> 'cancelled' does exactly that, so a cancelled project's name can be reused. Template names and person emails use the same LOWER() unique index.

### Progress and overdue are never stored

Section 5 says progress, overdue counts and days in stage are computed from tasks and dates. Progress is (done + skipped) / all tasks rounded half up (R8), which integer SQL can do as (200 * closed + total) / (2 * total). Storing these would go stale every midnight in the team time zone, when tasks become overdue without any write.

### One active client link per project

Section 12 allows one active link per project; replacing a link revokes the old one. A partial unique index on project_id WHERE revoked_at IS NULL enforces it while keeping revoked links for the record. The token is UNIQUE and at least 128 random bits.

## Example queries

### Board cards with progress and overdue

```sql
SELECT p.client_name, p.name, p.stage, o.name AS owner, SUM(CASE WHEN t.status IN ('done', 'skipped') THEN 1 ELSE 0 END) AS closed, COUNT(t.id) AS total, CASE WHEN COUNT(t.id) = 0 THEN 0 ELSE (200 * SUM(CASE WHEN t.status IN ('done', 'skipped') THEN 1 ELSE 0 END) + COUNT(t.id)) / (2 * COUNT(t.id)) END AS progress_percent, SUM(CASE WHEN t.status = 'open' AND p.status = 'active' AND t.due_date < '2026-10-13' THEN 1 ELSE 0 END) AS overdue FROM projects p JOIN people o ON o.id = p.owner_id LEFT JOIN tasks t ON t.project_id = p.id WHERE p.status <> 'cancelled' GROUP BY p.id, p.client_name, p.name, p.stage, o.name, p.stage_started_at ORDER BY CASE p.stage WHEN 'kickoff' THEN 1 WHEN 'setup' THEN 2 WHEN 'training' THEN 3 ELSE 4 END, overdue DESC, p.stage_started_at, p.client_name, p.name;
```

On the seed data on 2026-10-13: 4 rows, matching section 7's worked example, for example Bluebird, Analytics rollout, setup, 2 of 6, 33%, 2 overdue.

### Board header counts

```sql
SELECT (SELECT COUNT(*) FROM projects WHERE stage <> 'live' AND status <> 'cancelled') AS in_progress, (SELECT COUNT(*) FROM tasks t JOIN projects p ON p.id = t.project_id WHERE t.status = 'open' AND p.status = 'active' AND t.due_date < '2026-10-13') AS overdue_tasks;
```

On the seed data: 1 row, 3 in progress and 4 overdue tasks.

### My tasks for Maya Chen

```sql
SELECT CASE WHEN p.status = 'on_hold' THEN 'paused' WHEN t.stage <> p.stage THEN 'waiting for an earlier stage' WHEN t.due_date < '2026-10-13' THEN 'overdue' WHEN t.due_date = '2026-10-13' THEN 'due today' WHEN t.due_date <= '2026-10-20' THEN 'next 7 days' ELSE 'later' END AS task_group, t.title, p.client_name, t.due_date FROM tasks t JOIN projects p ON p.id = t.project_id WHERE t.owner_id = 'person_maya' AND t.status = 'open' AND p.stage <> 'live' AND p.status <> 'cancelled' ORDER BY CASE WHEN p.status = 'on_hold' THEN 6 WHEN t.stage <> p.stage THEN 5 WHEN t.due_date < '2026-10-13' THEN 1 WHEN t.due_date = '2026-10-13' THEN 2 WHEN t.due_date <= '2026-10-20' THEN 3 ELSE 4 END, t.due_date, p.client_name;
```

On the seed data: 4 rows, Run kickoff workshop at Northwind overdue, Train client champions at Harbor Studio due today, and two later-stage Train client champions tasks waiting.

### Handoffs, newest first

```sql
SELECT h.created_at, p.client_name, p.name, h.from_stage, h.to_stage, f.name AS from_owner, n.name AS to_owner, b.name AS handed_off_by FROM handoffs h JOIN projects p ON p.id = h.project_id JOIN people f ON f.id = h.from_owner_id JOIN people n ON n.id = h.to_owner_id JOIN people b ON b.id = h.by_id ORDER BY h.created_at DESC;
```

On the seed data: 6 rows, newest Harbor Studio setup to training, Sam Okafor to Maya Chen, on 2026-10-10.

### What the client progress page may show

```sql
SELECT t.stage, t.title, o.name AS owner, t.status, t.due_date FROM tasks t JOIN people o ON o.id = t.owner_id WHERE t.project_id = 'project_bluebird' AND t.visible_to_client = TRUE ORDER BY CASE t.stage WHEN 'kickoff' THEN 1 WHEN 'setup' THEN 2 ELSE 3 END, t.position;
```

On the seed data: 5 rows for Bluebird, 2 of them done; the Internal task Verify access and permissions is not selected. The page shows only the owner's first name.

## 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 [Client Onboarding Tracker blueprint](https://personalsoftwarefactory.com/blueprints/client-onboarding-tracker), which also has the business rules, the screens, the phased build prompts and the acceptance checks. Paste-ready spec: https://personalsoftwarefactory.com/blueprints/client-onboarding-tracker/blueprint.md
