-- Feature Requests database schema -- Source: https://personalsoftwarefactory.com/blueprints/feature-requests (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. -- Where the spec stores "a customer or a team member" (comment author, status change by, event actor), there are two columns: the kind and the id. -- Board 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, board_title TEXT NOT NULL, from_email TEXT, -- the From address of the board's emails company_domain TEXT NOT NULL, -- team emails; these sign in to the admin area, never as customers posts_per_day_limit INTEGER NOT NULL DEFAULT 5 CHECK (posts_per_day_limit >= 0) -- per customer per rolling 24 hours; 0 turns customer posting off ); -- Someone on the product team. -- App rule (section 4): only admins hide items, import accounts, change MRR, publish changelog entries and open the Outbox. CREATE TABLE team_members ( id TEXT PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE, -- on company_domain role TEXT NOT NULL CHECK (role IN ('admin', 'member')), active BOOLEAN NOT NULL DEFAULT TRUE ); -- A paying customer company, imported from your account list. Revenue behind a post is computed from these rows. CREATE TABLE accounts ( id TEXT PRIMARY KEY, company TEXT NOT NULL, domain TEXT NOT NULL UNIQUE, -- customers are matched to an account by email domain mrr_cents INTEGER NOT NULL CHECK (mrr_cents >= 0) -- monthly revenue in cents; imported as dollars ); -- A customer who signed in with a one-time email link. Created at the first sign-in. -- App rule (R1): account_id is matched by email domain at every sign-in and after every accounts import. CREATE TABLE customers ( id TEXT PRIMARY KEY, email TEXT NOT NULL UNIQUE, -- lowercase name TEXT, -- optional; refusals use the first name, or the email when no name is known account_id TEXT REFERENCES accounts(id), -- NULL when the domain matches no account created_at TIMESTAMP NOT NULL, unsubscribed_at TIMESTAMP, -- set: no status, merge, changelog or comment emails (sign-in links still go) CHECK (email = lower(email)) ); -- An idea on the board. Posted by a customer or by a team member. -- App rule (R5): at most posts_per_day_limit new posts per customer in a rolling 24 hours. -- App rule (section 6): merging into itself, an already merged idea or a hidden idea is refused; votes follow to the final target. CREATE TABLE posts ( id TEXT PRIMARY KEY, number INTEGER NOT NULL UNIQUE, -- shown to people: #1, #2 title TEXT NOT NULL CHECK (length(title) BETWEEN 8 AND 120), body TEXT, author_customer_id TEXT REFERENCES customers(id), author_team_id TEXT REFERENCES team_members(id), status TEXT NOT NULL DEFAULT 'under_review' CHECK (status IN ('under_review', 'planned', 'in_progress', 'shipped', 'declined')), status_note TEXT, -- the latest status change's note; a change without a note clears it merged_into_id TEXT REFERENCES posts(id), -- set: this post is a merged duplicate and redirects to the target hidden BOOLEAN NOT NULL DEFAULT FALSE, -- hidden by an admin (R8) created_at TIMESTAMP NOT NULL, CHECK ((author_customer_id IS NULL) <> (author_team_id IS NULL)), -- exactly one author CHECK (status <> 'declined' OR status_note IS NOT NULL), -- declining requires a public reason CHECK (merged_into_id IS NULL OR merged_into_id <> id) ); -- One customer's vote on one post. Shipped and declined posts take no new votes (app rule). CREATE TABLE votes ( post_id TEXT NOT NULL REFERENCES posts(id), customer_id TEXT NOT NULL REFERENCES customers(id), created_at TIMESTAMP NOT NULL, added_by_team_id TEXT REFERENCES team_members(id), -- set when a team member voted on the customer's behalf (R7) note TEXT, -- where a vote on the customer's behalf came from; required for those, absent otherwise PRIMARY KEY (post_id, customer_id), CHECK ((added_by_team_id IS NULL) = (note IS NULL)) ); -- A customer following a post, for status and comment emails. CREATE TABLE follows ( post_id TEXT NOT NULL REFERENCES posts(id), customer_id TEXT NOT NULL REFERENCES customers(id), created_at TIMESTAMP NOT NULL, PRIMARY KEY (post_id, customer_id) ); -- A comment on a post. Internal comments are team-only and never send email. CREATE TABLE comments ( id TEXT PRIMARY KEY, post_id TEXT NOT NULL REFERENCES posts(id), author_kind TEXT NOT NULL CHECK (author_kind IN ('customer', 'team')), author_id TEXT NOT NULL, -- a customers.id or team_members.id, by author_kind body TEXT NOT NULL, internal BOOLEAN NOT NULL DEFAULT FALSE, hidden BOOLEAN NOT NULL DEFAULT FALSE, created_at TIMESTAMP NOT NULL, CHECK (internal = FALSE OR author_kind = 'team') ); -- One change of a post's status. Append-only (R10). -- The spec gives this entity no id; id is added so every row has a primary key, like the spec's other append-only logs. -- The spec's fields "from" and "to" are reserved words in SQL, so they are from_status and to_status. CREATE TABLE status_changes ( id TEXT PRIMARY KEY, post_id TEXT NOT NULL REFERENCES posts(id), from_status TEXT NOT NULL CHECK (from_status IN ('under_review', 'planned', 'in_progress', 'shipped', 'declined')), to_status TEXT NOT NULL CHECK (to_status IN ('under_review', 'planned', 'in_progress', 'shipped', 'declined')), note TEXT, by_kind TEXT NOT NULL CHECK (by_kind IN ('customer', 'team')), by_id TEXT NOT NULL, at TIMESTAMP NOT NULL, CHECK (from_status <> to_status), -- choosing the status an idea already has is refused CHECK (to_status <> 'declined' OR note IS NOT NULL) ); CREATE INDEX status_changes_post ON status_changes (post_id, at); -- A changelog entry. A draft until published; a published entry is never edited, deleted or published again. CREATE TABLE changelog_entries ( id TEXT PRIMARY KEY, title TEXT NOT NULL, body TEXT, published_at TIMESTAMP -- NULL while a draft ); -- The spec's post_ids list: one shipped post linked from a changelog entry. -- App rule (R6): only shipped posts that are not merged or hidden can be linked. CREATE TABLE changelog_entry_posts ( changelog_entry_id TEXT NOT NULL REFERENCES changelog_entries(id), post_id TEXT NOT NULL REFERENCES posts(id), PRIMARY KEY (changelog_entry_id, post_id) ); -- Audit log entry. Append-only (R10); exports write one too. CREATE TABLE events ( id TEXT PRIMARY KEY, at TIMESTAMP NOT NULL, actor_kind TEXT CHECK (actor_kind IN ('customer', 'team')), actor_id TEXT, -- a customers.id or team_members.id, by actor_kind type TEXT NOT NULL, data TEXT, -- details as JSON text CHECK ((actor_kind IS NULL) = (actor_id IS NULL)) ); -- An email in the outbox. Written here first, then sent; the Outbox lists newest first and blanks out sign-in links. CREATE TABLE notifications ( id TEXT PRIMARY KEY, 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 error TEXT, created_at TIMESTAMP NOT NULL ); -- A one-time sign-in link: valid for 15 minutes and used once (R1). Only the hash of the token is stored. -- App rule (section 13): at most 5 links per email per rolling 60 minutes. CREATE TABLE sign_in_links ( id TEXT PRIMARY KEY, email TEXT NOT NULL, token_hash TEXT NOT NULL UNIQUE, -- never the link itself created_at TIMESTAMP NOT NULL, expires_at TIMESTAMP NOT NULL, used_at TIMESTAMP ); CREATE INDEX sign_in_links_email ON sign_in_links (email, created_at); -- A signed-in session for a customer or a team member; lasts 30 days. CREATE TABLE sessions ( id TEXT PRIMARY KEY, customer_id TEXT REFERENCES customers(id), team_member_id TEXT REFERENCES team_members(id), created_at TIMESTAMP NOT NULL, expires_at TIMESTAMP NOT NULL, CHECK ((customer_id IS NULL) <> (team_member_id IS NULL)) -- exactly one );