Contract management system database schema
Nine tables. contracts carries the design: the current term's dates, the renewal and notice settings, and a decision whose consistency with the status is enforced by CHECKs (ending only with cancel, cancel only with a notice date and a note, late notice only on an auto-renewing cancel). Past terms live in an append-only terms table, and reminders_sent is keyed on contract, kind, days before and key date, so the daily job can run twice without sending a reminder twice. The notice deadline is computed from end_date and notice_days, never stored.
- 9 tables, 6 indexes
- Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite 0.6.1),
- 28 seed rows from the blueprint
- The blueprint's test build passed 15 of 15 acceptance checks
Contract tracker entity-relationship diagram
Relationships
- contracts.counterparty_id references counterparties.id: each contracts row points to exactly one counterparties row, and one counterparties row can have many contracts rows pointing to it.
- contracts.owner_id references people.id: each contracts row points to exactly one people row, and one people row can have many contracts rows pointing to it.
- documents.contract_id references contracts.id: each documents row points to exactly one contracts row, and one contracts row can have many documents rows pointing to it. On delete: cascade.
- documents.uploaded_by references people.id: each documents row points to exactly one people row, and one people row can have many documents rows pointing to it.
- reminders_sent.contract_id references contracts.id: each reminders_sent row points to exactly one contracts row, and one contracts row can have many reminders_sent rows pointing to it. On delete: cascade.
- terms.contract_id references contracts.id: each terms row points to exactly one contracts row, and one contracts row can have many terms rows pointing to it. On delete: cascade.
- events.contract_id references contracts.id: each events row points to at most one contracts row, and one contracts row can have many events rows pointing to it.
Contract tracker tables
The schema has 9 tables. Every column below is read from the SQL file itself. Also described as: contract renewal tracker database design, contract register database tables, vendor contract data model.
| Table | Implements | What a row is |
|---|---|---|
settings | Settings | The one row of company settings: name, time zone and the reminder day lists. |
people | Person | An admin or member who signs in, with a secret calendar feed token. |
counterparties | Counterparty | The other party to contracts, with a unique name and a kind. |
contracts | Contract | One contract with its current term, value, renewal settings, status and decision. |
documents | Document | One uploaded PDF on a contract, with its label, file name and size. |
reminders_sent | ReminderSent | One reminder recorded for one key date, so it is never sent twice. |
terms | Term | One term of a contract in the append-only term history. |
events | Event | An append-only record of one change, linked to its contract when there is one. |
notifications | Notification | One email to one address in the outbox, with its delivery status. |
settings
The single settings row. id is fixed at 1 so the table can never hold a second row.
| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
id | INTEGER | no | Primary key | Check: id = 1 | |
company_name | TEXT | no | |||
time_zone | TEXT | no | 'America/Chicago' | IANA name; today, the daily job and every date use this zone | |
notice_reminder_days | TEXT | no | '60,30,7' | comma-separated days before a notice deadline; admins are copied on the smallest | |
expiry_reminder_days | TEXT | no | '90,30' | comma-separated days before the end date of a contract that does not auto-renew |
people
A person who signs in. Owner is not a role: a person owns the contracts whose owner_id is theirs.
| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
id | TEXT | no | Primary key | ||
name | TEXT | no | |||
email | TEXT | no | Unique | stored lowercaseCheck: email = lower(email) | |
role | TEXT | no | Check: role IN ('admin', 'member') | ||
active | BOOLEAN | no | TRUE | ||
calendar_token | TEXT | no | Unique | long random secret; the calendar feed is /calendar/<calendar_token>.ics |
- App rule (R8): a person cannot be deactivated while they own an active or ending contract.
counterparties
The other party to one or more contracts. Only admins create counterparties.
| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
id | TEXT | no | Primary key | ||
name | TEXT | no | Unique | ||
kind | TEXT | no | Check: kind IN ('customer', 'supplier', 'landlord', 'insurer', 'other') | ||
contact_email | TEXT | yes |
contracts
One contract and its current term. Only admins create contracts and change owner_id or confidential.
| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
id | TEXT | no | Primary key | ||
number | TEXT | no | Unique | e.g. C-001Check: substr(number, 1, 2) = 'C-' | |
title | TEXT | no | |||
counterparty_id | TEXT | no | References counterparties.id | ||
type | TEXT | no | free text, such as Customer agreement, Services, Lease, NDA, Insurance, Software | ||
owner_id | TEXT | no | References people.id | ||
confidential | BOOLEAN | no | FALSE | ||
tags | TEXT | yes | comma-separated free-text tags; the tag filter matches one whole tag, ignoring case | ||
annual_value_cents | INTEGER | no | 0 | 0 for no valueCheck: annual_value_cents >= 0 | |
start_date | DATE | no | start of the current term | ||
end_date | DATE | yes | end of the current term; NULL for evergreen contracts | ||
auto_renew | BOOLEAN | no | FALSE | ||
renewal_term_months | INTEGER | yes | Check: renewal_term_months BETWEEN 1 AND 60 | ||
notice_days | INTEGER | yes | Check: notice_days BETWEEN 0 AND 365 | ||
status | TEXT | no | 'active' | Check: status IN ('active', 'ending', 'ended') | |
decision | TEXT | no | 'none' | Check: decision IN ('none', 'renew', 'renegotiate', 'cancel') | |
decision_note | TEXT | yes | |||
notice_sent_on | DATE | yes | the day notice was sent to the counterparty; required to record cancel | ||
late_notice | BOOLEAN | no | FALSE | TRUE when cancel was confirmed with notice after the notice deadline |
- Table check:
end_date IS NULL OR end_date > start_date - Table check:
auto_renew = FALSE OR (end_date IS NOT NULL AND renewal_term_months IS NOT NULL) - Table check:
status <> 'ending' OR decision = 'cancel' - Table check:
decision <> 'cancel' OR (status IN ('ending', 'ended') AND notice_sent_on IS NOT NULL AND decision_note IS NOT NULL) - Table check:
decision <> 'renegotiate' OR decision_note IS NOT NULL - Table check:
decision <> 'renew' OR auto_renew = TRUE - Table check:
late_notice = FALSE OR (decision = 'cancel' AND auto_renew = TRUE) - Index
contracts_owneron(owner_id) - Index
contracts_counterpartyon(counterparty_id) - Index
contracts_end_dateon(status, end_date) - App rule (section 6): the notice deadline is end_date minus notice_days for auto-renewing contracts; it is computed, never stored.
- App rule (R3): the roll-over starts a new term the day after end_date unless the decision is cancel, and clears decision, decision_note, notice_sent_on and late_notice.
- App rule (section 7): once renew or cancel is recorded only an admin Undo clears it; an ended contract takes no decision.
- App rule (R5): confidential contracts are visible only to their owner and admins, everywhere.
- App rule: number is the next unused C- number and is never reused.
documents
One uploaded PDF on a contract: the original, an amendment or a renewal.
| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
id | TEXT | no | Primary key | ||
contract_id | TEXT | no | References contracts.id, on delete cascade | ||
label | TEXT | no | e.g. Original, Amendment 1, Renewal 2027 | ||
storage_key | TEXT | no | Unique | where the file lives in private storage | |
original_filename | TEXT | no | |||
size_bytes | INTEGER | no | at most 25 MB (25 x 1024 x 1024)Check: size_bytes BETWEEN 0 AND 26214400 | ||
uploaded_at | TIMESTAMP | no | |||
uploaded_by | TEXT | no | References people.id |
- Index
documents_contracton(contract_id) - App rule (R6): the declared type is application/pdf, the file starts with %PDF- and the name ends in .pdf; only the owner or an admin uploads.
reminders_sent
One reminder recorded for one key date, so each is sent once.
| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
contract_id | TEXT | no | Primary key (part); References contracts.id, on delete cascade | ||
kind | TEXT | no | Primary key (part) | Check: kind IN ('notice', 'expiry') | |
days_before | INTEGER | no | Primary key (part) | one of the settings reminder daysCheck: days_before >= 0 | |
for_date | DATE | no | Primary key (part) | the key date: the notice deadline or the end date | |
sent_on | DATE | no | the company date of the daily run that recorded it |
- App rule (section 6): when several reminders for one key date are due on one run, only the nearest is sent and the others are recorded here as covered.
terms
One term of a contract. Append-only history.
| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
id | TEXT | no | Primary key | ||
contract_id | TEXT | no | References contracts.id, on delete cascade | ||
start_date | DATE | no | |||
end_date | DATE | yes | NULL for an evergreen contract | ||
how | TEXT | no | extended: an edit moved the end date later, start = old end + 1 dayCheck: how IN ('signed', 'auto_renewed', 'extended') |
- Table check:
end_date IS NULL OR end_date >= start_date - Index
terms_contracton(contract_id, start_date) - App rule (R10): terms are never edited or deleted.
events
One change, written by every action. Append-only.
| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
id | TEXT | no | Primary key | ||
at | TIMESTAMP | no | |||
actor | TEXT | no | a person id, or the daily job | ||
type | TEXT | no | e.g. decision_recorded, rolled_over | ||
contract_id | TEXT | yes | References contracts.id | NULL for events that are not about one contract | |
data | TEXT | yes | details of the change as JSON text |
- Index
events_contracton(contract_id, at) - App rule (R10): events are never edited or deleted.
notifications
One email to one address in the outbox. An email to several people is one row per address.
| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
id | TEXT | no | Primary key | ||
created_at | TIMESTAMP | no | the Outbox lists newest first | ||
kind | TEXT | no | which trigger in section 10, e.g. notice_reminder, renewed, late_notice | ||
to_email | TEXT | no | |||
subject | TEXT | no | |||
body | TEXT | no | |||
status | TEXT | no | 'queued' | logged when no email provider is configuredCheck: status IN ('queued', 'sent', 'failed', 'logged') | |
error | TEXT | yes |
- App rule (section 10): a failed email never blocks the action that caused it.
The SQL
The whole schema in one file. It runs top to bottom, unmodified, on SQLite and PostgreSQL. Download contract-tracker.sql or copy it from here.
-- Contract Tracker database schema
-- Source: https://personalsoftwarefactory.com/blueprints/contract-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. 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,
time_zone TEXT NOT NULL DEFAULT 'America/Chicago', -- IANA name; today, the daily job and every date use this zone
notice_reminder_days TEXT NOT NULL DEFAULT '60,30,7', -- comma-separated days before a notice deadline; admins are copied on the smallest
expiry_reminder_days TEXT NOT NULL DEFAULT '90,30' -- comma-separated days before the end date of a contract that does not auto-renew
);
-- A person who signs in. Owner is not a role: a person owns the contracts whose owner_id is theirs.
-- App rule (R8): a person cannot be deactivated while they own an active or ending contract.
CREATE TABLE people (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE CHECK (email = lower(email)), -- stored lowercase
role TEXT NOT NULL CHECK (role IN ('admin', 'member')),
active BOOLEAN NOT NULL DEFAULT TRUE,
calendar_token TEXT NOT NULL UNIQUE -- long random secret; the calendar feed is /calendar/<calendar_token>.ics
);
-- The other party to one or more contracts. Only admins create counterparties.
CREATE TABLE counterparties (
id TEXT PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
kind TEXT NOT NULL CHECK (kind IN ('customer', 'supplier', 'landlord', 'insurer', 'other')),
contact_email TEXT
);
-- One contract and its current term. Only admins create contracts and change owner_id or confidential.
-- App rule (section 6): the notice deadline is end_date minus notice_days for auto-renewing contracts; it is computed, never stored.
-- App rule (R3): the roll-over starts a new term the day after end_date unless the decision is cancel, and clears decision, decision_note, notice_sent_on and late_notice.
-- App rule (section 7): once renew or cancel is recorded only an admin Undo clears it; an ended contract takes no decision.
-- App rule (R5): confidential contracts are visible only to their owner and admins, everywhere.
-- App rule: number is the next unused C- number and is never reused.
CREATE TABLE contracts (
id TEXT PRIMARY KEY,
number TEXT NOT NULL UNIQUE CHECK (substr(number, 1, 2) = 'C-'), -- e.g. C-001
title TEXT NOT NULL,
counterparty_id TEXT NOT NULL REFERENCES counterparties(id),
type TEXT NOT NULL, -- free text, such as Customer agreement, Services, Lease, NDA, Insurance, Software
owner_id TEXT NOT NULL REFERENCES people(id),
confidential BOOLEAN NOT NULL DEFAULT FALSE,
tags TEXT, -- comma-separated free-text tags; the tag filter matches one whole tag, ignoring case
annual_value_cents INTEGER NOT NULL DEFAULT 0 CHECK (annual_value_cents >= 0), -- 0 for no value
start_date DATE NOT NULL, -- start of the current term
end_date DATE, -- end of the current term; NULL for evergreen contracts
auto_renew BOOLEAN NOT NULL DEFAULT FALSE,
renewal_term_months INTEGER CHECK (renewal_term_months BETWEEN 1 AND 60),
notice_days INTEGER CHECK (notice_days BETWEEN 0 AND 365),
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'ending', 'ended')),
decision TEXT NOT NULL DEFAULT 'none' CHECK (decision IN ('none', 'renew', 'renegotiate', 'cancel')),
decision_note TEXT,
notice_sent_on DATE, -- the day notice was sent to the counterparty; required to record cancel
late_notice BOOLEAN NOT NULL DEFAULT FALSE, -- TRUE when cancel was confirmed with notice after the notice deadline
CHECK (end_date IS NULL OR end_date > start_date),
CHECK (auto_renew = FALSE OR (end_date IS NOT NULL AND renewal_term_months IS NOT NULL)),
CHECK (status <> 'ending' OR decision = 'cancel'),
CHECK (decision <> 'cancel' OR (status IN ('ending', 'ended') AND notice_sent_on IS NOT NULL AND decision_note IS NOT NULL)),
CHECK (decision <> 'renegotiate' OR decision_note IS NOT NULL),
CHECK (decision <> 'renew' OR auto_renew = TRUE),
CHECK (late_notice = FALSE OR (decision = 'cancel' AND auto_renew = TRUE))
);
CREATE INDEX contracts_owner ON contracts (owner_id);
CREATE INDEX contracts_counterparty ON contracts (counterparty_id);
CREATE INDEX contracts_end_date ON contracts (status, end_date);
-- One uploaded PDF on a contract: the original, an amendment or a renewal.
-- App rule (R6): the declared type is application/pdf, the file starts with %PDF- and the name ends in .pdf; only the owner or an admin uploads.
CREATE TABLE documents (
id TEXT PRIMARY KEY,
contract_id TEXT NOT NULL REFERENCES contracts(id) ON DELETE CASCADE,
label TEXT NOT NULL, -- e.g. Original, Amendment 1, Renewal 2027
storage_key TEXT NOT NULL UNIQUE, -- where the file lives in private storage
original_filename TEXT NOT NULL,
size_bytes INTEGER NOT NULL CHECK (size_bytes BETWEEN 0 AND 26214400), -- at most 25 MB (25 x 1024 x 1024)
uploaded_at TIMESTAMP NOT NULL,
uploaded_by TEXT NOT NULL REFERENCES people(id)
);
CREATE INDEX documents_contract ON documents (contract_id);
-- One reminder recorded for one key date, so each is sent once.
-- App rule (section 6): when several reminders for one key date are due on one run, only the nearest is sent and the others are recorded here as covered.
CREATE TABLE reminders_sent (
contract_id TEXT NOT NULL REFERENCES contracts(id) ON DELETE CASCADE,
kind TEXT NOT NULL CHECK (kind IN ('notice', 'expiry')),
days_before INTEGER NOT NULL CHECK (days_before >= 0), -- one of the settings reminder days
for_date DATE NOT NULL, -- the key date: the notice deadline or the end date
sent_on DATE NOT NULL, -- the company date of the daily run that recorded it
PRIMARY KEY (contract_id, kind, days_before, for_date)
);
-- One term of a contract. Append-only history.
-- App rule (R10): terms are never edited or deleted.
CREATE TABLE terms (
id TEXT PRIMARY KEY,
contract_id TEXT NOT NULL REFERENCES contracts(id) ON DELETE CASCADE,
start_date DATE NOT NULL,
end_date DATE, -- NULL for an evergreen contract
how TEXT NOT NULL CHECK (how IN ('signed', 'auto_renewed', 'extended')), -- extended: an edit moved the end date later, start = old end + 1 day
CHECK (end_date IS NULL OR end_date >= start_date)
);
CREATE INDEX terms_contract ON terms (contract_id, start_date);
-- One change, written by every action. Append-only.
-- App rule (R10): events are never edited or deleted.
CREATE TABLE events (
id TEXT PRIMARY KEY,
at TIMESTAMP NOT NULL,
actor TEXT NOT NULL, -- a person id, or the daily job
type TEXT NOT NULL, -- e.g. decision_recorded, rolled_over
contract_id TEXT REFERENCES contracts(id), -- NULL for events that are not about one contract
data TEXT -- details of the change as JSON text
);
CREATE INDEX events_contract ON events (contract_id, at);
-- One email to one address in the outbox. An email to several people is one row per address.
-- App rule (section 10): a failed email never blocks the action that caused it.
CREATE TABLE notifications (
id TEXT PRIMARY KEY,
created_at TIMESTAMP NOT NULL, -- the Outbox lists newest first
kind TEXT NOT NULL, -- which trigger in section 10, e.g. notice_reminder, renewed, late_notice
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 email provider is configured
error TEXT
);Seed data
Loads section 14 as of Thursday 2026-10-15: settings, 4 people, 6 counterparties, contracts C-001 to C-006, the 5 reminders the notes say were sent (as ReminderSent rows with the key date, sent on those dates), and one signed term per contract with its current dates, since section 5 writes a signed term when a contract is created. Calendar tokens are readable placeholders for the random secrets the app generates. The spec gives no tags, contact emails, documents, or notice days for the contracts that do not auto-renew, so those are NULL or absent; no events or emails are seeded.
Download contract-tracker-seed.sql (28 rows). It loads with foreign keys enforced on both engines.
Load it
SQLite, into a new file:
curl -s https://personalsoftwarefactory.com/schemas/contract-tracker.sql https://personalsoftwarefactory.com/schemas/contract-tracker-seed.sql | sqlite3 contract_tracker.dbPostgreSQL, into a new database:
createdb contract_tracker && curl -s https://personalsoftwarefactory.com/schemas/contract-tracker.sql https://personalsoftwarefactory.com/schemas/contract-tracker-seed.sql | psql -v ON_ERROR_STOP=1 contract_trackerSQLite only enforces foreign keys when the connection asks for it: run PRAGMA foreign_keys = ON; when your app opens the database.
Design decisions
Owner is a column, not a role
From the build test · field report
The build test found the roles table listed an Owner role while Person.role was only admin or member. Owner is now a relationship, so people.role is CHECKed to admin or member and contracts.owner_id is a required foreign key; a member can own a contract. R8 (no deactivating someone who still owns an active or ending contract) spans rows and stays an app rule.
Status and decision are checked together
From the build test · field report
Section 7 and the build test fixed several gaps here: ending is set only by recording Cancel, Cancel needs a notice date and a note, and a contract that does not auto-renew is never late. CHECKs enforce each: ending requires decision cancel, cancel requires status ending or ended plus notice_sent_on and decision_note, renegotiate requires a note, renew requires auto_renew, and late_notice requires an auto-renewing cancel. Without them a contract could show Late notice with no cancellation behind it.
R1 date rules live in the table
From the build test · field report
end_date is after start_date, notice_days is 0 to 365, and renewal_term_months is 1 to 60, all as CHECKs. The build test found an auto-renewing contract with no end date was not covered; R1 now requires one, so a CHECK requires end_date and renewal_term_months whenever auto_renew is TRUE. Evergreen contracts are end_date NULL with auto_renew FALSE.
Reminders are recorded per key date
From the build test · field report
ReminderSent is unique on contract, kind, days_before and for_date (section 5), which is the primary key here, so a second run of the daily job cannot record or send the same reminder again, and a changed end date starts fresh reminders. The build test found a missed run would send the 60, 30 and 7 day reminders together; only the nearest is sent and the others are recorded as covered. The spec gives no column to tell covered rows from sent ones, so both are plain rows.
Terms are append-only history
From the build test · field report
Each contract row holds only its current term; terms keeps every term with how it began. The build test found extended was never defined; it is written when an edit moves the end date later, starting the day after the old end date, so a terms CHECK allows end_date equal to start_date for a one-day extension, and end_date is NULL for an evergreen term.
Tags and reminder days are comma-separated text
From the build test · field report
The build test found tags had no format; they are a comma-separated list of free-text tags and the filter matches one whole tag ignoring case, so tags is a TEXT column. The settings reminder lists (60, 30, 7 and 90, 30) are short fixed lists read as a whole by the daily job, so they are comma-separated TEXT too rather than child tables.
The notice deadline is computed
Section 6 defines the notice deadline as end_date minus notice_days for auto-renewing contracts with an end date. Storing it would go stale whenever an edit or a roll-over changes the end date, so the app computes it, and the queries below select end_date and notice_days for it. notice_days is nullable because the spec gives none for contracts that do not auto-renew.
Example queries
The queries behind the tool's main screens. Each returned the same rows on both engines against the seed data.
Contract register as one person sees it
SELECT c.number, c.title, cp.name AS counterparty, c.type, o.name AS owner,
CASE WHEN c.confidential = TRUE THEN 'yes' ELSE 'no' END AS confidential,
c.annual_value_cents, c.start_date, c.end_date,
CASE WHEN c.auto_renew = TRUE THEN 'yes' ELSE 'no' END AS auto_renew,
c.renewal_term_months, c.notice_days, c.decision, c.status
FROM contracts c
JOIN counterparties cp ON cp.id = c.counterparty_id
JOIN people o ON o.id = c.owner_id
WHERE c.confidential = FALSE OR c.owner_id = 'person_omar'
OR EXISTS (SELECT 1 FROM people v WHERE v.id = 'person_omar' AND v.role = 'admin')
ORDER BY c.number;On the seed data, as Omar Ali (a member): 5 rows, C-001 to C-005; C-006 Warehouse lease is confidential and owned by Grace Kim, so it is left out.
Contracts expiring in the next 90 days
SELECT c.number, c.title, c.end_date, o.name AS owner, c.decision
FROM contracts c
JOIN people o ON o.id = c.owner_id
WHERE (c.auto_renew = FALSE OR c.decision = 'cancel')
AND c.status <> 'ended'
AND c.end_date BETWEEN '2026-10-15' AND '2027-01-13'
ORDER BY c.end_date, c.number;On the seed data, for Oct 15, 2026 to Jan 13, 2027: 1 row; C-004 Van lease ends 2026-10-31, owner Priya Nair.
Auto-renewing contracts waiting on a decision
SELECT c.number, c.title, c.end_date, c.notice_days, c.decision,
(SELECT COUNT(*) FROM reminders_sent r WHERE r.contract_id = c.id AND r.kind = 'notice') AS reminders_recorded
FROM contracts c
WHERE c.auto_renew = TRUE AND c.decision IN ('none', 'renegotiate') AND c.status <> 'ended'
ORDER BY c.end_date, c.number;On the seed data: 2 rows; C-002 Zendesk subscription ends 2026-12-15 with 30 days notice and 1 reminder recorded, then C-001 with 90 days notice and 2.
Reminders already recorded
SELECT c.number, c.title, r.kind, r.days_before, r.for_date, r.sent_on
FROM reminders_sent r
JOIN contracts c ON c.id = r.contract_id
ORDER BY r.sent_on, c.number;On the seed data: 5 rows; the first is C-004 Van lease, the 90-day expiry reminder for 2026-10-31, sent 2026-08-02.
Annual value by type
SELECT c.type, COUNT(*) AS contracts, SUM(c.annual_value_cents) AS annual_value_cents
FROM contracts c
WHERE c.status IN ('active', 'ending')
GROUP BY c.type
ORDER BY annual_value_cents DESC, c.type;On the seed data, as an admin: 5 rows; Customer agreement 12,000,000 cents ($120,000) first, Lease 11,040,000 cents across 2 contracts, NDA 0.
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 Contract Tracker blueprint, a free spec that also has the business rules, the screens, 4 phased build prompts and 15 acceptance checks for building the whole tool with an AI app builder. We built it from those prompts and the result passed 15 of 15 acceptance checks in a browser.
- Read the Contract Tracker blueprint: rules, screens, build prompts and acceptance checks
- Read the build-test field report: what the test build got wrong and what was not tested
- All database schemas
- How we test blueprints
Follow new blueprints
Every new blueprint and build test appears in the feed and in the public GitHub repository. No account, no email list.