-- Async Standups database schema -- Source: https://personalsoftwarefactory.com/blueprints/async-standups (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. -- A person on the team. Deactivated, never deleted. -- App rule (R13): there is always at least one active admin. CREATE TABLE people ( id TEXT PRIMARY KEY, name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 1 AND 80), email TEXT NOT NULL UNIQUE CHECK (email = LOWER(email)), -- stored lowercase time_zone TEXT NOT NULL DEFAULT 'America/New_York', -- IANA name; the schedule zone for local-timing standups is_admin BOOLEAN NOT NULL DEFAULT FALSE, active BOOLEAN NOT NULL DEFAULT TRUE, created_at TIMESTAMP NOT NULL ); -- One standup: its schedule, reminder, summary and Slack settings. -- App rule (R3): prompt_time plus reminder_minutes must be earlier than due_time. CREATE TABLE standups ( id TEXT PRIMARY KEY, name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 1 AND 60), status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'paused')), paused_at TIMESTAMP, visibility TEXT NOT NULL CHECK (visibility IN ('team', 'members')), timing TEXT NOT NULL CHECK (timing IN ('local', 'fixed')), -- local: each member's own zone; fixed: time_zone below time_zone TEXT NOT NULL, -- IANA name; the zone for fixed timing and for the summary prompt_time TEXT NOT NULL CHECK (prompt_time LIKE '__:__' AND prompt_time BETWEEN '04:00' AND '22:00'), -- HH:MM, 24-hour due_time TEXT NOT NULL CHECK (due_time LIKE '__:__' AND due_time BETWEEN '04:00' AND '22:00'), -- HH:MM, 24-hour reminder_minutes INTEGER CHECK (reminder_minutes BETWEEN 15 AND 480), -- empty means no reminder summary_time TEXT CHECK (summary_time LIKE '__:__'), -- HH:MM in time_zone, any time of day; empty means no summary slack_webhook_url TEXT, -- secret: never shown in full after saving, never exported or logged created_by TEXT NOT NULL REFERENCES people(id), created_at TIMESTAMP NOT NULL, CHECK (due_time > prompt_time), CHECK ((status = 'paused' AND paused_at IS NOT NULL) OR (status = 'active' AND paused_at IS NULL)) ); CREATE UNIQUE INDEX standups_name_uniq ON standups (LOWER(name)); -- unique ignoring case -- One weekday a standup runs on (child table of Standup.days). -- App rule (R3): every standup has at least one day. CREATE TABLE standup_days ( standup_id TEXT NOT NULL REFERENCES standups(id), weekday INTEGER NOT NULL CHECK (weekday BETWEEN 1 AND 7), -- ISO weekday: 1 = Monday, 7 = Sunday PRIMARY KEY (standup_id, weekday) ); -- One question on a standup's form. -- App rule (R3): 1 to 8 active questions per standup; a question with answers can't change its kind; archiving is final. CREATE TABLE questions ( id TEXT PRIMARY KEY, standup_id TEXT NOT NULL REFERENCES standups(id), position INTEGER NOT NULL, -- order on the form text TEXT NOT NULL CHECK (LENGTH(text) BETWEEN 1 AND 200), kind TEXT NOT NULL CHECK (kind IN ('text', 'choice', 'blocker')), required BOOLEAN NOT NULL, archived_at TIMESTAMP, -- archived questions leave new forms; their answers stay CHECK (kind <> 'blocker' OR required = TRUE) -- a blocker question is always required ); CREATE INDEX questions_standup_idx ON questions (standup_id, position); CREATE UNIQUE INDEX questions_one_blocker ON questions (standup_id) WHERE kind = 'blocker' AND archived_at IS NULL; -- R3: at most one active blocker question -- One option of a choice question (child table of Question.options). -- App rule (R3): choice questions have 2 to 6 options; only choice questions have options. CREATE TABLE question_options ( question_id TEXT NOT NULL REFERENCES questions(id), position INTEGER NOT NULL, -- button order label TEXT NOT NULL CHECK (LENGTH(label) BETWEEN 1 AND 40), -- stored trimmed PRIMARY KEY (question_id, position) ); CREATE UNIQUE INDEX question_options_label_uniq ON question_options (question_id, LOWER(label)); -- options differ ignoring case -- A person's place in a standup, with their flags. -- App rule (R4): removing a member, or unticking reports, deletes their open check-ins that have no submission. CREATE TABLE members ( id TEXT PRIMARY KEY, standup_id TEXT NOT NULL REFERENCES standups(id), person_id TEXT NOT NULL REFERENCES people(id), reports BOOLEAN NOT NULL, -- gets check-ins is_manager BOOLEAN NOT NULL, email_summary BOOLEAN NOT NULL, joined_at TIMESTAMP NOT NULL, -- set when added or re-added; never changed by flag edits removed_at TIMESTAMP, UNIQUE (standup_id, person_id) ); -- One member's check-in for one standup and one report date. Created only by the scheduled job. -- App rule (section 6): prompt_at, due_at and closes_at are computed once with the time zone database for the report date, never by adding fixed offsets. -- App rule (section 7): missed and away are final; on_time and late can be edited until closes_at. CREATE TABLE check_ins ( id TEXT PRIMARY KEY, standup_id TEXT NOT NULL REFERENCES standups(id), person_id TEXT NOT NULL REFERENCES people(id), report_date DATE NOT NULL, -- calendar date in schedule_zone schedule_zone TEXT NOT NULL, -- IANA zone used, copied at creation prompt_at TIMESTAMP NOT NULL, -- report_date at prompt_time in schedule_zone due_at TIMESTAMP NOT NULL, -- report_date at due_time in schedule_zone closes_at TIMESTAMP NOT NULL, -- the next day at 00:00 in schedule_zone status TEXT NOT NULL CHECK (status IN ('open', 'on_time', 'late', 'missed', 'away')), prompted_at TIMESTAMP, -- when the prompt was queued; empty when created as away reminded_at TIMESTAMP, nudged_at TIMESTAMP, -- R14: once per check-in nudged_by TEXT REFERENCES people(id), submitted_at TIMESTAMP, -- first submission; decides on_time (at or before due_at) or late (R7) edited_at TIMESTAMP, -- last edit created_at TIMESTAMP NOT NULL, UNIQUE (standup_id, person_id, report_date), CHECK (prompt_at < due_at AND due_at < closes_at), CHECK ((status IN ('on_time', 'late') AND submitted_at IS NOT NULL) OR (status NOT IN ('on_time', 'late') AND submitted_at IS NULL)), CHECK (edited_at IS NULL OR submitted_at IS NOT NULL), CHECK ((nudged_at IS NULL AND nudged_by IS NULL) OR (nudged_at IS NOT NULL AND nudged_by IS NOT NULL)) ); CREATE INDEX check_ins_report_date_idx ON check_ins (standup_id, report_date); CREATE INDEX check_ins_open_idx ON check_ins (closes_at) WHERE status = 'open'; -- One answer to one question in a check-in. Keeps its own copy of the question text. CREATE TABLE answers ( id TEXT PRIMARY KEY, check_in_id TEXT NOT NULL REFERENCES check_ins(id), question_id TEXT NOT NULL REFERENCES questions(id), question_text TEXT NOT NULL, -- copied when saved kind TEXT NOT NULL CHECK (kind IN ('text', 'choice', 'blocker')), -- copied when saved text TEXT CHECK (LENGTH(text) <= 2000), -- for a blocker question, the answer text from section 8 ("Blocked: ...") choice TEXT, blocker_action TEXT CHECK (blocker_action IN ('none', 'blocked', 'still_blocked', 'unblocked', 'blocked_other')), -- blocker questions only blocker_text TEXT CHECK (LENGTH(blocker_text) BETWEEN 1 AND 500), -- the new blocker's description UNIQUE (check_in_id, question_id), CHECK (kind = 'choice' OR choice IS NULL), CHECK (kind <> 'choice' OR text IS NULL), CHECK (kind = 'blocker' OR blocker_action IS NULL), CHECK (CASE WHEN blocker_action IN ('blocked', 'blocked_other') THEN blocker_text IS NOT NULL ELSE blocker_text IS NULL END) -- R8: a new blocker needs a description ); -- One blocker a person reported in a standup, open until someone resolves it. -- App rule (R11): resolved by the person, a current manager of the standup or an admin; a resolved blocker is never reopened. CREATE TABLE blockers ( id TEXT PRIMARY KEY, standup_id TEXT NOT NULL REFERENCES standups(id), person_id TEXT NOT NULL REFERENCES people(id), text TEXT NOT NULL CHECK (LENGTH(text) BETWEEN 1 AND 500), opened_check_in_id TEXT NOT NULL REFERENCES check_ins(id), opened_on DATE NOT NULL, -- report date opened_at TIMESTAMP NOT NULL, -- submitted_at of the opening check-in last_reported_on DATE NOT NULL, -- report date of the latest "Still blocked" status TEXT NOT NULL CHECK (status IN ('open', 'resolved')), resolved_at TIMESTAMP, resolved_by TEXT REFERENCES people(id), resolved_check_in_id TEXT REFERENCES check_ins(id), -- set when resolved from a report resolution_note TEXT CHECK (LENGTH(resolution_note) <= 300), -- optional CHECK ((status = 'open' AND resolved_at IS NULL AND resolved_by IS NULL AND resolved_check_in_id IS NULL AND resolution_note IS NULL) OR (status = 'resolved' AND resolved_at IS NOT NULL AND resolved_by IS NOT NULL)), CHECK (last_reported_on >= opened_on) ); CREATE UNIQUE INDEX blockers_one_open ON blockers (standup_id, person_id) WHERE status = 'open'; -- R10: one open blocker per person per standup -- One out-of-office period of a person; applies to every standup they report in. -- App rule (R12): at most 90 days counting both ends; periods of one person never overlap; the start is not before today. CREATE TABLE out_of_office ( id TEXT PRIMARY KEY, person_id TEXT NOT NULL REFERENCES people(id), start_date DATE NOT NULL, -- inclusive report date end_date DATE NOT NULL, -- inclusive report date note TEXT CHECK (LENGTH(note) <= 100), -- optional created_at TIMESTAMP NOT NULL, CHECK (end_date >= start_date) ); CREATE INDEX out_of_office_person_idx ON out_of_office (person_id, start_date); -- One outgoing email or Slack post in the outbox. CREATE TABLE notifications ( id TEXT PRIMARY KEY, channel TEXT NOT NULL CHECK (channel IN ('email', 'slack')), kind TEXT NOT NULL CHECK (kind IN ('prompt', 'reminder', 'nudge', 'report_post', 'blocker_opened', 'blocker_resolved', 'summary')), standup_id TEXT NOT NULL REFERENCES standups(id), person_id TEXT REFERENCES people(id), -- empty for Slack to_address TEXT NOT NULL, -- the spec's "to": an email address, or "Slack: " check_in_id TEXT REFERENCES check_ins(id) ON DELETE SET NULL, -- cleared when R4 deletes the check-in; the row stays subject TEXT NOT NULL, body TEXT NOT NULL, -- plain text, unescaped status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'sent', 'logged', 'failed')), -- logged = no email provider; not an attempt attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts BETWEEN 0 AND 5), -- each send attempt adds 1; retried until 5 last_error TEXT, -- "HTTP 404: no_team" or the error message, never the webhook URL created_at TIMESTAMP NOT NULL, sent_at TIMESTAMP ); CREATE INDEX notifications_status_idx ON notifications (status, attempts); -- One daily summary already sent for a standup and report date; makes the job safe to repeat. CREATE TABLE summary_runs ( id TEXT PRIMARY KEY, standup_id TEXT NOT NULL REFERENCES standups(id), report_date DATE NOT NULL, -- in the standup's time_zone created_at TIMESTAMP NOT NULL, UNIQUE (standup_id, report_date) );