SaaS management system database schema

Six tables, with tools carrying the design: one row per subscription with its cycle price for the whole subscription, billing cycle, renewal date, notice days, seats and status. Annualized cost, unused seat cost, notice deadline and reminder date are computed, never stored, and a unique dedupe key on notifications makes the daily reminder job safe to run twice.

  • 6 tables, 8 indexes
  • Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite 0.6.1),
  • 27 seed rows from the blueprint
  • The blueprint's test build passed 31 of 31 acceptance checks

Copy the SQLDownload SQLDownload seed data

By Sam Claassen · From the SaaS Spend Tracker blueprint · MIT licensed · Markdown version

SaaS spend tracker entity-relationship diagram

peopleidPK+ 4 more columnsdepartmentsidPK+ 1 more columntoolsidPKowner_id→ peopledepartment_id→ departments+ 16 more columnshistory_eventsidPKtool_id→ toolsactor_id→ people+ 5 more columnsnotificationsidPKrecipient_id→ peopletool_id→ tools+ 9 more columnssettingsidPK+ 3 more columnspeopleidPK+ 4 more columnsdepartmentsidPK+ 1 more columntoolsidPKowner_id→ peopledepartment_id→ departments+ 16 more columnshistory_eventsidPKtool_id→ toolsactor_id→ people+ 5 more columnsnotificationsidPKrecipient_id→ peopletool_id→ tools+ 9 more columnssettingsidPK+ 3 more columns
Each box is a table with its key columns. A line runs from a table up to a table it references, with the forked end on the side that has many rows; a dashed line is an optional reference.

Relationships

  • tools.owner_id references people.id: each tools row points to exactly one people row, and one people row can have many tools rows pointing to it.
  • tools.department_id references departments.id: each tools row points to exactly one departments row, and one departments row can have many tools rows pointing to it.
  • history_events.tool_id references tools.id: each history_events row points to exactly one tools row, and one tools row can have many history_events rows pointing to it.
  • history_events.actor_id references people.id: each history_events row points to at most one people row, and one people row can have many history_events rows pointing to it.
  • notifications.recipient_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.tool_id references tools.id: each notifications row points to at most one tools row, and one tools row can have many notifications rows pointing to it.

SaaS spend tracker tables

The schema has 6 tables. Every column below is read from the SQL file itself. Also described as: software subscription tracker database design, SaaS license management database tables, vendor contract renewal SQL schema.

TableImplementsWhat a row is
peoplePersonA team member, who may own tools and may be a finance admin.
departmentsDepartmentThe budget that pays for a tool.
toolsToolOne paid subscription or contract, with its price per billing cycle, renewal date, notice period, seats and status.
history_eventsHistoryEventOne append-only change to a tool, by a person, a CSV import or the daily job.
notificationsNotificationOne renewal reminder or owner notice in the outbox, with its dedupe key and send status.
settingsSettingsThe single row with the currency, time zone and development clock offset.

people

A person on the team. Owners and admins are people.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
nameTEXTno
emailTEXTnounique ignoring case (index below)
is_adminBOOLEANnoFALSE
activeBOOLEANnoTRUE
  • Unique index people_email_unique on (LOWER(email))
  • App rule (R16): at least one active admin must remain.

departments

A department: the budget that pays for a tool.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
nameTEXTnounique ignoring case (index below)Check: LENGTH(name) BETWEEN 2 AND 60
  • Unique index departments_name_unique on (LOWER(name))
  • App rule (screen 10): a department with tools of any status can't be deleted.

tools

One paid subscription or contract.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
nameTEXTnotrimmed; unique among current tools (index below)Check: name = TRIM(name) AND LENGTH(name) BETWEEN 2 AND 100
owner_idTEXTnoReferences people.id
department_idTEXTnoReferences departments.id
billing_cycleTEXTnoCheck: billing_cycle IN ('monthly', 'quarterly', 'annual')
cycle_price_centsINTEGERnototal per billing cycle for the whole subscription, never per seatCheck: cycle_price_cents BETWEEN 0 AND 100000000
renews_onDATEnoend of the current term; for a cancelling tool, the day it ends
auto_renewBOOLEANnoTRUEthe vendor renews unless notice is given
notice_daysINTEGERno0notice the contract requires before renews_onCheck: notice_days BETWEEN 0 AND 365
seats_purchasedINTEGERno00 means not seat-basedCheck: seats_purchased BETWEEN 0 AND 100000
seats_usedINTEGERno0typed in by the ownerCheck: seats_used >= 0
statusTEXTno'active'Check: status IN ('active', 'cancelling', 'cancelled')
status_reasonTEXTyesgiven when marked cancelling or cancelledCheck: status_reason IS NULL OR LENGTH(status_reason) BETWEEN 3 AND 200
ended_onDATEyesset when the tool becomes cancelled
linkTEXTyesCheck: link IS NULL OR (LENGTH(link) <= 500 AND (SUBSTR(link, 1, 7) = 'http://' OR SUBSTR(link, 1, 8) = 'https://'))
notesTEXTyesCheck: notes IS NULL OR LENGTH(notes) <= 1000
versionINTEGERno1Check: version >= 1
created_atTIMESTAMPnoCURRENT_TIMESTAMP
updated_atTIMESTAMPnoCURRENT_TIMESTAMP
  • Table check: seats_used <= seats_purchased
  • Table check: status = 'active' OR status_reason IS NOT NULL
  • Table check: (status = 'cancelled' AND ended_on IS NOT NULL) OR (status <> 'cancelled' AND ended_on IS NULL)
  • Unique index tools_current_name_unique on (LOWER(name)) where status IN ('active', 'cancelling')
  • Index tools_owner on (owner_id)
  • Index tools_department on (department_id)
  • Index tools_status_renews on (status, renews_on)
  • App rule (R16): owner_id is an active person while the tool is active or cancelling.
  • App rule (R18): every change increments version; a save with a stale version is refused.
  • App rule (R19): cancelled tools are read-only until restored.

history_events

One change to a tool. Append-only, never updated or deleted (R17).

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
tool_idTEXTnoReferences tools.id
actor_idTEXTyesReferences people.idnull means the daily job
typeTEXTnoCheck: type IN ('created', 'edited', 'renewed', 'auto_renewed', 'status_changed', 'reminder_queued')
sourceTEXTnoCheck: source IN ('form', 'csv', 'job')
changesTEXTyesJSON text: field -> {from, to}; a late cancellation also holds "late_notice": true
reasonTEXTyes
created_atTIMESTAMPnoCURRENT_TIMESTAMP
  • Index history_events_tool on (tool_id, created_at)

notifications

One reminder or notice in the outbox, written before it is sent.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
recipient_idTEXTnoReferences people.id
kindTEXTnoCheck: kind IN ('renewal_reminder', 'owner_assigned')
tool_idTEXTyesReferences tools.idnull when one notice lists several tools
dedupe_keyTEXTyesUniquereminder:{tool_id}:{renews_on}:{notice_deadline}:{recipient_id} (R7)
subjectTEXTno
bodyTEXTnothe text as sent
statusTEXTno'queued'logged: no email provider configuredCheck: status IN ('queued', 'sent', 'logged', 'failed')
attemptsINTEGERno0Check: attempts >= 0
last_errorTEXTyes
created_atTIMESTAMPnoCURRENT_TIMESTAMP
sent_atTIMESTAMPyes
  • Index notifications_recipient on (recipient_id, created_at)
  • App rule (section 11): after 5 failed attempts the status becomes failed.

settings

The single settings row.

ColumnTypeNullDefaultKeyNotes
idINTEGERno1Primary keyalways 1, so there can only be one rowCheck: id = 1
currency_codeTEXTno'USD'changes the symbol only; amounts are never converted
time_zoneTEXTno'UTC'IANA name; today is the date in this zone
dev_clock_offset_daysINTEGERno0development only, ignored in production

The SQL

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

saas-spend-tracker.sql
-- SaaS Spend Tracker database schema
-- Source: https://personalsoftwarefactory.com/blueprints/saas-spend-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.
--
-- Money is integer cents. renews_on and ended_on are calendar dates with no time.
-- Annualized cost, unused seat cost, notice deadline and reminder date are computed, never stored (section 5).

-- A person on the team. Owners and admins are people.
-- App rule (R16): at least one active admin must remain.
CREATE TABLE people (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT NOT NULL, -- unique ignoring case (index below)
  is_admin BOOLEAN NOT NULL DEFAULT FALSE,
  active BOOLEAN NOT NULL DEFAULT TRUE
);

CREATE UNIQUE INDEX people_email_unique ON people (LOWER(email));

-- A department: the budget that pays for a tool.
-- App rule (screen 10): a department with tools of any status can't be deleted.
CREATE TABLE departments (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 2 AND 60) -- unique ignoring case (index below)
);

CREATE UNIQUE INDEX departments_name_unique ON departments (LOWER(name));

-- One paid subscription or contract.
-- App rule (R16): owner_id is an active person while the tool is active or cancelling.
-- App rule (R18): every change increments version; a save with a stale version is refused.
-- App rule (R19): cancelled tools are read-only until restored.
CREATE TABLE tools (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (name = TRIM(name) AND LENGTH(name) BETWEEN 2 AND 100), -- trimmed; unique among current tools (index below)
  owner_id TEXT NOT NULL REFERENCES people(id),
  department_id TEXT NOT NULL REFERENCES departments(id),
  billing_cycle TEXT NOT NULL CHECK (billing_cycle IN ('monthly', 'quarterly', 'annual')),
  cycle_price_cents INTEGER NOT NULL CHECK (cycle_price_cents BETWEEN 0 AND 100000000), -- total per billing cycle for the whole subscription, never per seat
  renews_on DATE NOT NULL, -- end of the current term; for a cancelling tool, the day it ends
  auto_renew BOOLEAN NOT NULL DEFAULT TRUE, -- the vendor renews unless notice is given
  notice_days INTEGER NOT NULL DEFAULT 0 CHECK (notice_days BETWEEN 0 AND 365), -- notice the contract requires before renews_on
  seats_purchased INTEGER NOT NULL DEFAULT 0 CHECK (seats_purchased BETWEEN 0 AND 100000), -- 0 means not seat-based
  seats_used INTEGER NOT NULL DEFAULT 0 CHECK (seats_used >= 0), -- typed in by the owner
  status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'cancelling', 'cancelled')),
  status_reason TEXT CHECK (status_reason IS NULL OR LENGTH(status_reason) BETWEEN 3 AND 200), -- given when marked cancelling or cancelled
  ended_on DATE, -- set when the tool becomes cancelled
  link TEXT CHECK (link IS NULL OR (LENGTH(link) <= 500 AND (SUBSTR(link, 1, 7) = 'http://' OR SUBSTR(link, 1, 8) = 'https://'))),
  notes TEXT CHECK (notes IS NULL OR LENGTH(notes) <= 1000),
  version INTEGER NOT NULL DEFAULT 1 CHECK (version >= 1),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CHECK (seats_used <= seats_purchased), -- R14
  CHECK (status = 'active' OR status_reason IS NOT NULL), -- R19: a reason is required
  CHECK ((status = 'cancelled' AND ended_on IS NOT NULL) OR (status <> 'cancelled' AND ended_on IS NULL))
);

CREATE UNIQUE INDEX tools_current_name_unique ON tools (LOWER(name)) WHERE status IN ('active', 'cancelling'); -- R13: a cancelled tool's name can be reused
CREATE INDEX tools_owner ON tools (owner_id);
CREATE INDEX tools_department ON tools (department_id);
CREATE INDEX tools_status_renews ON tools (status, renews_on);

-- One change to a tool. Append-only, never updated or deleted (R17).
CREATE TABLE history_events (
  id TEXT PRIMARY KEY,
  tool_id TEXT NOT NULL REFERENCES tools(id),
  actor_id TEXT REFERENCES people(id), -- null means the daily job
  type TEXT NOT NULL CHECK (type IN ('created', 'edited', 'renewed', 'auto_renewed', 'status_changed', 'reminder_queued')),
  source TEXT NOT NULL CHECK (source IN ('form', 'csv', 'job')),
  changes TEXT, -- JSON text: field -> {from, to}; a late cancellation also holds "late_notice": true
  reason TEXT,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX history_events_tool ON history_events (tool_id, created_at);

-- One reminder or notice in the outbox, written before it is sent.
-- App rule (section 11): after 5 failed attempts the status becomes failed.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  recipient_id TEXT NOT NULL REFERENCES people(id),
  kind TEXT NOT NULL CHECK (kind IN ('renewal_reminder', 'owner_assigned')),
  tool_id TEXT REFERENCES tools(id), -- null when one notice lists several tools
  dedupe_key TEXT UNIQUE, -- reminder:{tool_id}:{renews_on}:{notice_deadline}:{recipient_id} (R7)
  subject TEXT NOT NULL,
  body TEXT NOT NULL, -- the text as sent
  status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'sent', 'logged', 'failed')), -- logged: no email provider configured
  attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts >= 0),
  last_error TEXT,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  sent_at TIMESTAMP
);

CREATE INDEX notifications_recipient ON notifications (recipient_id, created_at);

-- The single settings row.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY DEFAULT 1 CHECK (id = 1), -- always 1, so there can only be one row
  currency_code TEXT NOT NULL DEFAULT 'USD', -- changes the symbol only; amounts are never converted
  time_zone TEXT NOT NULL DEFAULT 'UTC', -- IANA name; today is the date in this zone
  dev_clock_offset_days INTEGER NOT NULL DEFAULT 0 -- development only, ignored in production
);

Seed data

Loads section 14 with T fixed to Tue 13 Oct 2026, the date the spec's examples use: 7 people, 5 departments, the 6 tools with their prices, seats, renewal dates, notice periods and statuses, 8 history events (created by Ana Lima for each tool, Dana's change of Monday.com to cancelling and Maya's change of Loom to cancelled), and the settings row. The spec gives no times for the seed history, so the events are stamped 09:00 and 09:05 on T; stamped on T, Dana's change comes after Monday.com's Oct 11 notice deadline, so its changes record late_notice as section 8 requires. The outbox is empty, as the spec says; the first daily job run queues the four reminders.

Download saas-spend-tracker-seed.sql (27 rows). It loads with foreign keys enforced on both engines.

Load it

SQLite, into a new file:

sqlite3
curl -s https://personalsoftwarefactory.com/schemas/saas-spend-tracker.sql https://personalsoftwarefactory.com/schemas/saas-spend-tracker-seed.sql | sqlite3 saas_spend_tracker.db

PostgreSQL, into a new database:

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

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

Design decisions

The price is per billing cycle for the whole subscription

tools.cycle_price_cents is the total charged each cycle, never a per-seat price (section 5, R1). Annualized cost is the cycle price times 12, 4 or 1, so a $1,000-a-month plan with 100 seats is $12,000 a year. Storing a per-seat price invites multiplying by seats and reporting $1,200,000.

Money and dates that follow from the row are never stored

Annualized cost, unused seat cost, the notice deadline (renews_on minus notice_days) and the reminder date are computed in one shared module (section 5), so a changed price or notice period can never leave a stale total. Date arithmetic differs between SQLite and PostgreSQL, so the deadline belongs in the app, not in a portable query.

Names are unique among current tools only

R13 makes names unique ignoring case among active and cancelling tools, and lets a cancelled tool's name be reused. A partial unique index on LOWER(name) WHERE status IN ('active', 'cancelling') enforces exactly that; restoring a cancelled tool while a current one has its name fails on the same index.

Status, reason and end date must agree

CHECK constraints require a reason for cancelling and cancelled tools (R19), an ended_on exactly when the tool is cancelled (section 8), and seats_used no higher than seats_purchased (R14). Tools are never deleted; a mistake is marked cancelled with that reason, so the history stays complete.

A unique dedupe key makes reminders idempotent

notifications.dedupe_key is reminder:{tool_id}:{renews_on}:{notice_deadline}:{recipient_id} and is UNIQUE (R7). Two overlapping job runs cannot queue the same reminder; the second insert fails and is treated as already queued. A new renewal date, notice period or owner makes a new key, so the next reminder is queued when it is due.

Late notice lives in the history event's changes

From the build test · field report

Our build test found that cancelling after the notice deadline was supposed to record late_notice, but the history model had no place for it. Section 5 now puts "late_notice": true in the changes JSON of that status_changed event, which history_events.changes holds as text.

Every edit carries a version

tools.version starts at 1 and goes up on every change (R18). A save sends the version the form was opened with, and the update is refused when the row has moved on, so a person and the daily job can't overwrite each other's changes.

Example queries

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

Company tiles: run rate, seats and unused seat cost

SQL
SELECT
  COUNT(*) AS active_tools,
  SUM(CASE billing_cycle WHEN 'monthly' THEN cycle_price_cents * 12 WHEN 'quarterly' THEN cycle_price_cents * 4 ELSE cycle_price_cents END) AS run_rate_cents,
  SUM(seats_used) AS seats_used,
  SUM(seats_purchased) AS seats_purchased,
  SUM(CASE WHEN seats_purchased = 0 THEN 0 ELSE ((CASE billing_cycle WHEN 'monthly' THEN cycle_price_cents * 12 WHEN 'quarterly' THEN cycle_price_cents * 4 ELSE cycle_price_cents END) * (seats_purchased - seats_used) * 2 + seats_purchased) / (2 * seats_purchased) END) AS unused_seat_cents
FROM tools
WHERE status = 'active';

On the seed data: 1 row. 4 active tools, run rate 3132000 cents ($31,320), 141 of 190 seats used, unused seat cost 894000 cents ($8,940), as section 6 says. On PostgreSQL, very large contracts can overflow 32-bit INTEGER in the unused-seat product; R3 asks for 64-bit arithmetic.

Totals by department, with ending tools

SQL
SELECT
  d.name,
  SUM(CASE WHEN t.status = 'active' THEN 1 ELSE 0 END) AS active_tools,
  SUM(CASE WHEN t.status = 'active' THEN (CASE t.billing_cycle WHEN 'monthly' THEN t.cycle_price_cents * 12 WHEN 'quarterly' THEN t.cycle_price_cents * 4 ELSE t.cycle_price_cents END) ELSE 0 END) AS run_rate_cents,
  SUM(CASE WHEN t.status = 'cancelling' THEN 1 ELSE 0 END) AS ending_tools,
  SUM(CASE WHEN t.status = 'cancelling' THEN (CASE t.billing_cycle WHEN 'monthly' THEN t.cycle_price_cents * 12 WHEN 'quarterly' THEN t.cycle_price_cents * 4 ELSE t.cycle_price_cents END) ELSE 0 END) AS ending_cents
FROM departments d
LEFT JOIN tools t ON t.department_id = d.id
GROUP BY d.name
ORDER BY d.name;

On the seed data: 5 rows, matching the section 6 department table. Ops has 1 active tool at 1200000 cents ($12,000) and 1 ending tool at 240000 cents; Finance has none.

Unused seat cost per active tool

SQL
SELECT
  name,
  seats_used,
  seats_purchased,
  CASE WHEN seats_purchased = 0 THEN 0 ELSE ((CASE billing_cycle WHEN 'monthly' THEN cycle_price_cents * 12 WHEN 'quarterly' THEN cycle_price_cents * 4 ELSE cycle_price_cents END) * (seats_purchased - seats_used) * 2 + seats_purchased) / (2 * seats_purchased) END AS unused_seat_cents
FROM tools
WHERE status = 'active'
ORDER BY unused_seat_cents DESC, name;

On the seed data: 4 rows. Notion 336000 cents ($3,360), Figma 288000, Zoom 270000 and GitHub 0. The integer formula is R3's round-half-up.

Upcoming renewals with their notice periods

SQL
SELECT t.name, p.name AS owner, t.renews_on, t.auto_renew, t.notice_days, t.status
FROM tools t
JOIN people p ON p.id = t.owner_id
WHERE t.status IN ('active', 'cancelling')
ORDER BY t.renews_on, t.name;

On the seed data: 5 rows, starting with Notion (2026-10-20, auto-renew, 0 days' notice) and Monday.com (cancelling, ends 2026-10-25). The notice deadline, renews_on minus notice_days, is computed in the app (R5).

One tool's history, newest first

SQL
SELECT h.type, h.source, COALESCE(p.name, 'Daily job') AS actor, h.reason, h.created_at
FROM history_events h
JOIN tools t ON t.id = h.tool_id
LEFT JOIN people p ON p.id = h.actor_id
WHERE t.name = 'Monday.com'
ORDER BY h.created_at DESC, h.id DESC;

On the seed data: 2 rows for Monday.com, the status change by Dana Ruiz ("Nobody has used it since we moved to Notion") and the created event by Ana Lima.

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 SaaS Spend Tracker blueprint, a free spec that also has the business rules, the screens, 4 phased build prompts and 31 acceptance checks for building the whole tool with an AI app builder. We built it from those prompts and the result passed 31 of 31 acceptance checks in a browser.

Follow new blueprints

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