-- Project Status Board database schema -- Source: https://personalsoftwarefactory.com/blueprints/project-status-board (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. -- One row per person on the team. -- App rule (R10): deactivating someone who owns an active project is refused, and there must always be at least one active admin. CREATE TABLE people ( id TEXT PRIMARY KEY, name TEXT NOT NULL CHECK (length(name) >= 1), email TEXT NOT NULL UNIQUE CHECK (email = lower(email)), -- stored lowercase is_admin BOOLEAN NOT NULL DEFAULT FALSE, active BOOLEAN NOT NULL DEFAULT TRUE ); -- The single settings row for the one team and board. CREATE TABLE settings ( id INTEGER PRIMARY KEY CHECK (id = 1), -- one row only team_name TEXT NOT NULL CHECK (length(team_name) BETWEEN 1 AND 60), -- used in the report title time_zone TEXT NOT NULL DEFAULT 'America/New_York', -- IANA name; decides today, weeks and job times update_weekday INTEGER NOT NULL DEFAULT 1 CHECK (update_weekday BETWEEN 1 AND 7), -- 1 = Monday to 7 = Sunday reminder_time TEXT NOT NULL DEFAULT '09:00' CHECK (reminder_time LIKE '__:__' AND reminder_time BETWEEN '00:00' AND '23:59' AND substr(reminder_time, 4, 2) < '60'), -- HH:MM, 24-hour, team time report_time TEXT NOT NULL DEFAULT '15:00' CHECK (report_time LIKE '__:__' AND report_time BETWEEN '00:00' AND '23:59' AND substr(report_time, 4, 2) < '60'), -- HH:MM, 24-hour, team time report_recipients TEXT NOT NULL DEFAULT '', -- email addresses separated by commas; empty means the scheduled report is skipped last_reminder_week DATE, -- written only by the scheduled job: the Monday of the last week reminded last_report_week DATE, -- written only by the scheduled job: the Monday of the last week reported CHECK (report_time > reminder_time) ); -- One row per project on the board. Projects are archived, never deleted. -- App rule (R9): only the owner or an admin can edit, change the owner, archive or restore. -- App rule (R10): owner_id must point at an active person. -- App rule (R7): an archived project is read-only and left out of the board, missing counts, reminders and reports. CREATE TABLE projects ( id TEXT PRIMARY KEY, name TEXT NOT NULL CHECK (length(name) BETWEEN 1 AND 100), -- trimmed; unique ignoring case across active and archived projects (index below) owner_id TEXT NOT NULL REFERENCES people(id), target_date DATE NOT NULL, -- may be in the past; the board then shows past target date (R13) start_week DATE NOT NULL, -- always a Monday: the week the project was created; never edited archived_at TIMESTAMP, -- empty while active created_by TEXT NOT NULL REFERENCES people(id), created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- One row per project per week: the owner's health and note for that week. Revising replaces the row's values. -- App rule (R1): only the project's current owner posts or revises; admins get no exception. -- App rule (R2): only the current week, computed on the server in the team time zone, can be posted or revised. -- App rule (R5): the app never writes health on its own or copies it into a week without an update. CREATE TABLE updates ( id TEXT PRIMARY KEY, project_id TEXT NOT NULL REFERENCES projects(id), week_start DATE NOT NULL, -- always a Monday in the team time zone health TEXT NOT NULL CHECK (health IN ('on_track', 'at_risk', 'blocked')), -- shown as On track, At risk, Blocked note TEXT NOT NULL CHECK (length(note) BETWEEN 1 AND 500), -- trimmed, line breaks turned into spaces (R4) posted_by TEXT NOT NULL REFERENCES people(id), -- who saved it last; kept when the owner changes (R11) posted_at TIMESTAMP NOT NULL, -- time of the last save revision INTEGER NOT NULL DEFAULT 1 CHECK (revision >= 1), -- 1 on the first post, plus 1 on each revision UNIQUE (project_id, week_start) ); -- The append-only activity log of a project. -- App rule (R12): every action in section 7 writes its row; rows are never edited or deleted. CREATE TABLE activities ( id TEXT PRIMARY KEY, project_id TEXT NOT NULL REFERENCES projects(id), actor_id TEXT NOT NULL REFERENCES people(id), type TEXT NOT NULL CHECK (type IN ('project_created', 'project_edited', 'owner_changed', 'archived', 'restored', 'update_posted', 'update_revised')), data TEXT, -- JSON as text: old and new values, such as from and to owner or old and new health and note created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- The email outbox: one row per message, written before sending. -- App rule (section 12): a failed send is retried by the hourly job until it has had 3 attempts; a failure never blocks a save. CREATE TABLE notifications ( id TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK (kind IN ('reminder', 'report', 'owner_changed')), to_email TEXT NOT NULL, person_id TEXT REFERENCES people(id), -- empty for report recipients outside the team week_start DATE, -- the week a reminder or report is for subject TEXT NOT NULL, body TEXT NOT NULL, -- plain text status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'sent', 'logged', 'failed')), -- logged when no email provider is configured error TEXT, -- the last send error, if any attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts BETWEEN 0 AND 3), -- each send attempt adds 1; 3 in all created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, sent_at TIMESTAMP ); -- Project names are unique ignoring case (R8). CREATE UNIQUE INDEX projects_name_idx ON projects (lower(name)); -- The board and the report read updates by week. CREATE INDEX updates_week_idx ON updates (week_start); CREATE INDEX projects_owner_idx ON projects (owner_id); CREATE INDEX activities_project_idx ON activities (project_id, created_at); -- The hourly job retries failed notifications only. CREATE INDEX notifications_failed_idx ON notifications (created_at) WHERE status = 'failed';