# OKR software database schema

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

> Ten tables. Objectives belong to a cycle at company or team level, and key results store start, target and current values as integer hundredths, with CHECKs that make a lower-is-better target sit below its start and pin milestones to 0 and 100. Check-ins and target changes are append-only logs that keep their key result id without a foreign key, so history survives a deleted key result. Progress is computed, not stored, until a cycle closes and freezes it in basis points.

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

Files: [okr-tracker.sql](https://personalsoftwarefactory.com/schemas/okr-tracker.sql) · [okr-tracker-seed.sql](https://personalsoftwarefactory.com/schemas/okr-tracker-seed.sql) · [the OKR Tracker blueprint](https://personalsoftwarefactory.com/blueprints/okr-tracker)

## Relationships

- people.team_id references teams.id: each people row points to at most one teams row, and one teams row can have many people rows pointing to it.
- cycles.closed_by references people.id: each cycles row points to at most one people row, and one people row can have many cycles rows pointing to it.
- objectives.cycle_id references cycles.id: each objectives row points to exactly one cycles row, and one cycles row can have many objectives rows pointing to it.
- objectives.team_id references teams.id: each objectives row points to at most one teams row, and one teams row can have many objectives rows pointing to it.
- objectives.owner_id references people.id: each objectives row points to exactly one people row, and one people row can have many objectives rows pointing to it.
- objectives.aligned_to_id references objectives.id: each objectives row points to at most one another objectives row, and one objectives row can have many objectives rows pointing to it.
- objectives.carried_from_id references objectives.id: each objectives row points to at most one another objectives row, and one objectives row can have many objectives rows pointing to it.
- key_results.objective_id references objectives.id: each key_results row points to exactly one objectives row, and one objectives row can have many key_results rows pointing to it. On delete: cascade.
- key_results.owner_id references people.id: each key_results row points to exactly one people row, and one people row can have many key_results rows pointing to it.
- key_results.carried_from_id references key_results.id: each key_results row points to at most one another key_results row, and one key_results row can have many key_results rows pointing to it.
- check_ins.by_id references people.id: each check_ins row points to exactly one people row, and one people row can have many check_ins rows pointing to it.
- target_changes.by_id references people.id: each target_changes row points to exactly one people row, and one people row can have many target_changes rows pointing to it.
- events.actor 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.

## Tables

Also described as: objectives and key results database design, OKR tracking database tables, goal tracking schema.

### settings

The single row of company settings: domain, currency, time zone and reminder and summary schedule. Implements: Settings.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | INTEGER | no |  | Primary key | keeps this table to one row Check: `id = 1` |
| `company_name` | TEXT | no |  |  |  |
| `email_domain` | TEXT | no |  |  | sign-in is limited to this domain |
| `currency` | TEXT | no | `'USD'` |  | used by every currency key result |
| `time_zone` | TEXT | no | `'America/New_York'` |  | IANA name; days and job times are reckoned here |
| `reminder_day` | TEXT | no | `'Monday'` |  | Check: `reminder_day IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')` |
| `reminder_time` | TEXT | no | `'09:00'` |  | "HH:MM" company time |
| `summary_day` | TEXT | no | `'Friday'` |  | Check: `summary_day IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')` |
| `summary_time` | TEXT | no | `'16:00'` |  | "HH:MM" company time |

### teams

A team with an optional lead. Implements: Team.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | Check: `length(name) <= 100` |
| `lead_id` | TEXT | yes |  |  | a person id; no foreign key because people.team_id points back here (create order) |

- Unique index `teams_name_unique` on (lower(name)). Team names are unique ignoring case.
- App rule (section 4): deleted only when it has no people and no objectives.

### people

Someone who can sign in, an admin or a member, with an optional team. Implements: Person.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | Check: `length(name) <= 100` |
| `email` | TEXT | no |  | Unique | trimmed and lowercase |
| `role` | TEXT | no |  |  | Check: `role IN ('admin', 'member')` |
| `team_id` | TEXT | yes |  | References teams.id | optional |
| `active` | BOOLEAN | no | `TRUE` |  |  |

- Table check: `email = lower(email)`
- App rule (section 4): an admin cannot deactivate themselves; the last active admin cannot be demoted or deactivated.

### cycles

A goal-setting period, usually a quarter, in planning, active or closed. Implements: Cycle.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | such as "Q4 2026" Check: `length(name) BETWEEN 1 AND 50` |
| `starts_on` | DATE | no |  |  |  |
| `ends_on` | DATE | no |  |  |  |
| `status` | TEXT | no | `'planning'` |  | Check: `status IN ('planning', 'active', 'closed')` |
| `closed_at` | TIMESTAMP | yes |  |  |  |
| `closed_by` | TEXT | yes |  | References people.id |  |

- Table check: `ends_on > starts_on`
- Table check: `status <> 'closed' OR (closed_at IS NOT NULL AND closed_by IS NOT NULL)`
- Table check: `status <> 'planning' OR (closed_at IS NULL AND closed_by IS NULL)`
- Unique index `cycles_name_unique` on (lower(name)). Cycle names are unique ignoring case.
- Unique index `cycles_one_active` on (status) where `status = 'active'`. Only one active cycle at a time.
- App rule (section 7): cycle dates must not overlap another cycle (touching dates are fine).

### objectives

A company or team objective in a cycle, with its owner, alignment and final score. Implements: Objective.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `cycle_id` | TEXT | no |  | References cycles.id |  |
| `level` | TEXT | no |  |  | cannot change after creation Check: `level IN ('company', 'team')` |
| `team_id` | TEXT | yes |  | References teams.id | team level only; cannot change after creation |
| `title` | TEXT | no |  |  | Check: `length(title) <= 200` |
| `description` | TEXT | yes |  |  | Check: `length(description) <= 2000` |
| `owner_id` | TEXT | no |  | References people.id |  |
| `aligned_to_id` | TEXT | yes |  | References objectives.id | optional; no cascade, so a company objective with aligned team objectives cannot be deleted (R6) |
| `position` | INTEGER | no |  |  | order within its company or team list |
| `final_score_bp` | INTEGER | yes |  |  | set at close, basis points: 6875 shows as 0.7 Check: `final_score_bp BETWEEN 0 AND 10000` |
| `carried_from_id` | TEXT | yes |  | References objectives.id | the objective this one was copied from at a close (R7) |

- Table check: `(level = 'company' AND team_id IS NULL) OR (level = 'team' AND team_id IS NOT NULL)`
- Table check: `aligned_to_id IS NULL OR level = 'team'`
- App rule (R1): 1 to 5 key results; at most 5 objectives per team, and 5 for the company, per cycle.
- App rule (R6): aligned_to_id is a company objective in the same cycle.

### key_results

A measurable result of an objective, with start, target and current values in hundredths. Implements: KeyResult.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `objective_id` | TEXT | no |  | References objectives.id, on delete cascade |  |
| `title` | TEXT | no |  |  | free text; does not change when a target changes Check: `length(title) <= 200` |
| `owner_id` | TEXT | no |  | References people.id |  |
| `metric` | TEXT | no |  |  | Check: `metric IN ('number', 'percent', 'currency', 'milestone')` |
| `unit` | TEXT | yes |  |  | such as "hours"; optional for numbers, empty for percent, currency and milestones Check: `length(unit) <= 30` |
| `direction` | TEXT | no |  |  | Check: `direction IN ('increase', 'decrease')` |
| `start_x100` | INTEGER | no |  |  | hundredths; milestones store 0 |
| `target_x100` | INTEGER | no |  |  | hundredths; milestones store 100 |
| `current_x100` | INTEGER | no |  |  | hundredths; milestones store 0 or 100; a new key result starts at start_x100 |
| `confidence` | TEXT | yes |  |  | from the latest check-in; NULL until the first Check: `confidence IN ('on_track', 'at_risk', 'off_track')` |
| `last_check_in_at` | TIMESTAMP | yes |  |  |  |
| `final_progress_bp` | INTEGER | yes |  |  | set at close, basis points Check: `final_progress_bp BETWEEN 0 AND 10000` |
| `position` | INTEGER | no |  |  | order within its objective |
| `carried_from_id` | TEXT | yes |  | References key_results.id | the key result it was carried forward from (R7) |

- Table check: `unit IS NULL OR metric = 'number'`
- Table check: `metric <> 'milestone' OR (direction = 'increase' AND start_x100 = 0 AND target_x100 = 100 AND current_x100 IN (0, 100))`
- Table check: `metric <> 'percent' OR (start_x100 BETWEEN 0 AND 10000 AND target_x100 BETWEEN 0 AND 10000 AND current_x100 BETWEEN 0 AND 10000)`
- Table check: `(direction = 'increase' AND target_x100 > start_x100) OR (direction = 'decrease' AND target_x100 < start_x100)`
- Table check: `(confidence IS NULL) = (last_check_in_at IS NULL)`
- App rule (R2): the owner is active. App rule (section 13): the metric cannot change once check-ins exist.

### check_ins

One append-only check-in: a new value, a confidence and a comment. Implements: CheckIn.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `key_result_id` | TEXT | no |  |  | no foreign key: check-ins stay when their key result is deleted (R1) |
| `at` | TIMESTAMP | no |  |  |  |
| `by_id` | TEXT | no |  | References people.id |  |
| `value_x100` | INTEGER | no |  |  | hundredths; percent check-ins are 0 to 10000 (app rule, depends on the key result's metric) |
| `confidence` | TEXT | no |  |  | Check: `confidence IN ('on_track', 'at_risk', 'off_track')` |
| `comment` | TEXT | no |  |  | trimmed before it is stored Check: `length(comment) BETWEEN 3 AND 1000` |

- Index `check_ins_key_result` on (key_result_id, at)
- App rule (section 7): refused unless the cycle is active.

### target_changes

One append-only change to a key result's start or target in an active cycle, with its reason. Implements: TargetChange.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `key_result_id` | TEXT | no |  |  | no foreign key: target changes stay when their key result is deleted (R1) |
| `at` | TIMESTAMP | no |  |  |  |
| `by_id` | TEXT | no |  | References people.id |  |
| `field` | TEXT | no |  |  | Check: `field IN ('start', 'target')` |
| `old_x100` | INTEGER | no |  |  |  |
| `new_x100` | INTEGER | no |  |  |  |
| `reason` | TEXT | no |  |  | Check: `length(trim(reason)) BETWEEN 5 AND 300` |

### events

An append-only audit entry for a change. Implements: Event.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `at` | TIMESTAMP | no |  |  |  |
| `actor` | TEXT | yes |  | References people.id | NULL when the hourly job acted |
| `type` | TEXT | no |  |  |  |
| `data` | TEXT | yes |  |  | details as JSON text |

### notifications

An email in the outbox, written before it is sent, with its status. Implements: Notification.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `created_at` | TIMESTAMP | no |  |  |  |
| `kind` | TEXT | no |  |  | which email it is: one of the triggers in section 10 |
| `to_email` | TEXT | no |  |  |  |
| `subject` | TEXT | no |  |  |  |
| `body` | TEXT | no |  |  |  |
| `status` | TEXT | no | `'queued'` |  | logged when no provider is configured Check: `status IN ('queued', 'sent', 'failed', 'logged')` |
| `sent_at` | TIMESTAMP | yes |  |  |  |
| `error` | TEXT | yes |  |  |  |

## The SQL

```sql
-- OKR Tracker database schema
-- Source: https://personalsoftwarefactory.com/blueprints/okr-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.
-- Key result values are integer hundredths (8.5% is 850, $40,000 is 4000000). INTEGER is 4 bytes in PostgreSQL,
-- so a value must stay within about +/- 21.4 million units (2147483647 hundredths).

-- Company settings. Exactly one row.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY CHECK (id = 1), -- keeps this table to one row
  company_name TEXT NOT NULL,
  email_domain TEXT NOT NULL, -- sign-in is limited to this domain
  currency TEXT NOT NULL DEFAULT 'USD', -- used by every currency key result
  time_zone TEXT NOT NULL DEFAULT 'America/New_York', -- IANA name; days and job times are reckoned here
  reminder_day TEXT NOT NULL DEFAULT 'Monday' CHECK (reminder_day IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')),
  reminder_time TEXT NOT NULL DEFAULT '09:00', -- "HH:MM" company time
  summary_day TEXT NOT NULL DEFAULT 'Friday' CHECK (summary_day IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')),
  summary_time TEXT NOT NULL DEFAULT '16:00' -- "HH:MM" company time
);

-- A team. At most one lead, who need not be a member; a team may have no lead.
-- App rule (section 4): deleted only when it has no people and no objectives.
CREATE TABLE teams (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (length(name) <= 100),
  lead_id TEXT -- a person id; no foreign key because people.team_id points back here (create order)
);

-- Team names are unique ignoring case.
CREATE UNIQUE INDEX teams_name_unique ON teams (lower(name));

-- A person who can sign in. Team leads are found through teams.lead_id.
-- App rule (section 4): an admin cannot deactivate themselves; the last active admin cannot be demoted or deactivated.
CREATE TABLE people (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (length(name) <= 100),
  email TEXT NOT NULL UNIQUE, -- trimmed and lowercase
  role TEXT NOT NULL CHECK (role IN ('admin', 'member')),
  team_id TEXT REFERENCES teams(id), -- optional
  active BOOLEAN NOT NULL DEFAULT TRUE,
  CHECK (email = lower(email))
);

-- A goal-setting period, usually a calendar quarter. Cannot be edited or deleted in v1; closed cycles are read-only.
-- App rule (section 7): cycle dates must not overlap another cycle (touching dates are fine).
CREATE TABLE cycles (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (length(name) BETWEEN 1 AND 50), -- such as "Q4 2026"
  starts_on DATE NOT NULL,
  ends_on DATE NOT NULL,
  status TEXT NOT NULL DEFAULT 'planning' CHECK (status IN ('planning', 'active', 'closed')),
  closed_at TIMESTAMP,
  closed_by TEXT REFERENCES people(id),
  CHECK (ends_on > starts_on),
  CHECK (status <> 'closed' OR (closed_at IS NOT NULL AND closed_by IS NOT NULL)),
  CHECK (status <> 'planning' OR (closed_at IS NULL AND closed_by IS NULL))
);

-- Cycle names are unique ignoring case.
CREATE UNIQUE INDEX cycles_name_unique ON cycles (lower(name));
-- Only one active cycle at a time.
CREATE UNIQUE INDEX cycles_one_active ON cycles (status) WHERE status = 'active';

-- An objective in a cycle, for the company or for one team.
-- App rule (R1): 1 to 5 key results; at most 5 objectives per team, and 5 for the company, per cycle.
-- App rule (R6): aligned_to_id is a company objective in the same cycle.
CREATE TABLE objectives (
  id TEXT PRIMARY KEY,
  cycle_id TEXT NOT NULL REFERENCES cycles(id),
  level TEXT NOT NULL CHECK (level IN ('company', 'team')), -- cannot change after creation
  team_id TEXT REFERENCES teams(id), -- team level only; cannot change after creation
  title TEXT NOT NULL CHECK (length(title) <= 200),
  description TEXT CHECK (length(description) <= 2000),
  owner_id TEXT NOT NULL REFERENCES people(id),
  aligned_to_id TEXT REFERENCES objectives(id), -- optional; no cascade, so a company objective with aligned team objectives cannot be deleted (R6)
  position INTEGER NOT NULL, -- order within its company or team list
  final_score_bp INTEGER CHECK (final_score_bp BETWEEN 0 AND 10000), -- set at close, basis points: 6875 shows as 0.7
  carried_from_id TEXT REFERENCES objectives(id), -- the objective this one was copied from at a close (R7)
  CHECK ((level = 'company' AND team_id IS NULL) OR (level = 'team' AND team_id IS NOT NULL)),
  CHECK (aligned_to_id IS NULL OR level = 'team')
);

-- A measurable key result of an objective. Progress is computed, not stored (section 6), except final_progress_bp at close.
-- App rule (R2): the owner is active. App rule (section 13): the metric cannot change once check-ins exist.
CREATE TABLE key_results (
  id TEXT PRIMARY KEY,
  objective_id TEXT NOT NULL REFERENCES objectives(id) ON DELETE CASCADE,
  title TEXT NOT NULL CHECK (length(title) <= 200), -- free text; does not change when a target changes
  owner_id TEXT NOT NULL REFERENCES people(id),
  metric TEXT NOT NULL CHECK (metric IN ('number', 'percent', 'currency', 'milestone')),
  unit TEXT CHECK (length(unit) <= 30), -- such as "hours"; optional for numbers, empty for percent, currency and milestones
  direction TEXT NOT NULL CHECK (direction IN ('increase', 'decrease')),
  start_x100 INTEGER NOT NULL, -- hundredths; milestones store 0
  target_x100 INTEGER NOT NULL, -- hundredths; milestones store 100
  current_x100 INTEGER NOT NULL, -- hundredths; milestones store 0 or 100; a new key result starts at start_x100
  confidence TEXT CHECK (confidence IN ('on_track', 'at_risk', 'off_track')), -- from the latest check-in; NULL until the first
  last_check_in_at TIMESTAMP,
  final_progress_bp INTEGER CHECK (final_progress_bp BETWEEN 0 AND 10000), -- set at close, basis points
  position INTEGER NOT NULL, -- order within its objective
  carried_from_id TEXT REFERENCES key_results(id), -- the key result it was carried forward from (R7)
  CHECK (unit IS NULL OR metric = 'number'),
  CHECK (metric <> 'milestone' OR (direction = 'increase' AND start_x100 = 0 AND target_x100 = 100 AND current_x100 IN (0, 100))),
  CHECK (metric <> 'percent' OR (start_x100 BETWEEN 0 AND 10000 AND target_x100 BETWEEN 0 AND 10000 AND current_x100 BETWEEN 0 AND 10000)),
  -- R2 and section 13: the target differs from the start, in the key result's direction
  CHECK ((direction = 'increase' AND target_x100 > start_x100) OR (direction = 'decrease' AND target_x100 < start_x100)),
  CHECK ((confidence IS NULL) = (last_check_in_at IS NULL))
);

-- One check-in on a key result. Append-only (R4): sets the key result's current value, confidence and last_check_in_at.
-- App rule (section 7): refused unless the cycle is active.
CREATE TABLE check_ins (
  id TEXT PRIMARY KEY,
  key_result_id TEXT NOT NULL, -- no foreign key: check-ins stay when their key result is deleted (R1)
  at TIMESTAMP NOT NULL,
  by_id TEXT NOT NULL REFERENCES people(id),
  value_x100 INTEGER NOT NULL, -- hundredths; percent check-ins are 0 to 10000 (app rule, depends on the key result's metric)
  confidence TEXT NOT NULL CHECK (confidence IN ('on_track', 'at_risk', 'off_track')),
  comment TEXT NOT NULL CHECK (length(comment) BETWEEN 3 AND 1000) -- trimmed before it is stored
);

CREATE INDEX check_ins_key_result ON check_ins (key_result_id, at);

-- A change to a key result's start or target once its cycle is active (R5). Append-only.
CREATE TABLE target_changes (
  id TEXT PRIMARY KEY,
  key_result_id TEXT NOT NULL, -- no foreign key: target changes stay when their key result is deleted (R1)
  at TIMESTAMP NOT NULL,
  by_id TEXT NOT NULL REFERENCES people(id),
  field TEXT NOT NULL CHECK (field IN ('start', 'target')),
  old_x100 INTEGER NOT NULL,
  new_x100 INTEGER NOT NULL,
  reason TEXT NOT NULL CHECK (length(trim(reason)) BETWEEN 5 AND 300)
);

-- Audit log entry. Append-only (R10). A cycle reopen stores its reason here.
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  at TIMESTAMP NOT NULL,
  actor TEXT REFERENCES people(id), -- NULL when the hourly job acted
  type TEXT NOT NULL,
  data TEXT -- details as JSON text
);

-- An email in the outbox. Written here first, then sent. Failed emails stay failed in v1.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  created_at TIMESTAMP NOT NULL,
  kind TEXT NOT NULL, -- which email it is: one of the triggers in section 10
  to_email TEXT NOT NULL,
  subject TEXT NOT NULL,
  body TEXT NOT NULL,
  status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'sent', 'failed', 'logged')), -- logged when no provider is configured
  sent_at TIMESTAMP,
  error TEXT
);
```

## Seed data

Loads Fernway from section 14: the settings row, 3 teams, 6 people, the closed Q3 2026 and active Q4 2026 cycles, 6 objectives and 12 key results with their current values, confidence and Q3 final scores. Left out: the Q4 check-in history, because the spec says each key result has "two or three" check-ins with values stepping toward the current one and a one-line comment, without giving the count, values or comments; Q3's check-ins, which the spec does not describe (so Q3 key results have no confidence); and target changes, events and emails, which start empty. last_check_in_at is loaded from the spec's ages at 10:00 New York time: 9 days ago for the partner program page, 8 for help articles, and 2 days for the rest, which the spec gives as "1 or 2 days ago". Objectives have no description in the spec.

## Load it

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

## Design decisions

### Values are integer hundredths; milestones store 0 and 100

Section 3 stores key result values as integer hundredths and never as floats, so 8.5% is 850 and $40,000 is 4000000. The build test found that "milestones: 0 and 100" sat among fields stored in hundredths, so 100 could mean 1; the spec now says milestones store 0 and 100 literally, and a CHECK pins a milestone to start 0, target 100, current 0 or 100 and direction increase. INTEGER is 4 bytes in PostgreSQL, so values must stay within about 21.4 million units. (This point comes from a gap the blueprint's build test found.)

### The target must lie in the key result's direction

R2 needs a target different from the start, and section 13 refuses a lower-is-better key result whose target is above its start (and the reverse). One CHECK covers both: an increase needs target above start and a decrease needs target below start. With that, the single progress formula in section 6, (current - start) / (target - start), works for both directions.

### Check-ins and target changes outlive their key result

R1 lets objectives and key results be deleted while their check-ins, target changes and events stay. The build test found the spec had not said whether they could be deleted or what happened to their check-ins. A foreign key would block the delete or remove the history, so check_ins.key_result_id and target_changes.key_result_id are plain columns with an index. (This point comes from a gap the blueprint's build test found.)

### Final scores are stored in basis points at close

Progress is computed every time (section 6), but R7 freezes it when a cycle closes: final_progress_bp on each key result and final_score_bp on each objective. The build test found final_score had no stored unit; the spec now stores basis points (6875 shows as 0.7), and CHECKs keep both between 0 and 10000. (This point comes from a gap the blueprint's build test found.)

### Alignment is a self-reference that blocks deletes

A team objective may align to one company objective in the same cycle, and deleting a company objective that has aligned team objectives is refused (R6). aligned_to_id references objectives with no ON DELETE action, so the database refuses that delete by itself, and a CHECK allows alignment only on team objectives. "Same cycle" spans two rows and stays an app rule.

### One active cycle, unique names

Section 7 allows only one active cycle at a time and makes cycle names unique ignoring case, up to 50 characters. A partial unique index on cycles (status) WHERE status = 'active' and a unique index on lower(name) enforce both. Non-overlapping dates compare rows and stay in the app.

### A team's lead has no foreign key

people.team_id points to teams and teams.lead_id points to people, a true cycle. PostgreSQL cannot create a reference to a table that does not exist yet, so lead_id keeps the column without a foreign key, and the app checks it is an existing person. A lead need not be a member of the team (section 4).

## Example queries

### Key result progress, as whole percentages

```sql
SELECT o.title AS objective, k.title AS key_result, CASE WHEN (k.current_x100 - k.start_x100) * 1.0 / (k.target_x100 - k.start_x100) <= 0 THEN 0 WHEN (k.current_x100 - k.start_x100) * 1.0 / (k.target_x100 - k.start_x100) >= 1 THEN 100 ELSE ROUND(100.0 * (k.current_x100 - k.start_x100) / (k.target_x100 - k.start_x100)) END AS progress_pct FROM key_results k JOIN objectives o ON o.id = k.objective_id LEFT JOIN teams tm ON tm.id = o.team_id WHERE o.cycle_id = 'q4-2026' ORDER BY o.level, COALESCE(tm.name, ''), o.position, k.position;
```

On the seed data: 10 rows in OKRs-page order (company, then teams A to Z), from Increase trial-to-paid conversion at 25 to Publish 20 help articles at 100; median first response is 38 (37.5 rounded half up).

### Objective progress (plain average of exact key result progress)

```sql
SELECT o.title, ROUND(100.0 * AVG(CASE WHEN (k.current_x100 - k.start_x100) * 1.0 / (k.target_x100 - k.start_x100) <= 0 THEN 0 WHEN (k.current_x100 - k.start_x100) * 1.0 / (k.target_x100 - k.start_x100) >= 1 THEN 1 ELSE (k.current_x100 - k.start_x100) * 1.0 / (k.target_x100 - k.start_x100) END)) AS progress_pct FROM objectives o JOIN key_results k ON k.objective_id = o.id LEFT JOIN teams tm ON tm.id = o.team_id WHERE o.cycle_id = 'q4-2026' GROUP BY o.id, o.title, o.level, tm.name, o.position ORDER BY o.level, COALESCE(tm.name, ''), o.position;
```

On the seed data: 5 rows, matching section 14 (Grow revenue from self-serve customers 14, Keep customers longer 35, then the teams A to Z: Make the trial easier to start 70, Build a partner channel 15, Answer customers faster 69).

### Monday reminder: not checked in for 7 days or more (R8)

```sql
SELECT p.name AS owner, p.email, k.title FROM key_results k JOIN objectives o ON o.id = k.objective_id JOIN cycles c ON c.id = o.cycle_id JOIN people p ON p.id = k.owner_id WHERE c.status = 'active' AND (k.last_check_in_at IS NULL OR k.last_check_in_at < '2026-10-13 04:00:00') ORDER BY p.name, k.title;
```

On the seed data, for Monday Oct 19 (latest check-in dated Oct 12 or earlier in New York, so before 2026-10-13 04:00 UTC): 2 rows (Ben Ortiz, Launch the partner program page; Sam Lee, Publish 20 help articles).

### Alignment view

```sql
SELECT c.title AS company_objective, t.title AS team_objective, tm.name AS team FROM objectives c LEFT JOIN objectives t ON t.aligned_to_id = c.id LEFT JOIN teams tm ON tm.id = t.team_id WHERE c.level = 'company' AND c.cycle_id = 'q4-2026' ORDER BY c.position, tm.name;
```

On the seed data: 3 rows (Grow revenue from self-serve customers with Make the trial easier to start (Product) and Build a partner channel (Sales); Keep customers longer with Answer customers faster (Support)).

### Final scores of closed cycles

```sql
SELECT cy.name AS cycle, o.title AS objective, o.final_score_bp, k.title AS key_result, k.final_progress_bp FROM cycles cy JOIN objectives o ON o.cycle_id = cy.id JOIN key_results k ON k.objective_id = o.id WHERE cy.status = 'closed' ORDER BY cy.starts_on, o.position, k.position;
```

On the seed data: 2 rows for Q3 2026, Launch self-serve checkout at 8000 basis points (0.8): Ship checkout to all plans 10000, Reach 200 self-serve signups a month 6000.

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