Skip to main content

max / makenotwork

2.5 KB · 50 lines History Blame Raw
1 -- Custom Pages (Phase 1 foundation): creators author their own HTML + CSS for
2 -- their public profile and each project page. v1 covers users and projects
3 -- only; item pages inherit their parent project's styling at render time, so
4 -- items get no columns here. See plans/custom-pages.md.
5 --
6 -- These columns hold the user's original source (shown in the editor). The
7 -- sanitized render output is regenerated on save and cached separately; Phase 1
8 -- introduces only the source columns. An empty string means "no customization,
9 -- render the platform default" -- there is no separate enabled flag. The
10 -- octet_length caps are defensive backstops behind the app-side size limits
11 -- (16KB HTML, 32KB CSS).
12
13 ALTER TABLE users
14 ADD COLUMN custom_html TEXT NOT NULL DEFAULT ''
15 CHECK (octet_length(custom_html) <= 16384),
16 ADD COLUMN custom_css TEXT NOT NULL DEFAULT ''
17 CHECK (octet_length(custom_css) <= 32768),
18 ADD COLUMN custom_pages_updated_at TIMESTAMPTZ,
19 -- Per-user moderation kill switch: while true the editor is read-only.
20 ADD COLUMN custom_pages_locked BOOLEAN NOT NULL DEFAULT FALSE;
21
22 ALTER TABLE projects
23 ADD COLUMN custom_html TEXT NOT NULL DEFAULT ''
24 CHECK (octet_length(custom_html) <= 16384),
25 ADD COLUMN custom_css TEXT NOT NULL DEFAULT ''
26 CHECK (octet_length(custom_css) <= 32768),
27 ADD COLUMN custom_pages_updated_at TIMESTAMPTZ;
28
29 -- Drafts let a creator experiment without touching the live page. One draft per
30 -- (owner, page kind, page) -- the editor upserts on this key. Drafts are
31 -- ephemeral (not git-backed); a scheduled job clears those older than 30 days
32 -- (by created_at). page_kind is 'user' or 'project'; page_id is the user or
33 -- project id. owner_id is always the editing user (the project owner for
34 -- project drafts) so a per-user cascade cleans everything on account deletion.
35 CREATE TABLE custom_page_drafts (
36 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
37 owner_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
38 page_kind TEXT NOT NULL CHECK (page_kind IN ('user', 'project')),
39 page_id UUID NOT NULL,
40 custom_html TEXT NOT NULL DEFAULT ''
41 CHECK (octet_length(custom_html) <= 16384),
42 custom_css TEXT NOT NULL DEFAULT ''
43 CHECK (octet_length(custom_css) <= 32768),
44 created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
45 updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
46 UNIQUE (owner_id, page_kind, page_id)
47 );
48
49 CREATE INDEX idx_custom_page_drafts_created_at ON custom_page_drafts (created_at);
50