diff --git a/CLAUDE.md b/CLAUDE.md index 53fb340..03bf6c6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -89,8 +89,8 @@ Descriptor-driven: `server/src/admin-crud.js` and `server/src/admin-schema/` (se - `admin-cli.js` imports `ROLES` and `destroyAllSessionsFor` from `auth.js`. Keep it that way to prevent drift. ## Migrations -- `server/src/migrations/023_schema.sql` is the baseline: the whole schema, consolidated from the old 001–023. It only runs on an empty database; the runner refuses a database between v1 and v22. It's the place to read the schema, not to change it: a database that already exists never re-runs it. -- Changes go in new sequential files after it: `024_`, `025_`, ... +- `server/src/migrations/066_schema.sql` is the baseline: the whole schema, consolidated on 2026-10-04 from the old 023–066 (generated from the live schema, so the comments are the ones inside each table). `066_seed.sql` runs right after it with the least a new database needs (single rows, event scopes, the site pages' sections, the Musicians tag); content is typed in through the admin. Both only run on an empty database; the runner refuses a database between v1 and v65 (bring it to v66 with a release from before the consolidation first). It's the place to read the schema, not to change it: a database that already exists never re-runs it. +- Changes go in new sequential files after it: `067_`, `068_`, ... - The runner may drop statements after a `BEGIN...END` trigger body. Keep triggers last in a file, and put each `CREATE VIEW` before any trigger or in its own file. - The runner turns foreign keys off around every migration (it can't be done inside the file's transaction) and runs `PRAGMA foreign_key_check` before committing, so a table rebuild needs no `PRAGMA foreign_keys` of its own. When views or triggers name the table being rebuilt, wrap the drop-and-rename in `PRAGMA legacy_alter_table = ON` ... `OFF`, then recreate the rebuilt table's own indexes and triggers. diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index 6800fbd..cb2fa80 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -56,7 +56,7 @@ each entity: And the database itself holds the final word: most fixed lists are a `CHECK (... IN (...))` constraint on the column (read them in -`server/src/migrations/023_schema.sql` and any later migration). +`server/src/migrations/066_schema.sql` and any later migration). ### Two kinds of dropdown diff --git a/server/src/db.js b/server/src/db.js index ec341d9..63a2cce 100644 --- a/server/src/db.js +++ b/server/src/db.js @@ -84,6 +84,9 @@ export function tx(db, fn) { baseline was built by those older files and has to be brought up by a release that still has them; running the baseline over it would fail halfway on CREATE TABLE, so this refuses first. + The baseline's seed shares its version (066_schema.sql, then + 066_seed.sql): `current` is read once, so an empty database + runs both and one already at that version skips both. ───────────────────────────────────────────────────────────── */ export function migrate(db, { log = console.log } = {}) { diff --git a/server/src/migrations/024_front_page_video.sql b/server/src/migrations/024_front_page_video.sql deleted file mode 100644 index 2637b43..0000000 --- a/server/src/migrations/024_front_page_video.sql +++ /dev/null @@ -1,79 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 024 FRONT PAGE: FEATURED VIDEO --- --- A fourth hero mode, 'video': a recorded video beside the words, --- the way 'livestream' puts a stream there, but without the LIVE --- badge and without autoplay: a visitor presses play. --- --- Its own two columns rather than reusing the livestream's, so a --- featured video and a stream can both be set up ahead of time and --- the mode switches between them, as photos and livestream already --- can. --- --- video_url a YouTube, Vimeo or Facebook link (turned into an --- embed), or a video file: a filename in --- public/front-page/, a /path, or an https URL ending --- in .mp4, .webm, .m4v, .mov or .ogv, which plays in --- the browser's own player --- video_title shown after "Featured video" above the headline --- --- hero_mode's CHECK can't be altered in place, so front_page is --- rebuilt. Its children (slides, sections, stats, paths) reference --- it by name; the runner has foreign keys off, so the DROP leaves --- them alone and the rename puts front_page back underneath them. --- No view or other table's trigger names front_page, so the rename --- needs no legacy_alter_table. front_page_touch goes with the old --- table and is recreated last. --- --- PRAGMA user_version; -- reads 23 before this file --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE front_page_new ( - id TEXT PRIMARY KEY CHECK (id = 'home'), - - hero_mode TEXT NOT NULL DEFAULT 'brand' - CHECK (hero_mode IN ('brand', 'photos', 'livestream', 'video')), - eyebrow TEXT, - headline TEXT NOT NULL DEFAULT 'Next Generation of Unity', - subhead TEXT, - primary_label TEXT, - primary_url TEXT, - secondary_label TEXT, - secondary_url TEXT, - - slide_seconds INTEGER NOT NULL DEFAULT 7 - CHECK (slide_seconds BETWEEN 3 AND 60), - - livestream_url TEXT, - livestream_title TEXT, - - video_url TEXT, - video_title TEXT, - - countdown_event_id TEXT REFERENCES events (id) ON DELETE SET NULL, - - updated_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - -INSERT INTO front_page_new - (id, hero_mode, eyebrow, headline, subhead, - primary_label, primary_url, secondary_label, secondary_url, - slide_seconds, livestream_url, livestream_title, - countdown_event_id, updated_at) -SELECT - id, hero_mode, eyebrow, headline, subhead, - primary_label, primary_url, secondary_label, secondary_url, - slide_seconds, livestream_url, livestream_title, - countdown_event_id, updated_at - FROM front_page; - -DROP TABLE front_page; - -ALTER TABLE front_page_new RENAME TO front_page; - -CREATE TRIGGER front_page_touch -AFTER UPDATE ON front_page -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE front_page SET updated_at = datetime('now') WHERE id = new.id; -END; diff --git a/server/src/migrations/025_hero_backdrop_feature.sql b/server/src/migrations/025_hero_backdrop_feature.sql deleted file mode 100644 index c85e1ff..0000000 --- a/server/src/migrations/025_hero_backdrop_feature.sql +++ /dev/null @@ -1,40 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 025 HERO: BACKDROP AND FEATURE ARE SEPARATE CHOICES --- --- hero_mode answered two questions with one value: what fills the --- background (the brand animation or the photo slideshow) and what --- sits beside the words (nothing, a livestream or a featured --- video). A stream or a video could only ever sit on the brand --- backdrop. Split, any backdrop goes with any feature. --- --- hero_backdrop 'brand' | 'photos' --- hero_feature 'none' | 'livestream' | 'video' --- --- Today's modes map across exactly: photos → photos + none; --- livestream and video → brand + that feature; brand → brand + --- none. Photos mode still falls back to brand on the page when --- there are no photos, as before. --- --- ADD COLUMN takes a constant DEFAULT and a CHECK, and DROP COLUMN --- allows a column whose only constraint is its own CHECK, so no --- rebuild: front_page's children and its touch trigger are never --- touched. --- --- PRAGMA user_version; -- reads 24 before this file --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE front_page ADD COLUMN hero_backdrop TEXT NOT NULL DEFAULT 'brand' - CHECK (hero_backdrop IN ('brand', 'photos')); - -ALTER TABLE front_page ADD COLUMN hero_feature TEXT NOT NULL DEFAULT 'none' - CHECK (hero_feature IN ('none', 'livestream', 'video')); - -UPDATE front_page - SET hero_backdrop = CASE hero_mode WHEN 'photos' THEN 'photos' ELSE 'brand' END, - hero_feature = CASE hero_mode - WHEN 'livestream' THEN 'livestream' - WHEN 'video' THEN 'video' - ELSE 'none' - END; - -ALTER TABLE front_page DROP COLUMN hero_mode; diff --git a/server/src/migrations/026_countdown_filters.sql b/server/src/migrations/026_countdown_filters.sql deleted file mode 100644 index b859265..0000000 --- a/server/src/migrations/026_countdown_filters.sql +++ /dev/null @@ -1,29 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 026 COUNTDOWN: FILTER BY SCOPE AND TYPE --- --- The countdown counts to the pinned event, or else to the next --- published event that hasn't ended. These two narrow "the next --- event": National + Retreat counts down to the next national --- retreat and skips a regional class that happens sooner. Either or --- both can be left null, meaning any. A pinned event still wins --- whatever they say; the admin chose it by name. --- --- countdown_scope_id an event_scopes id. A real foreign key, --- so it can't name a scope that doesn't --- exist; ON DELETE SET NULL puts it back to --- "any" if a scope is ever removed. --- countdown_event_type the same values as events.event_type. --- Adding an event type now means widening --- this CHECK too. --- --- Plain ADD COLUMN: a REFERENCES column is allowed when its default --- is NULL, and a CHECK is allowed on any. No rebuild. --- --- PRAGMA user_version; -- reads 25 before this file --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE front_page ADD COLUMN countdown_scope_id TEXT - REFERENCES event_scopes (id) ON DELETE SET NULL; - -ALTER TABLE front_page ADD COLUMN countdown_event_type TEXT - CHECK (countdown_event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other')); diff --git a/server/src/migrations/027_listed.sql b/server/src/migrations/027_listed.sql deleted file mode 100644 index 12a9f79..0000000 --- a/server/src/migrations/027_listed.sql +++ /dev/null @@ -1,43 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 027 LISTED: PUBLISHED BUT ONLY BY LINK --- --- is_published stays the hard gate: 0 is a draft (or, for people, --- private), off the site entirely and a 404 at its own URL. --- is_listed only means anything on a published row. 0 keeps the --- record's own page working but leaves it out of every list the --- site gathers by itself: --- --- the /events, /organizations, /teams and /awards lists (and so --- every band, calendar, map and card grid built on them), a --- region's chapters, an organization's events, teams and awards, --- the /directory the QR page reads, and the front page's counts --- and next-event countdown. --- --- It still appears wherever someone attached it by hand: rosters, --- billed people, hosts, award recipients, timeline entries, and a --- countdown pinned to it by name. Each of those rows has its own --- is_public (or is_published) to hide it there. --- --- Defaults to 1, so every existing row stays listed. --- --- Plain ADD COLUMN: NOT NULL with a constant default and a CHECK is --- allowed without a rebuild, STRICT tables included. v_events reads --- e.*, so it picks the column up with no change of its own. --- --- PRAGMA user_version; -- reads 26 before this file --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE organizations ADD COLUMN is_listed INTEGER NOT NULL DEFAULT 1 - CHECK (is_listed IN (0, 1)); - -ALTER TABLE events ADD COLUMN is_listed INTEGER NOT NULL DEFAULT 1 - CHECK (is_listed IN (0, 1)); - -ALTER TABLE people ADD COLUMN is_listed INTEGER NOT NULL DEFAULT 1 - CHECK (is_listed IN (0, 1)); - -ALTER TABLE teams ADD COLUMN is_listed INTEGER NOT NULL DEFAULT 1 - CHECK (is_listed IN (0, 1)); - -ALTER TABLE awards ADD COLUMN is_listed INTEGER NOT NULL DEFAULT 1 - CHECK (is_listed IN (0, 1)); diff --git a/server/src/migrations/028_media.sql b/server/src/migrations/028_media.sql deleted file mode 100644 index 09ca066..0000000 --- a/server/src/migrations/028_media.sql +++ /dev/null @@ -1,41 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 028 MEDIA: UPLOADED IMAGES --- --- One row per file in UPLOADS_DIR (/var/lib/ngu/uploads in --- production, outside the deployed app so an rsync can't touch --- it). nginx serves the directory at /uploads/; the API only --- writes and deletes. --- --- An image field stores the file's public path, '/uploads/', --- not this row's id. That keeps every image column a plain TEXT --- that also takes a filename in public/ or a full URL, as before, --- and means media.ts needs no lookup. The cost is no foreign key: --- deleting a file a record still names leaves that record showing --- nothing (the and fallbacks already handle a missing --- file), so the Media page warns before a delete. --- --- filename the stored name: random, so it can't collide or --- be guessed from the original. '3f9c…e1.webp' --- original_name what the uploader's file was called, for the --- library's search and display --- processed 1 when resized and converted to WebP, 0 when --- kept as uploaded --- width, height null for an SVG, which has no pixel size --- --- PRAGMA user_version; -- reads 27 before this file --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE media ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - filename TEXT NOT NULL UNIQUE, - original_name TEXT NOT NULL, - content_type TEXT NOT NULL, - bytes INTEGER NOT NULL CHECK (bytes >= 0), - width INTEGER, - height INTEGER, - processed INTEGER NOT NULL DEFAULT 1 CHECK (processed IN (0, 1)), - uploaded_by INTEGER REFERENCES admin_users (id) ON DELETE SET NULL, - created_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - -CREATE INDEX media_created_idx ON media (created_at DESC); diff --git a/server/src/migrations/029_event_card_image.sql b/server/src/migrations/029_event_card_image.sql deleted file mode 100644 index 82cac9a..0000000 --- a/server/src/migrations/029_event_card_image.sql +++ /dev/null @@ -1,15 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 029 EVENTS: CARD BACKGROUND IMAGE --- --- A photo behind an event's card. The card keeps its size and its --- layout; the image covers it, under a light veil (CARD_IMAGE_VEIL --- in EventList-Cards.tsx) so the text on top stays readable. --- --- Like every image column, it holds a path: '/uploads/' from --- the media library, a bare filename in public/event-backgrounds/, --- or a full URL. Null draws the card as before. --- --- PRAGMA user_version; -- reads 28 before this file --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE events ADD COLUMN card_image TEXT; diff --git a/server/src/migrations/030_featured_cards.sql b/server/src/migrations/030_featured_cards.sql deleted file mode 100644 index 9776cae..0000000 --- a/server/src/migrations/030_featured_cards.sql +++ /dev/null @@ -1,167 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 030 FEATURED CARDS --- --- A row of cards that point somewhere: the front page's new --- 'featured' band first, and the Community page's blog posts next. --- One table for both, owned polymorphically like links and --- content_blocks, so the card's shape and the code that draws it --- are written once. owner_kind only allows 'front_page' today; --- adding an owner is a rebuild of this table, which nothing --- references, so it's a cheap one. --- --- A card is one of three kinds: --- --- record points at an event, organization, person, team or --- award. Title, image and link come from that record at --- read time, so renaming the event renames the card. --- Any of title, blurb and image filled in here overrides. --- link any URL, on the site or off it. Title and image are --- the card's own (the editor can fetch them from the --- page's preview tags). --- video a YouTube, Vimeo or Facebook link, or a video file. --- Drawn as a thumbnail that swaps in the player when --- pressed. image overrides the thumbnail. --- --- ref_kind + ref_id is checked by the triggers below, the same way --- timeline_entries' is, and a deleted record takes its cards with --- it. An unpublished record's card is left out when read. --- --- Also: 'featured' joins front_page_sections.section. A CHECK can't --- be altered in place, so that table is rebuilt. No view or trigger --- names it, and nothing references it. --- --- PRAGMA user_version; -- reads 29 before this file --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE front_page_sections_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES front_page (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - section TEXT NOT NULL - CHECK (section IN ('countdown', 'retreats', 'calendar', 'stats', - 'timeline', 'connect', 'featured')), - title TEXT, - blurb TEXT, - is_hidden INTEGER NOT NULL DEFAULT 0 CHECK (is_hidden IN (0, 1)), - UNIQUE (page_id, section) -) STRICT; - -INSERT INTO front_page_sections_new (id, page_id, sort_order, section, title, blurb, is_hidden) -SELECT id, page_id, sort_order, section, title, blurb, is_hidden - FROM front_page_sections; - -DROP TABLE front_page_sections; - -ALTER TABLE front_page_sections_new RENAME TO front_page_sections; - - -CREATE TABLE featured_cards ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL CHECK (owner_kind IN ('front_page')), - owner_id TEXT NOT NULL, - sort_order INTEGER NOT NULL DEFAULT 0, - - kind TEXT NOT NULL DEFAULT 'link' - CHECK (kind IN ('record', 'link', 'video')), - - ref_kind TEXT CHECK (ref_kind IN ('event', 'organization', 'person', 'team', 'award')), - ref_id TEXT, - url TEXT, - - eyebrow TEXT, -- 'Article', 'Watch' - title TEXT, - blurb TEXT, - image TEXT, -- '/uploads/…', a filename, or a URL - - CHECK ((ref_kind IS NULL) = (ref_id IS NULL)), - -- A record card needs its record; the other two need somewhere to - -- go. Named as sentences: the admin shows a sentence-shaped - -- constraint name as the error (wrapDbErrors in admin-crud.js). - CONSTRAINT "A record card needs a record to point at." - CHECK (kind != 'record' OR ref_kind IS NOT NULL), - CONSTRAINT "A link or video card needs a URL." - CHECK (kind = 'record' OR url IS NOT NULL) -) STRICT; - -CREATE INDEX featured_cards_owner_idx ON featured_cards (owner_kind, owner_id, sort_order); - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER featured_cards_ref_exists -BEFORE INSERT ON featured_cards -BEGIN - SELECT CASE - WHEN new.ref_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such event') - WHEN new.ref_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such organization') - WHEN new.ref_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such person') - WHEN new.ref_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such team') - WHEN new.ref_kind = 'award' - AND NOT EXISTS (SELECT 1 FROM awards WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such award') - END; -END; - -CREATE TRIGGER featured_cards_ref_exists_update -BEFORE UPDATE OF ref_kind, ref_id ON featured_cards -BEGIN - SELECT CASE - WHEN new.ref_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such event') - WHEN new.ref_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such organization') - WHEN new.ref_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such person') - WHEN new.ref_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such team') - WHEN new.ref_kind = 'award' - AND NOT EXISTS (SELECT 1 FROM awards WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such award') - END; -END; - --- A deleted record takes the cards that point at it. Separate --- triggers rather than additions to the existing *_cleanup ones, so --- this file doesn't have to drop and restate those. - -CREATE TRIGGER events_featured_cleanup -AFTER DELETE ON events -BEGIN - DELETE FROM featured_cards WHERE ref_kind = 'event' AND ref_id = old.id; -END; - -CREATE TRIGGER organizations_featured_cleanup -AFTER DELETE ON organizations -BEGIN - DELETE FROM featured_cards WHERE ref_kind = 'organization' AND ref_id = old.id; -END; - -CREATE TRIGGER people_featured_cleanup -AFTER DELETE ON people -BEGIN - DELETE FROM featured_cards WHERE ref_kind = 'person' AND ref_id = old.id; -END; - -CREATE TRIGGER teams_featured_cleanup -AFTER DELETE ON teams -BEGIN - DELETE FROM featured_cards WHERE ref_kind = 'team' AND ref_id = old.id; -END; - -CREATE TRIGGER awards_featured_cleanup -AFTER DELETE ON awards -BEGIN - DELETE FROM featured_cards WHERE ref_kind = 'award' AND ref_id = old.id; -END; diff --git a/server/src/migrations/031_blog.sql b/server/src/migrations/031_blog.sql deleted file mode 100644 index a787dde..0000000 --- a/server/src/migrations/031_blog.sql +++ /dev/null @@ -1,254 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 031 BLOG --- --- Posts of our own, at /blog/, and the Community page's blog --- section, which shows two subsections: --- --- Our posts pinned blog_posts first, then the newest --- published, listed ones, up to internal_slots --- Community posts pinned featured_cards (owner 'community_page') --- first, then the newest items from the RSS or --- Atom feeds in community_page_feeds, up to --- external_slots --- --- blog_posts --- A draft until published (is_published defaults to 0, as for --- people): a half-written post shouldn't go live by accident. --- is_listed works as it does everywhere (027): unticked, the post --- is left out of "newest" but its page works and it can be pinned. --- The body is content_blocks with owner_kind 'blog_post', slot --- 'body'. Authors are people (blog_post_authors), or a guest named --- on the post itself, or both. tags is a comma-separated list, eg. --- 'Reflection, Event recap'; it is only displayed, never joined on. --- --- content_blocks gains 'blog_post' as an owner. A CHECK can't be --- altered in place, so the table is rebuilt; the *_cleanup triggers --- on other tables name it, hence legacy_alter_table around the --- rename. Its own index and owner trigger are recreated below. --- --- featured_cards gains 'community_page' as an owner, the same way. --- Nothing names it but its own triggers, recreated below. --- --- community_page is a singleton like front_page: one row, made --- here, which the admin edits and can't delete. --- --- PRAGMA user_version; -- reads 30 before this file --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE blog_posts ( - id TEXT PRIMARY KEY, -- slug: 'finding-unity-at-camp' - title TEXT NOT NULL, - excerpt TEXT, -- the card's text; else the body's start - cover_image TEXT, -- '/uploads/…', a filename, or a URL - published_on TEXT, -- 'YYYY-MM-DD'; newest first - tags TEXT, -- 'Reflection, Event recap' - guest_author TEXT, -- someone with no people row - guest_photo TEXT, - is_published INTEGER NOT NULL DEFAULT 0 CHECK (is_published IN (0, 1)), - is_listed INTEGER NOT NULL DEFAULT 1 CHECK (is_listed IN (0, 1)), - created_at TEXT NOT NULL DEFAULT (datetime('now')), - updated_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - -CREATE INDEX blog_posts_newest_idx ON blog_posts (is_published, is_listed, published_on DESC); - -CREATE TABLE blog_post_authors ( - post_id TEXT NOT NULL REFERENCES blog_posts (id) ON DELETE CASCADE, - person_id TEXT NOT NULL REFERENCES people (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - PRIMARY KEY (post_id, person_id) -) STRICT; - -CREATE INDEX blog_post_authors_person_idx ON blog_post_authors (person_id); - - -CREATE TABLE community_page ( - id TEXT PRIMARY KEY CHECK (id = 'community'), - blog_title TEXT, -- null → 'Community Blog' - blog_blurb TEXT, - internal_title TEXT, -- null → 'From NGU' - internal_slots INTEGER NOT NULL DEFAULT 3 CHECK (internal_slots BETWEEN 0 AND 12), - external_title TEXT, -- null → 'From our community' - external_slots INTEGER NOT NULL DEFAULT 3 CHECK (external_slots BETWEEN 0 AND 12), - external_url TEXT, -- the Substack home, for its button - external_label TEXT, -- null → 'Read more on Substack' - updated_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - -INSERT INTO community_page (id) VALUES ('community'); - -CREATE TABLE community_page_pinned_posts ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES community_page (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - post_id TEXT NOT NULL REFERENCES blog_posts (id) ON DELETE CASCADE, - UNIQUE (page_id, post_id) -) STRICT; - -CREATE TABLE community_page_feeds ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES community_page (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - url TEXT NOT NULL, -- 'https://ngu.substack.com/feed' - label TEXT -- shown on its items; else the feed's own title -) STRICT; - - --- ── content_blocks: add 'blog_post' ─────────────────────────── - -CREATE TABLE content_blocks_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider')), - text TEXT, - media TEXT, - href TEXT -) STRICT; - -INSERT INTO content_blocks_new (id, owner_kind, owner_id, slot, sort_order, type, text, media, href) -SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href - FROM content_blocks; - -PRAGMA legacy_alter_table = ON; -DROP TABLE content_blocks; -ALTER TABLE content_blocks_new RENAME TO content_blocks; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); - - --- ── featured_cards: add 'community_page' ────────────────────── - -CREATE TABLE featured_cards_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL CHECK (owner_kind IN ('front_page', 'community_page')), - owner_id TEXT NOT NULL, - sort_order INTEGER NOT NULL DEFAULT 0, - - kind TEXT NOT NULL DEFAULT 'link' - CHECK (kind IN ('record', 'link', 'video')), - - ref_kind TEXT CHECK (ref_kind IN ('event', 'organization', 'person', 'team', 'award')), - ref_id TEXT, - url TEXT, - - eyebrow TEXT, - title TEXT, - blurb TEXT, - image TEXT, - - CHECK ((ref_kind IS NULL) = (ref_id IS NULL)), - CONSTRAINT "A record card needs a record to point at." - CHECK (kind != 'record' OR ref_kind IS NOT NULL), - CONSTRAINT "A link or video card needs a URL." - CHECK (kind = 'record' OR url IS NOT NULL) -) STRICT; - -INSERT INTO featured_cards_new - (id, owner_kind, owner_id, sort_order, kind, ref_kind, ref_id, url, eyebrow, title, blurb, image) -SELECT id, owner_kind, owner_id, sort_order, kind, ref_kind, ref_id, url, eyebrow, title, blurb, image - FROM featured_cards; - -PRAGMA legacy_alter_table = ON; -DROP TABLE featured_cards; -ALTER TABLE featured_cards_new RENAME TO featured_cards; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX featured_cards_owner_idx ON featured_cards (owner_kind, owner_id, sort_order); - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - WHEN new.owner_kind = 'blog_post' - AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such blog post') - END; -END; - -CREATE TRIGGER featured_cards_ref_exists -BEFORE INSERT ON featured_cards -BEGIN - SELECT CASE - WHEN new.ref_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such event') - WHEN new.ref_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such organization') - WHEN new.ref_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such person') - WHEN new.ref_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such team') - WHEN new.ref_kind = 'award' - AND NOT EXISTS (SELECT 1 FROM awards WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such award') - END; -END; - -CREATE TRIGGER featured_cards_ref_exists_update -BEFORE UPDATE OF ref_kind, ref_id ON featured_cards -BEGIN - SELECT CASE - WHEN new.ref_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such event') - WHEN new.ref_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such organization') - WHEN new.ref_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such person') - WHEN new.ref_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such team') - WHEN new.ref_kind = 'award' - AND NOT EXISTS (SELECT 1 FROM awards WHERE id = new.ref_id) - THEN RAISE(ABORT, 'featured_cards: no such award') - END; -END; - -CREATE TRIGGER blog_posts_cleanup -AFTER DELETE ON blog_posts -BEGIN - DELETE FROM content_blocks WHERE owner_kind = 'blog_post' AND owner_id = old.id; -END; - -CREATE TRIGGER blog_posts_touch -AFTER UPDATE ON blog_posts -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE blog_posts SET updated_at = datetime('now') WHERE id = new.id; -END; - -CREATE TRIGGER community_page_touch -AFTER UPDATE ON community_page -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE community_page SET updated_at = datetime('now') WHERE id = new.id; -END; diff --git a/server/src/migrations/032_content_block_types.sql b/server/src/migrations/032_content_block_types.sql deleted file mode 100644 index ccb59d5..0000000 --- a/server/src/migrations/032_content_block_types.sql +++ /dev/null @@ -1,80 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 032 CONTENT BLOCKS: VIDEO, BUTTON, CALLOUT, ALT TEXT, ATTRIBUTION --- --- Three new block types, and two columns for types that had to --- borrow one: --- --- video href is the link (YouTube, Vimeo, Facebook) or a --- video file; text is the caption; media an optional --- still. Drawn click-to-play, like a featured card. --- button text is the label, href where it goes. --- callout text in a tinted box, for a note or announcement. --- --- alt an image's alt text. text stays its caption: a --- caption describes the moment, alt describes the --- picture to someone who can't see it. --- cite who a quote is by. --- --- The type list is a CHECK, so the table is rebuilt, the same way --- 031 did (see its header): legacy_alter_table around the rename, --- because the *_cleanup triggers on other tables name it, then the --- index and the owner trigger again. --- --- PRAGMA user_version; -- reads 31 before this file --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE content_blocks_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider', - 'video', 'button', 'callout')), - text TEXT, - media TEXT, - href TEXT, - alt TEXT, - cite TEXT -) STRICT; - -INSERT INTO content_blocks_new (id, owner_kind, owner_id, slot, sort_order, type, text, media, href) -SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href - FROM content_blocks; - -PRAGMA legacy_alter_table = ON; -DROP TABLE content_blocks; -ALTER TABLE content_blocks_new RENAME TO content_blocks; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - WHEN new.owner_kind = 'blog_post' - AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such blog post') - END; -END; diff --git a/server/src/migrations/033_hero_event.sql b/server/src/migrations/033_hero_event.sql deleted file mode 100644 index ae50122..0000000 --- a/server/src/migrations/033_hero_event.sql +++ /dev/null @@ -1,34 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 033 HERO: A FEATURED EVENT --- --- A fourth hero feature, 'event': an event's card beside the --- headline, over whichever backdrop is chosen. --- --- hero_event_id the event to feature. Null means the event the --- countdown shows (its pin, or the next one that --- hasn't ended, narrowed by its scope and type), --- so the hero and the countdown can't disagree. --- A pinned event that is over, unpublished or --- deleted falls back the same way; ON DELETE SET --- NULL does the last one. --- --- hero_feature's CHECK gains 'event'. A CHECK can't be altered in --- place, so the column is replaced the way 025 did it: a new column --- with the new CHECK, the values copied across, the old one dropped --- and the new one renamed into its place. Nothing else names the --- column, so front_page itself needn't be rebuilt. --- --- PRAGMA user_version; -- reads 32 before this file --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE front_page ADD COLUMN hero_feature_new TEXT NOT NULL DEFAULT 'none' - CHECK (hero_feature_new IN ('none', 'livestream', 'video', 'event')); - -UPDATE front_page SET hero_feature_new = hero_feature; - -ALTER TABLE front_page DROP COLUMN hero_feature; - -ALTER TABLE front_page RENAME COLUMN hero_feature_new TO hero_feature; - -ALTER TABLE front_page ADD COLUMN hero_event_id TEXT - REFERENCES events (id) ON DELETE SET NULL; diff --git a/server/src/migrations/034_schedule_block.sql b/server/src/migrations/034_schedule_block.sql deleted file mode 100644 index 0655c1a..0000000 --- a/server/src/migrations/034_schedule_block.sql +++ /dev/null @@ -1,99 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 034 CONTENT BLOCKS: SCHEDULE --- --- A 'schedule' block: the block's items are its entries, grouped --- into one tab per day. Each entry says when, what and where, and --- folds out for more. The block's own text is an optional intro. --- --- content_block_items gains the entry's fields. A list or link-row --- block leaves them empty: --- --- day the tab it sits under, eg. 'Friday'. Tabs follow --- the order entries are in; blank means one untitled --- day, and a schedule of one day draws no tabs --- time '7:00pm', '9:00 to 10:30am': shown as typed --- location where it happens, eg. 'Main Hall' --- person_id who hosts or speaks: a people row, drawn with its --- photo and linked to its page. ON DELETE SET NULL, --- and an unpublished person isn't shown --- description the fold-out text, formatted like a paragraph --- media a graphic in the fold-out: '/uploads/…' or a URL --- map a place or address to show on a Google map in the --- fold-out, eg. 'Camp Hebron, Halifax PA' --- --- text is the entry's title, detail a line under it, url a link on --- the title, as for list items. --- --- The type list is a CHECK, so content_blocks is rebuilt the way --- 031 and 032 did it (legacy_alter_table around the rename, then --- the index and the owner trigger again). The item columns are --- plain ADD COLUMNs. --- --- PRAGMA user_version; -- reads 33 before this file --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE content_blocks_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider', - 'video', 'button', 'callout', 'schedule')), - text TEXT, - media TEXT, - href TEXT, - alt TEXT, - cite TEXT -) STRICT; - -INSERT INTO content_blocks_new - (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite) -SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite - FROM content_blocks; - -PRAGMA legacy_alter_table = ON; -DROP TABLE content_blocks; -ALTER TABLE content_blocks_new RENAME TO content_blocks; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); - -ALTER TABLE content_block_items ADD COLUMN day TEXT; -ALTER TABLE content_block_items ADD COLUMN time TEXT; -ALTER TABLE content_block_items ADD COLUMN location TEXT; -ALTER TABLE content_block_items ADD COLUMN person_id TEXT - REFERENCES people (id) ON DELETE SET NULL; -ALTER TABLE content_block_items ADD COLUMN description TEXT; -ALTER TABLE content_block_items ADD COLUMN media TEXT; -ALTER TABLE content_block_items ADD COLUMN map TEXT; - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - WHEN new.owner_kind = 'blog_post' - AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such blog post') - END; -END; diff --git a/server/src/migrations/035_site_settings.sql b/server/src/migrations/035_site_settings.sql deleted file mode 100644 index e2a38c0..0000000 --- a/server/src/migrations/035_site_settings.sql +++ /dev/null @@ -1,62 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 035 SITE SETTINGS --- --- What the site says about itself, editable in the admin (Panel → --- Site settings, superadmins only) instead of only in site.json. --- Every column is an override: null means "whatever site.json --- says", so a fresh database behaves exactly as before and the --- built index.html (made from site.json) stays a true fallback for --- when the API is down. --- --- site_name the site's name, in every title --- description the default search description --- preview_image the default link-preview image --- favicon the browser-tab icon ('/uploads/…', PNG or SVG) --- apple_touch_icon the home-screen icon on iPhones (PNG, 180px) --- indexing 'on' or 'off': whether search engines may list --- the site. Per database, so the dev server can --- say off while production says on, from one --- build. Null follows site.json's robots.index. --- --- site_setting_pages overrides a static page's title and intro --- (site.json's "pages"), one row per page that differs. The path --- must be one of site.json's pages; the admin only offers those. --- --- A singleton like front_page: one row, made here, which the admin --- edits and can't delete. --- --- PRAGMA user_version; -- reads 34 before this file --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE site_settings ( - id TEXT PRIMARY KEY CHECK (id = 'site'), - site_name TEXT, - description TEXT, - preview_image TEXT, - favicon TEXT, - apple_touch_icon TEXT, - indexing TEXT CHECK (indexing IN ('on', 'off')), - updated_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - -INSERT INTO site_settings (id) VALUES ('site'); - -CREATE TABLE site_setting_pages ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - settings_id TEXT NOT NULL REFERENCES site_settings (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - path TEXT NOT NULL, -- '/retreats' - title TEXT, - description TEXT, - UNIQUE (settings_id, path) -) STRICT; - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER site_settings_touch -AFTER UPDATE ON site_settings -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE site_settings SET updated_at = datetime('now') WHERE id = new.id; -END; diff --git a/server/src/migrations/036_clip_jobs.sql b/server/src/migrations/036_clip_jobs.sql deleted file mode 100644 index d4616db..0000000 --- a/server/src/migrations/036_clip_jobs.sql +++ /dev/null @@ -1,53 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 036 VIDEO CLIPS --- --- The admin's video clip tool (Tools → Video clips): download one of --- our videos from YouTube or Facebook, cut clips from it, and take --- them away as MP4 or MP3. One row per job, of two kinds: --- --- source a download (yt-dlp) of source_url. When done, file is --- the video in CLIPS_DIR and title/duration describe it. --- clip a cut (ffmpeg) of a source: params holds the JSON --- { start, end, shape, focus, format }. When done, file --- is the clip in CLIPS_DIR. --- --- Jobs run one at a time, oldest queued first (server/src/clips.js). --- A job left 'running' by a restart is marked failed at boot. --- --- Files are temporary. A clip's file is deleted once it has been --- downloaded, unless it was saved to the media library first --- (saved_media_id), and anything older than a day is swept, sources --- included. Deleting a source deletes its clips. --- --- PRAGMA user_version; -- reads 35 before this file --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE clip_jobs ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - kind TEXT NOT NULL CHECK (kind IN ('source', 'clip')), - status TEXT NOT NULL DEFAULT 'queued' - CHECK (status IN ('queued', 'running', 'done', 'failed')), - progress REAL NOT NULL DEFAULT 0 CHECK (progress BETWEEN 0 AND 1), - - source_url TEXT, -- kind 'source' - source_id INTEGER REFERENCES clip_jobs (id) ON DELETE CASCADE, -- kind 'clip' - params TEXT, -- kind 'clip': JSON - - title TEXT, - duration REAL, -- seconds - file TEXT, -- a name in CLIPS_DIR, once done - bytes INTEGER, - error TEXT, - saved_media_id INTEGER REFERENCES media (id) ON DELETE SET NULL, - downloaded_at TEXT, -- a clip's file went out, and was deleted - - created_by INTEGER REFERENCES admin_users (id) ON DELETE SET NULL, - created_at TEXT NOT NULL DEFAULT (datetime('now')), - finished_at TEXT, - - CHECK ((kind = 'source') = (source_url IS NOT NULL)), - CHECK ((kind = 'clip') = (source_id IS NOT NULL)) -) STRICT; - -CREATE INDEX clip_jobs_queue_idx ON clip_jobs (status, id); -CREATE INDEX clip_jobs_source_idx ON clip_jobs (source_id); diff --git a/server/src/migrations/037_leadership_published_orgs.sql b/server/src/migrations/037_leadership_published_orgs.sql deleted file mode 100644 index cd3a3cf..0000000 --- a/server/src/migrations/037_leadership_published_orgs.sql +++ /dev/null @@ -1,39 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 037 LEADERSHIP VIEW: PUBLISHED HOME ORGS ONLY --- --- v_org_leadership named a person's primary organization even when --- that organization was unpublished, so a draft org's name could --- show on a public leadership list. It now joins published ones --- only; an unpublished one reads as no primary org. --- ═══════════════════════════════════════════════════════════════ - -DROP VIEW v_org_leadership; - -CREATE VIEW v_org_leadership AS -SELECT - a.org_id, - a.team_id, - t.name AS team_name, - t.sort_order AS team_sort_order, - a.person_id, - a.title, - a.role, - a.is_owner, - a.sort_order, - p.display_name, - p.sort_name, - p.pronouns, - p.tagline, - p.photo, - p.public_email, - p.location_label, - p.bio, - o.id AS primary_org_id, - o.name AS primary_org_name -FROM affiliations a -JOIN people p ON p.id = a.person_id AND p.is_published = 1 -LEFT JOIN teams t ON t.id = a.team_id -LEFT JOIN organizations o ON o.id = p.primary_org_id AND o.is_published = 1 -WHERE a.is_public = 1 - AND a.ended_on IS NULL -ORDER BY a.org_id, a.is_owner DESC, a.sort_order, p.sort_name; diff --git a/server/src/migrations/038_image_alt_text.sql b/server/src/migrations/038_image_alt_text.sql deleted file mode 100644 index cff6a0d..0000000 --- a/server/src/migrations/038_image_alt_text.sql +++ /dev/null @@ -1,13 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 038 ALT TEXT FOR BLOG COVERS AND SCHEDULE GRAPHICS --- --- Both images can carry information (a flyer, a site map, a cover --- photo that sets the scene), so each gets its own description for --- screen readers. Blank means decorative: the image is skipped. --- --- blog_posts.cover_alt the cover image's description --- content_block_items.media_alt a schedule entry graphic's --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE blog_posts ADD COLUMN cover_alt TEXT; -ALTER TABLE content_block_items ADD COLUMN media_alt TEXT; diff --git a/server/src/migrations/039_privacy_contact.sql b/server/src/migrations/039_privacy_contact.sql deleted file mode 100644 index 4e37428..0000000 --- a/server/src/migrations/039_privacy_contact.sql +++ /dev/null @@ -1,11 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 039 PRIVACY CONTACT --- --- The address the Privacy page gives for privacy questions and data --- requests (Panel → Site settings). Null falls back to site.json's --- privacyEmail; blank in both, the page points to its request form --- only. Data requests themselves are feedback rows of type --- 'privacy' (routes/feedback.js), triaged in Admin → Feedback. --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE site_settings ADD COLUMN privacy_email TEXT; diff --git a/server/src/migrations/040_drop_event_gradient.sql b/server/src/migrations/040_drop_event_gradient.sql deleted file mode 100644 index 3282ab1..0000000 --- a/server/src/migrations/040_drop_event_gradient.sql +++ /dev/null @@ -1,12 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 040 NO MORE CARD GRADIENTS --- --- An event card is its photo (card_image) under a light veil, or a --- plain card, always with the event's colour as its border. The --- gradient layer went over the photo and hid it, and gradients are --- leaving the design, so the column goes. Any gradient saved on an --- event is dropped with it; the card falls back to its photo or the --- plain surface. --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE events DROP COLUMN gradient; diff --git a/server/src/migrations/041_site_colors.sql b/server/src/migrations/041_site_colors.sql deleted file mode 100644 index 30cc48f..0000000 --- a/server/src/migrations/041_site_colors.sql +++ /dev/null @@ -1,28 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 041 SITE COLOURS --- --- The admin's palette (Panel → Site settings → Colours): one row per --- colour token that differs from the site's own (src/index.css), with --- a light and a dark value. Blank keeps that mode's default. The --- server writes them into every page (server/src/theme.js) and --- refuses a save that would make text hard to read. --- --- token one of the tokens in THEME_DEFAULTS (theme.js), which --- the admin's dropdown offers --- light '#rrggbb', or null for the default --- dark '#rrggbb', or null for the default --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE site_setting_colors ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - settings_id TEXT NOT NULL REFERENCES site_settings (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - token TEXT NOT NULL CHECK (token IN ( - 'ink', 'body', 'muted', 'link', 'brand', 'action', 'action-hover', - 'surface', 'tint', 'tint-soft', 'danger', 'danger-tint')), - light TEXT CONSTRAINT "A colour must be written #rrggbb, eg. #0f7183." - CHECK (light IS NULL OR (length(light) = 7 AND light GLOB '#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]')), - dark TEXT CONSTRAINT "A dark colour must be written #rrggbb, eg. #5ccbdc." - CHECK (dark IS NULL OR (length(dark) = 7 AND dark GLOB '#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]')), - UNIQUE (settings_id, token) -) STRICT; diff --git a/server/src/migrations/042_person_awards_index.sql b/server/src/migrations/042_person_awards_index.sql deleted file mode 100644 index 2c8b10d..0000000 --- a/server/src/migrations/042_person_awards_index.sql +++ /dev/null @@ -1,10 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 042 AWARD RECIPIENTS BY AWARD --- --- person_awards is read by award (an award's page lists its --- recipients, an organization counts them), but its only index --- starts with person_id, so those reads scan the table. Tiny today; --- this keeps it from mattering later. --- ═══════════════════════════════════════════════════════════════ - -CREATE INDEX person_awards_award_idx ON person_awards (award_id); diff --git a/server/src/migrations/043_blog_contents.sql b/server/src/migrations/043_blog_contents.sql deleted file mode 100644 index 2064521..0000000 --- a/server/src/migrations/043_blog_contents.sql +++ /dev/null @@ -1,10 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 043 A POST'S TABLE OF CONTENTS --- --- Blog posts → "Show contents": list the post's headings beside it --- (a fold-out on phones), the one being read lit. Off unless an --- editor turns it on, since a short post doesn't need one. --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE blog_posts ADD COLUMN show_contents INTEGER NOT NULL DEFAULT 0 - CHECK (show_contents IN (0, 1)); diff --git a/server/src/migrations/044_table_block.sql b/server/src/migrations/044_table_block.sql deleted file mode 100644 index 121b902..0000000 --- a/server/src/migrations/044_table_block.sql +++ /dev/null @@ -1,72 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 044 TABLE BLOCKS --- --- A content block of type 'table': a grid of text, for comparison --- charts and the like (a blog post imported from Word, say). The --- grid is the block's text, one row per line, cells split by "|", --- the first row the header; cells take the same inline formatting as --- a paragraph (**bold**, *italic*, [link](url)). ContentBlocks.tsx --- draws it. --- --- Only the type's CHECK changes, and SQLite can't alter a CHECK, so --- the table is rebuilt the way 031, 032 and 034 did it --- (legacy_alter_table around the rename, then its index and owner --- trigger again). --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE content_blocks_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider', - 'video', 'button', 'callout', 'schedule', 'table')), - text TEXT, - media TEXT, - href TEXT, - alt TEXT, - cite TEXT -) STRICT; - -INSERT INTO content_blocks_new - (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite) -SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite - FROM content_blocks; - -PRAGMA legacy_alter_table = ON; -DROP TABLE content_blocks; -ALTER TABLE content_blocks_new RENAME TO content_blocks; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - WHEN new.owner_kind = 'blog_post' - AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such blog post') - END; -END; diff --git a/server/src/migrations/045_card_block.sql b/server/src/migrations/045_card_block.sql deleted file mode 100644 index 48feb2a..0000000 --- a/server/src/migrations/045_card_block.sql +++ /dev/null @@ -1,70 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 045 LINK CARD BLOCKS --- --- A content block of type 'cards': link cards, one per item, like a --- link shared in a chat. The item's text is the title, detail the --- description, url the link and media the picture (the item columns --- there already are); Fetch preview in the admin fills them. --- ContentBlocks.tsx draws it. --- --- Only the type's CHECK changes, so the table is rebuilt as 044 did --- (legacy_alter_table around the rename, then its index and owner --- trigger again). --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE content_blocks_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider', - 'video', 'button', 'callout', 'schedule', 'table', 'cards')), - text TEXT, - media TEXT, - href TEXT, - alt TEXT, - cite TEXT -) STRICT; - -INSERT INTO content_blocks_new - (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite) -SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite - FROM content_blocks; - -PRAGMA legacy_alter_table = ON; -DROP TABLE content_blocks; -ALTER TABLE content_blocks_new RENAME TO content_blocks; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - WHEN new.owner_kind = 'blog_post' - AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such blog post') - END; -END; diff --git a/server/src/migrations/046_content_requests.sql b/server/src/migrations/046_content_requests.sql deleted file mode 100644 index 2a22d1e..0000000 --- a/server/src/migrations/046_content_requests.sql +++ /dev/null @@ -1,39 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 046 CONTENT REQUESTS --- --- The Request form (/request): someone asks for a blog post, an --- event, or a new or updated chapter, region, partner, team, award --- or person, and can attach files (a .docx to fill in, photos). --- Requests are feedback rows of type 'content', so they share the --- admin's triage (Forms → Content requests): status, notes, delete. --- --- category what it's about (REQUEST_TYPES in --- src/data/requestTypes.ts) --- request_action 'new' or 'update' --- subject the title or name, or which record to update --- --- The files themselves live in Google Drive (googleService.js); --- feedback_files keeps Drive's id for each, and goes with its row. --- --- site_settings.notify_emails: who gets an email for each new --- content or data request (Panel → Site settings), comma separated. --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE feedback ADD COLUMN category TEXT - CHECK (category IN ('blog', 'event', 'chapter', 'region', 'partner', 'team', 'award', 'person')); -ALTER TABLE feedback ADD COLUMN request_action TEXT - CHECK (request_action IN ('new', 'update')); -ALTER TABLE feedback ADD COLUMN subject TEXT; - -CREATE TABLE feedback_files ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - feedback_id INTEGER NOT NULL REFERENCES feedback (id) ON DELETE CASCADE, - drive_id TEXT NOT NULL, - name TEXT NOT NULL, - mime TEXT NOT NULL, - size INTEGER NOT NULL -) STRICT; - -CREATE INDEX feedback_files_owner_idx ON feedback_files (feedback_id); - -ALTER TABLE site_settings ADD COLUMN notify_emails TEXT; diff --git a/server/src/migrations/047_access_groups.sql b/server/src/migrations/047_access_groups.sql deleted file mode 100644 index 0677d68..0000000 --- a/server/src/migrations/047_access_groups.sql +++ /dev/null @@ -1,29 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 047 ACCESS BY GOOGLE GROUP --- --- Admin access from Google Workspace groups (accessGroups.js). --- Panel → Site settings → Access names a group for each of viewer, --- editor and admin. Someone in one of them who signs in with Google --- gets an account with the highest of those roles, and keeps it only --- while they're in the group. Superadmins and admin-cli accounts are --- never touched. --- --- admin_users.access_source 'manual' (admin-cli, the Panel) or --- 'group' (made by a group sign-in; --- Google only, role follows the group) --- admin_users.group_disabled 1 when a group check turned it off --- (back in a group turns it on again); --- a superadmin's Disable sets 0, and --- that one sticks --- admin_users.groups_checked_at the last group check, UTC --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE admin_users ADD COLUMN access_source TEXT NOT NULL DEFAULT 'manual' - CHECK (access_source IN ('manual', 'group')); -ALTER TABLE admin_users ADD COLUMN group_disabled INTEGER NOT NULL DEFAULT 0 - CHECK (group_disabled IN (0, 1)); -ALTER TABLE admin_users ADD COLUMN groups_checked_at TEXT; - -ALTER TABLE site_settings ADD COLUMN access_group_viewer TEXT; -ALTER TABLE site_settings ADD COLUMN access_group_editor TEXT; -ALTER TABLE site_settings ADD COLUMN access_group_admin TEXT; diff --git a/server/src/migrations/048_drive_files.sql b/server/src/migrations/048_drive_files.sql deleted file mode 100644 index 710de12..0000000 --- a/server/src/migrations/048_drive_files.sql +++ /dev/null @@ -1,28 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 048 FILES IN GOOGLE DRIVE --- --- Files for the public site to link to (a handout, slides, a talk's --- audio, a brand kit), uploaded from Tools → Media → Files into the --- shared drive's "Blog" folder (routes/files.js) and shared as --- "anyone with the link can view". Content blocks link to `url`, --- Drive's page for the file. --- --- preview /uploads/... of Drive's picture of the first page, in --- the media library, once Drive has drawn one (PDFs and --- Office files); a link card to the file takes it as its --- picture --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE drive_files ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - drive_id TEXT NOT NULL UNIQUE, - name TEXT NOT NULL, - mime TEXT NOT NULL, - bytes INTEGER NOT NULL CHECK (bytes >= 0), - url TEXT NOT NULL, - preview TEXT, - uploaded_by INTEGER REFERENCES admin_users (id) ON DELETE SET NULL, - created_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - -CREATE INDEX drive_files_created_idx ON drive_files (created_at DESC); diff --git a/server/src/migrations/049_request_details.sql b/server/src/migrations/049_request_details.sql deleted file mode 100644 index 178a324..0000000 --- a/server/src/migrations/049_request_details.sql +++ /dev/null @@ -1,12 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 049 REQUEST DETAILS --- --- The Request form's details for the record it's about (a chapter's --- city, website and meeting time, an event's dates...), as one JSON --- object of strings: { "city": "Kansas City", "meets": "..." }. Which --- keys there are is src/data/requestTypes.ts's business; the server --- only checks the shape (routes/requests.js). Forms → Content --- requests shows them and opens the record's editor filled in. --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE feedback ADD COLUMN details TEXT CHECK (details IS NULL OR json_valid(details)); diff --git a/server/src/migrations/050_drive_file_folders.sql b/server/src/migrations/050_drive_file_folders.sql deleted file mode 100644 index 146a8cf..0000000 --- a/server/src/migrations/050_drive_file_folders.sql +++ /dev/null @@ -1,10 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 050 FOLDERS FOR DRIVE FILES --- --- The folder a file is in, under the shared drive's Media folder: --- '' for Media itself, 'Slides' or 'Slides/2026' below it. Made, --- renamed and deleted from Tools → Media → Files (routes/files.js); --- a file moved in Drive by hand is followed on the next look. --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE drive_files ADD COLUMN folder TEXT NOT NULL DEFAULT ''; diff --git a/server/src/migrations/051_clip_drive.sql b/server/src/migrations/051_clip_drive.sql deleted file mode 100644 index d352968..0000000 --- a/server/src/migrations/051_clip_drive.sql +++ /dev/null @@ -1,10 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 051 CLIPS SAVED TO DRIVE --- --- Tools → Video clips → Save to Drive puts a finished clip in a folder --- under the shared drive's Media folder, as a Files entry --- (drive_files, 048). The job keeps which one, as it keeps its media --- library copy in saved_media_id; a clip can be in both. --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE clip_jobs ADD COLUMN saved_drive_file_id INTEGER REFERENCES drive_files (id) ON DELETE SET NULL; diff --git a/server/src/migrations/052_groups.sql b/server/src/migrations/052_groups.sql deleted file mode 100644 index cf14851..0000000 --- a/server/src/migrations/052_groups.sql +++ /dev/null @@ -1,219 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 052 CHAPTERS BECOME GROUPS --- --- Local chapters are called groups now, everywhere: the kind value, --- the side table, the front page count, the Request form's type, the --- pages (/groups/, the Community page's #groups section). --- --- organizations.kind 'chapter' → 'group' (CHECK changes, so --- the table is rebuilt as 045 did, then --- its indexes and triggers again) --- chapters renamed groups, its index with it --- front_page_stats.source 'chapters' → 'groups' (rebuilt), and --- the seeded "Chapters" label --- feedback.category 'chapter' → 'group' (a column CHECK --- only, so a new column replaces it) --- links in records the site's own /chapters/ and --- #chapters links, in link columns and --- [text](url) formatting --- --- Names and prose written in the admin (an organization called --- "Lynnwood Chapter", a post's paragraph) are left as written. --- ═══════════════════════════════════════════════════════════════ - --- ── organizations.kind ───────────────────────────────────────── - -CREATE TABLE organizations_new ( - id TEXT PRIMARY KEY, -- slug: 'northwest', 'lynnwood' - kind TEXT NOT NULL - CHECK (kind IN ('national', 'region', 'group', 'partner')), - - name TEXT NOT NULL, - short_name TEXT, - tagline TEXT, -- one line, for the card - color TEXT, - logo TEXT, -- an upload's filename - - venue TEXT, - address TEXT, - locality TEXT, - state_code TEXT, -- US only - country TEXT NOT NULL DEFAULT 'US', - location_label TEXT, - latitude REAL, - longitude REAL, - is_online INTEGER NOT NULL DEFAULT 0 CHECK (is_online IN (0, 1)), - - is_published INTEGER NOT NULL DEFAULT 1 CHECK (is_published IN (0, 1)), - sort_order INTEGER NOT NULL DEFAULT 0, - created_at TEXT NOT NULL DEFAULT (datetime('now')), - updated_at TEXT NOT NULL DEFAULT (datetime('now')), - in_timeline INTEGER NOT NULL DEFAULT 0 CHECK (in_timeline IN (0, 1)), - is_listed INTEGER NOT NULL DEFAULT 1 CHECK (is_listed IN (0, 1)) -) STRICT; - -INSERT INTO organizations_new - (id, kind, name, short_name, tagline, color, logo, - venue, address, locality, state_code, country, location_label, - latitude, longitude, is_online, - is_published, sort_order, created_at, updated_at, in_timeline, is_listed) -SELECT id, CASE kind WHEN 'chapter' THEN 'group' ELSE kind END, - name, short_name, tagline, color, logo, - venue, address, locality, state_code, country, location_label, - latitude, longitude, is_online, - is_published, sort_order, created_at, updated_at, in_timeline, is_listed - FROM organizations; - -PRAGMA legacy_alter_table = ON; -DROP TABLE organizations; -ALTER TABLE organizations_new RENAME TO organizations; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX organizations_kind_idx ON organizations (kind, is_published, sort_order); -CREATE INDEX organizations_state_idx ON organizations (state_code); - - --- ── chapters → groups ────────────────────────────────────────── - -ALTER TABLE chapters RENAME TO groups; -DROP INDEX chapters_region_idx; -CREATE INDEX groups_region_idx ON groups (region_id); - - --- ── front_page_stats.source ──────────────────────────────────── - -CREATE TABLE front_page_stats_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES front_page (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - label TEXT NOT NULL, - source TEXT NOT NULL DEFAULT 'manual' - CHECK (source IN ('manual', 'years_since', 'regions', 'groups', - 'partners', 'events_held', 'retreats_held', - 'people', 'awards_given')), - value TEXT, - suffix TEXT, -- '+', 'k', ' states' - note TEXT -) STRICT; - -INSERT INTO front_page_stats_new - (id, page_id, sort_order, label, source, value, suffix, note) -SELECT id, page_id, sort_order, - CASE label WHEN 'Chapters' THEN 'Groups' ELSE label END, - CASE source WHEN 'chapters' THEN 'groups' ELSE source END, - value, suffix, note - FROM front_page_stats; - -PRAGMA legacy_alter_table = ON; -DROP TABLE front_page_stats; -ALTER TABLE front_page_stats_new RENAME TO front_page_stats; -PRAGMA legacy_alter_table = OFF; - - --- ── feedback.category ────────────────────────────────────────── - -ALTER TABLE feedback ADD COLUMN category_new TEXT - CHECK (category_new IN ('blog', 'event', 'group', 'region', 'partner', 'team', 'award', 'person')); -UPDATE feedback SET category_new = CASE category WHEN 'chapter' THEN 'group' ELSE category END; -ALTER TABLE feedback DROP COLUMN category; -ALTER TABLE feedback RENAME COLUMN category_new TO category; - -UPDATE feedback SET section_id = 'groups' WHERE section_id = 'chapters'; -UPDATE feedback SET page_path = '/groups/' || substr(page_path, 11) - WHERE page_path LIKE '/chapters/%'; - - --- ── Seeded text ──────────────────────────────────────────────── - -UPDATE front_page_path_actions SET description = 'Groups and regions across the country.' - WHERE description = 'Chapters and regions across the country.'; - -UPDATE affiliations SET title = replace(replace(title, 'Chapter', 'Group'), 'chapter', 'group') - WHERE title LIKE '%chapter%'; - - --- ── The site's own links ─────────────────────────────────────── --- A link to one of our group pages or the Community page's section: --- '/chapters/', '/community#chapters', or either on our domain. --- Someone else's site with a /chapters/ path is left alone. - -UPDATE links SET url = replace(replace(url, '/chapters/', '/groups/'), '#chapters', '#groups') - WHERE url LIKE '/chapters/%' OR url LIKE '%nextgenerationofunity.org/chapters/%' - OR url LIKE '%/community#chapters' OR url = '#chapters'; - -UPDATE content_block_items SET url = replace(replace(url, '/chapters/', '/groups/'), '#chapters', '#groups') - WHERE url LIKE '/chapters/%' OR url LIKE '%nextgenerationofunity.org/chapters/%' - OR url LIKE '%/community#chapters' OR url = '#chapters'; - -UPDATE content_blocks SET href = replace(replace(href, '/chapters/', '/groups/'), '#chapters', '#groups') - WHERE href LIKE '/chapters/%' OR href LIKE '%nextgenerationofunity.org/chapters/%' - OR href LIKE '%/community#chapters' OR href = '#chapters'; - -UPDATE featured_cards SET url = replace(replace(url, '/chapters/', '/groups/'), '#chapters', '#groups') - WHERE url LIKE '/chapters/%' OR url LIKE '%nextgenerationofunity.org/chapters/%' - OR url LIKE '%/community#chapters' OR url = '#chapters'; - -UPDATE timeline_entries SET link_url = replace(replace(link_url, '/chapters/', '/groups/'), '#chapters', '#groups') - WHERE link_url LIKE '/chapters/%' OR link_url LIKE '%nextgenerationofunity.org/chapters/%' - OR link_url LIKE '%/community#chapters' OR link_url = '#chapters'; - -UPDATE front_page_slides SET link_url = replace(replace(link_url, '/chapters/', '/groups/'), '#chapters', '#groups') - WHERE link_url LIKE '/chapters/%' OR link_url LIKE '%nextgenerationofunity.org/chapters/%' - OR link_url LIKE '%/community#chapters' OR link_url = '#chapters'; - -UPDATE front_page_path_actions SET url = replace(replace(url, '/chapters/', '/groups/'), '#chapters', '#groups') - WHERE url LIKE '/chapters/%' OR url LIKE '%nextgenerationofunity.org/chapters/%' - OR url LIKE '%/community#chapters' OR url = '#chapters'; - -UPDATE front_page SET primary_url = replace(replace(primary_url, '/chapters/', '/groups/'), '#chapters', '#groups') - WHERE primary_url LIKE '/chapters/%' OR primary_url LIKE '%nextgenerationofunity.org/chapters/%' - OR primary_url LIKE '%/community#chapters' OR primary_url = '#chapters'; - -UPDATE front_page SET secondary_url = replace(replace(secondary_url, '/chapters/', '/groups/'), '#chapters', '#groups') - WHERE secondary_url LIKE '/chapters/%' OR secondary_url LIKE '%nextgenerationofunity.org/chapters/%' - OR secondary_url LIKE '%/community#chapters' OR secondary_url = '#chapters'; - --- [text](url) formatting in block and item text. -UPDATE content_blocks - SET text = replace(replace(replace(text, '](/chapters/', '](/groups/'), - '](/community#chapters)', '](/community#groups)'), - 'nextgenerationofunity.org/chapters/', 'nextgenerationofunity.org/groups/') - WHERE text LIKE '%](/chapters/%' OR text LIKE '%](/community#chapters)%' - OR text LIKE '%nextgenerationofunity.org/chapters/%'; - -UPDATE content_block_items - SET text = replace(replace(replace(text, '](/chapters/', '](/groups/'), - '](/community#chapters)', '](/community#groups)'), - 'nextgenerationofunity.org/chapters/', 'nextgenerationofunity.org/groups/') - WHERE text LIKE '%](/chapters/%' OR text LIKE '%](/community#chapters)%' - OR text LIKE '%nextgenerationofunity.org/chapters/%'; - - --- ── Triggers last (see CLAUDE.md, Migrations) ── --- Dropping organizations took its own triggers with it. - -CREATE TRIGGER organizations_cleanup -AFTER DELETE ON organizations -BEGIN - DELETE FROM content_blocks WHERE owner_kind = 'organization' AND owner_id = old.id; - DELETE FROM links WHERE owner_kind = 'organization' AND owner_id = old.id; -END; - -CREATE TRIGGER timeline_organizations_cleanup -AFTER DELETE ON organizations -BEGIN - DELETE FROM timeline_entries WHERE ref_kind = 'organization' AND ref_id = old.id; -END; - -CREATE TRIGGER organizations_featured_cleanup -AFTER DELETE ON organizations -BEGIN - DELETE FROM featured_cards WHERE ref_kind = 'organization' AND ref_id = old.id; -END; - -CREATE TRIGGER organizations_touch -AFTER UPDATE ON organizations -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE organizations SET updated_at = datetime('now') WHERE id = new.id; -END; diff --git a/server/src/migrations/053_us_spelling.sql b/server/src/migrations/053_us_spelling.sql deleted file mode 100644 index e8d649f..0000000 --- a/server/src/migrations/053_us_spelling.sql +++ /dev/null @@ -1,34 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 053 US SPELLING IN MESSAGES --- --- The site is written in US English now. Two of 041's CHECKs are --- named with the sentence the admin shows when a save breaks them --- (admin-crud.js), and those said "colour"; the table is rebuilt to --- rename them, the same columns and rows as before. --- --- events.status keeps the value 'cancelled': it's stored data, and --- the admin and the pages show it as "canceled". --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE site_setting_colors_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - settings_id TEXT NOT NULL REFERENCES site_settings (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - token TEXT NOT NULL CHECK (token IN ( - 'ink', 'body', 'muted', 'link', 'brand', 'action', 'action-hover', - 'surface', 'tint', 'tint-soft', 'danger', 'danger-tint')), - light TEXT CONSTRAINT "A color must be written #rrggbb, eg. #0f7183." - CHECK (light IS NULL OR (length(light) = 7 AND light GLOB '#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]')), - dark TEXT CONSTRAINT "A dark color must be written #rrggbb, eg. #5ccbdc." - CHECK (dark IS NULL OR (length(dark) = 7 AND dark GLOB '#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]')), - UNIQUE (settings_id, token) -) STRICT; - -INSERT INTO site_setting_colors_new (id, settings_id, sort_order, token, light, dark) -SELECT id, settings_id, sort_order, token, light, dark - FROM site_setting_colors; - -PRAGMA legacy_alter_table = ON; -DROP TABLE site_setting_colors; -ALTER TABLE site_setting_colors_new RENAME TO site_setting_colors; -PRAGMA legacy_alter_table = OFF; diff --git a/server/src/migrations/054_people_blocks_host_teams.sql b/server/src/migrations/054_people_blocks_host_teams.sql deleted file mode 100644 index ecb39c0..0000000 --- a/server/src/migrations/054_people_blocks_host_teams.sql +++ /dev/null @@ -1,140 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 054 PEOPLE BLOCKS, HOST TEAMS, THE ORGANIZATION PAGE --- --- A content block of type 'people': a team's people tiles, people --- picked one by one (items, each with a title), or both. The team --- is a new column, content_blocks.team_id; a picked person rides on --- the item's person_id, as a schedule entry's does. ContentBlocks.tsx --- draws it with PeopleTiles. The type CHECK changes, so the table is --- rebuilt as 045 did (legacy_alter_table around the rename, then its --- index and owner trigger again). --- --- An event's organization host can name a team to show instead: --- event_hosts.team_id, any organization's team. The event page then --- reads "Hosted by " linked to the team's page. v_event_hosts --- carries it (and v_events, which reads v_event_hosts, is made again --- around it, unchanged). --- --- The Leadership page is now the Organization page, at /organization: --- a page title or intro saved for /leadership in Site settings moves --- with it. --- ═══════════════════════════════════════════════════════════════ - --- ── Host teams ───────────────────────────────────────────────── - -ALTER TABLE event_hosts ADD COLUMN team_id TEXT REFERENCES teams (id) ON DELETE SET NULL; - -DROP VIEW v_events; -DROP VIEW v_event_hosts; - -CREATE VIEW v_event_hosts AS -SELECT - eh.id, - eh.event_id, - eh.sort_order, - CASE WHEN eh.person_id IS NULL THEN 'organization' ELSE 'person' END - AS host_kind, - COALESCE(eh.org_id, eh.person_id) AS host_id, - COALESCE(o.name, p.display_name) AS host_name, - o.kind AS host_org_kind, - o.logo AS host_logo, - o.color AS host_color, - p.photo AS host_photo, - COALESCE(o.is_published, p.is_published) AS host_is_published, - t.id AS host_team_id, - t.name AS host_team_name -FROM event_hosts eh -LEFT JOIN organizations o ON o.id = eh.org_id -LEFT JOIN people p ON p.id = eh.person_id -LEFT JOIN teams t ON t.id = eh.team_id AND eh.org_id IS NOT NULL AND t.is_published = 1; - -CREATE VIEW v_events AS -SELECT - e.*, - h.host_kind, - h.host_id, - h.host_name, - h.host_org_kind, - COALESCE(e.org_logo, h.host_logo) AS effective_org_logo, - COALESCE(e.color, h.host_color) AS effective_color, - COALESCE( - e.status, - CASE WHEN e.ends_on IS NOT NULL AND e.ends_on < date('now') - THEN 'past' ELSE 'upcoming' END - ) AS effective_status -FROM events e -LEFT JOIN v_event_hosts h - ON h.id = ( - SELECT x.id - FROM v_event_hosts x - WHERE x.event_id = e.id - ORDER BY x.sort_order, x.id - LIMIT 1 - ); - - --- ── People blocks ────────────────────────────────────────────── - -CREATE TABLE content_blocks_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider', - 'video', 'button', 'callout', 'schedule', 'table', 'cards', - 'people')), - text TEXT, - media TEXT, - href TEXT, - alt TEXT, - cite TEXT, - team_id TEXT REFERENCES teams (id) ON DELETE SET NULL -) STRICT; - -INSERT INTO content_blocks_new - (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite) -SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite - FROM content_blocks; - -PRAGMA legacy_alter_table = ON; -DROP TABLE content_blocks; -ALTER TABLE content_blocks_new RENAME TO content_blocks; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); - - --- ── The Organization page ────────────────────────────────────── - -UPDATE site_setting_pages SET path = '/organization' WHERE path = '/leadership'; - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - WHEN new.owner_kind = 'blog_post' - AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such blog post') - END; -END; diff --git a/server/src/migrations/055_organization_page.sql b/server/src/migrations/055_organization_page.sql deleted file mode 100644 index 466cd82..0000000 --- a/server/src/migrations/055_organization_page.sql +++ /dev/null @@ -1,134 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 055 THE ORGANIZATION PAGE'S OWN EDITOR, NAMED PATH ICONS --- --- The Organization page (/organization) is edited in the admin like --- the Community blog section (Pages → Organization page): a --- singleton row, organization_page, with --- --- mission blocks content_blocks owned 'org_page_mission': --- the Mission, Vision & Values section --- leadership blocks content_blocks owned 'org_page_leadership': --- the Leadership section, eg. a heading and a --- People block per team (Board of Trustees, --- then the Retreat Team), in the order given --- volunteering a title, a blurb and organization_page_links, --- under the leadership --- --- Two owner kinds rather than a slot, so each list is its own --- collection in the editor. The owner_kind CHECK changes, so --- content_blocks is rebuilt as 054 did, with its index and owner --- trigger (which learns the new kinds) again. --- --- And the front page's "Find your way in" paths: the baseline seeded --- them with emoji, from before the named icon list --- (src/data/pathIcons.ts). The site now draws only named icons, so --- the seeded emoji become their names and any other non-name is --- cleared (shown as a plain dot until one is picked). --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE organization_page ( - id TEXT PRIMARY KEY CHECK (id = 'organization'), - mission_title TEXT, -- null → 'Mission, Vision & Values' - leadership_title TEXT, -- null → 'Leadership' - leadership_blurb TEXT, - volunteer_title TEXT, -- null → 'Volunteering' - volunteer_blurb TEXT, - updated_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - -INSERT INTO organization_page (id) VALUES ('organization'); - -CREATE TABLE organization_page_links ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES organization_page (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - label TEXT NOT NULL, - url TEXT NOT NULL -) STRICT; - -CREATE INDEX organization_page_links_idx ON organization_page_links (page_id, sort_order); - - --- ── Blocks for the page ──────────────────────────────────────── - -CREATE TABLE content_blocks_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post', - 'org_page_mission', 'org_page_leadership')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider', - 'video', 'button', 'callout', 'schedule', 'table', 'cards', - 'people')), - text TEXT, - media TEXT, - href TEXT, - alt TEXT, - cite TEXT, - team_id TEXT REFERENCES teams (id) ON DELETE SET NULL -) STRICT; - -INSERT INTO content_blocks_new - (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id) -SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id - FROM content_blocks; - -PRAGMA legacy_alter_table = ON; -DROP TABLE content_blocks; -ALTER TABLE content_blocks_new RENAME TO content_blocks; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); - - --- ── Path icons ───────────────────────────────────────────────── - -UPDATE front_page_paths SET icon = 'compass' WHERE icon = '🧭'; -UPDATE front_page_paths SET icon = 'hands' WHERE icon = '🤲'; -UPDATE front_page_paths SET icon = 'sparkle' WHERE icon = '🌱'; -UPDATE front_page_paths SET icon = 'people' WHERE icon = '🤝'; -UPDATE front_page_paths SET icon = NULL - WHERE icon IS NOT NULL - AND icon NOT IN ('heart', 'hands', 'people', 'calendar', 'tent', 'map', 'home', 'book', - 'learn', 'chat', 'music', 'compass', 'sparkle', 'star'); - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER organization_page_touch -AFTER UPDATE ON organization_page -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE organization_page SET updated_at = datetime('now') WHERE id = new.id; -END; - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - WHEN new.owner_kind = 'blog_post' - AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such blog post') - WHEN new.owner_kind IN ('org_page_mission', 'org_page_leadership') - AND NOT EXISTS (SELECT 1 FROM organization_page WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization page') - END; -END; diff --git a/server/src/migrations/056_site_pages.sql b/server/src/migrations/056_site_pages.sql deleted file mode 100644 index 8e72891..0000000 --- a/server/src/migrations/056_site_pages.sql +++ /dev/null @@ -1,221 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 056 PAGE EDITORS: SECTIONS FOR THE SITE'S OWN PAGES --- --- Community, Retreats, Resources, Organization and History are --- built in the admin (Pages → each page) as a list of sections. A --- section is its title (30 characters at most: it's listed in the --- page's side nav), an optional blurb, an accent and the anchor it --- sits at, and then either --- --- its own content blocks content_blocks owned 'page_section', --- owner_id the section's id --- a preset a prebuilt part of the site, drawn by --- the page (SitePage.tsx): the Community --- blog, the group map, the region list, --- the partner cards, an event list (scope, --- type and the view it opens in), the --- timeline, NGU's address and tax details --- --- Every page's sections are seeded as the code drew them, so nothing --- moves on the site. Organization takes what 055's editor held: its --- Mission and Leadership blocks, with the Volunteering title, blurb --- and links appended to the Leadership section as a heading, a --- paragraph and link buttons; 055's tables go. --- --- The Community blog's own settings (its slots, pinned posts, feeds) --- stay in community_page, now edited inside the Community page --- editor; its heading and blurb become the blog section's own, so --- community_page loses blog_title and blog_blurb. --- --- content_blocks is rebuilt for its owner_kind CHECK (as 055 did), --- moving 055's blocks across on the way. A section deleted (every --- save rewrites them) takes its blocks with it, by trigger, since --- the owner is polymorphic and can't be a foreign key. --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE site_pages ( - id TEXT PRIMARY KEY - CHECK (id IN ('community', 'retreats', 'resources', 'organization', 'history')), - updated_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - -INSERT INTO site_pages (id) VALUES ('community'), ('retreats'), ('resources'), ('organization'), ('history'); - -CREATE TABLE page_sections ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES site_pages (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - anchor TEXT NOT NULL - CONSTRAINT "A section's URL ID can use only lowercase letters, numbers and hyphens, eg. leadership." - CHECK (anchor <> '' AND anchor NOT GLOB '*[^a-z0-9-]*'), - title TEXT NOT NULL - CONSTRAINT "A section title can be 30 characters at most (it's listed in the page's side nav)." - CHECK (length(title) <= 30), - blurb TEXT, - accent TEXT CHECK (accent IN ('teal', 'deep', 'green', 'amber')), - preset TEXT CHECK (preset IN ('community_blog', 'group_map', 'region_list', 'partner_list', - 'events', 'timeline', 'organization_details')), - -- An events preset's filter and first view. - scope_id TEXT REFERENCES event_scopes (id) ON DELETE SET NULL, - event_type TEXT CHECK (event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other')), - view TEXT CHECK (view IN ('carousel', 'grid', 'map')), - UNIQUE (page_id, anchor) -) STRICT; - -CREATE INDEX page_sections_page_idx ON page_sections (page_id, sort_order); - -INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view) -SELECT 'community', 0, 'blog', COALESCE(blog_title, 'Community Blog'), blog_blurb, 'teal', 'community_blog', NULL, NULL, NULL - FROM community_page WHERE id = 'community'; - -INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view) VALUES - ('community', 1, 'groups', 'Local Groups', - 'Young adult groups meeting in person and online across the movement.', 'teal', 'group_map', NULL, NULL, 'map'), - ('community', 2, 'regions', 'Unity Regions', - 'The regional organizations that support groups and host their own gatherings.', 'deep', 'region_list', NULL, NULL, NULL), - ('community', 3, 'partners', 'Partner Organizations', - 'Organizations we collaborate with across the Unity movement and beyond.', 'amber', 'partner_list', NULL, NULL, NULL), - - ('retreats', 0, 'national', 'National Retreats', - 'Our flagship gatherings, open to young adults across the country.', 'teal', 'events', 'national', 'retreat', 'carousel'), - ('retreats', 1, 'regional', 'Regional Retreats', - 'Smaller gatherings hosted by regions throughout the year.', 'green', 'events', 'regional', 'retreat', 'grid'), - ('retreats', 2, 'partner', 'Partner Events', - 'Retreats hosted by organizations we collaborate with.', 'amber', 'events', 'partner', 'retreat', 'grid'), - - ('resources', 0, 'unity', 'Unity Teachings', - 'Core principles, readings, and study material from the Unity movement.', 'teal', NULL, NULL, NULL, NULL), - ('resources', 1, 'branding', 'Branding & Marketing', - 'Logos, colors, templates, and guidelines for representing NGU.', 'green', NULL, NULL, NULL, NULL), - ('resources', 2, 'partner', 'Partner Resources', - 'Material for the organizations we collaborate with.', 'amber', NULL, NULL, NULL, NULL), - - ('history', 0, 'timeline', 'NGU Timeline', 'Open a year to see what happened.', 'teal', 'timeline', NULL, NULL, NULL), - - ('organization', 2, 'contact', 'Details & Contact', NULL, 'deep', 'organization_details', NULL, NULL, NULL); - -INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent) -SELECT 'organization', 0, 'mission', substr(COALESCE(mission_title, 'Mission, Vision & Values'), 1, 30), NULL, 'teal' - FROM organization_page WHERE id = 'organization'; - -INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent) -SELECT 'organization', 1, 'leadership', substr(COALESCE(leadership_title, 'Leadership'), 1, 30), leadership_blurb, 'green' - FROM organization_page WHERE id = 'organization'; - -ALTER TABLE community_page DROP COLUMN blog_title; -ALTER TABLE community_page DROP COLUMN blog_blurb; - - --- ── Blocks: the new owner kind, 055's blocks moved across ────── - -CREATE TABLE content_blocks_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post', 'page_section')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider', - 'video', 'button', 'callout', 'schedule', 'table', 'cards', - 'people')), - text TEXT, - media TEXT, - href TEXT, - alt TEXT, - cite TEXT, - team_id TEXT REFERENCES teams (id) ON DELETE SET NULL -) STRICT; - -INSERT INTO content_blocks_new - (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id) -SELECT b.id, - CASE WHEN b.owner_kind IN ('org_page_mission', 'org_page_leadership') THEN 'page_section' ELSE b.owner_kind END, - CASE b.owner_kind - WHEN 'org_page_mission' THEN - (SELECT CAST(s.id AS TEXT) FROM page_sections s WHERE s.page_id = 'organization' AND s.anchor = 'mission') - WHEN 'org_page_leadership' THEN - (SELECT CAST(s.id AS TEXT) FROM page_sections s WHERE s.page_id = 'organization' AND s.anchor = 'leadership') - ELSE b.owner_id - END, - b.slot, b.sort_order, b.type, b.text, b.media, b.href, b.alt, b.cite, b.team_id - FROM content_blocks b; - -PRAGMA legacy_alter_table = ON; -DROP TABLE content_blocks; -ALTER TABLE content_blocks_new RENAME TO content_blocks; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); - --- Volunteering, appended to the Leadership section where 055 had it. -INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type, text) -SELECT 'page_section', CAST(s.id AS TEXT), 'body', 1000, 'heading', COALESCE(p.volunteer_title, 'Volunteering') - FROM organization_page p - JOIN page_sections s ON s.page_id = 'organization' AND s.anchor = 'leadership' - WHERE p.volunteer_title IS NOT NULL OR p.volunteer_blurb IS NOT NULL - OR EXISTS (SELECT 1 FROM organization_page_links); - -INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type, text) -SELECT 'page_section', CAST(s.id AS TEXT), 'body', 1001, 'paragraph', p.volunteer_blurb - FROM organization_page p - JOIN page_sections s ON s.page_id = 'organization' AND s.anchor = 'leadership' - WHERE p.volunteer_blurb IS NOT NULL; - -INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type) -SELECT 'page_section', CAST(s.id AS TEXT), 'body', 1002, 'links' - FROM page_sections s - WHERE s.page_id = 'organization' AND s.anchor = 'leadership' - AND EXISTS (SELECT 1 FROM organization_page_links); - -INSERT INTO content_block_items (block_id, sort_order, text, url) -SELECT b.id, l.sort_order, l.label, l.url - FROM organization_page_links l - JOIN content_blocks b ON b.owner_kind = 'page_section' AND b.type = 'links' AND b.sort_order = 1002; - -DROP TABLE organization_page_links; -DROP TABLE organization_page; - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER site_pages_touch -AFTER UPDATE ON site_pages -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE site_pages SET updated_at = datetime('now') WHERE id = new.id; -END; - -CREATE TRIGGER page_sections_cleanup -AFTER DELETE ON page_sections -BEGIN - DELETE FROM content_blocks WHERE owner_kind = 'page_section' AND owner_id = CAST(old.id AS TEXT); -END; - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - WHEN new.owner_kind = 'blog_post' - AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such blog post') - WHEN new.owner_kind = 'page_section' - AND NOT EXISTS (SELECT 1 FROM page_sections WHERE CAST(id AS TEXT) = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such page section') - END; -END; diff --git a/server/src/migrations/057_newsletters.sql b/server/src/migrations/057_newsletters.sql deleted file mode 100644 index 708889d..0000000 --- a/server/src/migrations/057_newsletters.sql +++ /dev/null @@ -1,111 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 057 NEWSLETTER DRAFTS --- --- Tools → Newsletter saves what it builds as a draft, to come back --- to, copy into Mailchimp again, or post as a blog post: --- --- title, intro the email's heading and opening lines --- footer the closing lines (blank: the site's name and --- address); no unsubscribe link, since Mailchimp --- adds its own --- picks what's ticked, as JSON: event ids, blog post --- ids, and the front page cards by their link --- ({"events": [...], "posts": [...], "cards": [...]}) --- blocks content_blocks owned 'newsletter': whatever is --- written for this issue, under the intro --- --- content_blocks is rebuilt for its owner_kind CHECK (as 056 did). A --- draft deleted takes its blocks with it, by trigger. --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE newsletters ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - title TEXT, - intro TEXT, - footer TEXT, - picks TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(picks)), - created_at TEXT NOT NULL DEFAULT (datetime('now')), - updated_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - - --- ── Blocks: the new owner kind ───────────────────────────────── - -CREATE TABLE content_blocks_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post', 'page_section', - 'newsletter')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider', - 'video', 'button', 'callout', 'schedule', 'table', 'cards', - 'people')), - text TEXT, - media TEXT, - href TEXT, - alt TEXT, - cite TEXT, - team_id TEXT REFERENCES teams (id) ON DELETE SET NULL -) STRICT; - -INSERT INTO content_blocks_new - (id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id) -SELECT id, owner_kind, owner_id, slot, sort_order, type, text, media, href, alt, cite, team_id - FROM content_blocks; - -PRAGMA legacy_alter_table = ON; -DROP TABLE content_blocks; -ALTER TABLE content_blocks_new RENAME TO content_blocks; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER newsletters_touch -AFTER UPDATE ON newsletters -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE newsletters SET updated_at = datetime('now') WHERE id = new.id; -END; - -CREATE TRIGGER newsletters_cleanup -AFTER DELETE ON newsletters -BEGIN - DELETE FROM content_blocks WHERE owner_kind = 'newsletter' AND owner_id = CAST(old.id AS TEXT); -END; - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - WHEN new.owner_kind = 'blog_post' - AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such blog post') - WHEN new.owner_kind = 'page_section' - AND NOT EXISTS (SELECT 1 FROM page_sections WHERE CAST(id AS TEXT) = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such page section') - WHEN new.owner_kind = 'newsletter' - AND NOT EXISTS (SELECT 1 FROM newsletters WHERE CAST(id AS TEXT) = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such newsletter') - END; -END; diff --git a/server/src/migrations/058_contact_blocks.sql b/server/src/migrations/058_contact_blocks.sql deleted file mode 100644 index 3dfdf4a..0000000 --- a/server/src/migrations/058_contact_blocks.sql +++ /dev/null @@ -1,73 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 058 DETAILS & CONTACT AS BLOCKS --- --- The Organization page's Details & Contact section was a preset --- (organization_details) drawing NGU's address, tax ID and email --- from code. It's ordinary content now, edited like any section's: --- each section that used the preset gets those details as blocks --- (the address, the nonprofit line with the tax ID, an email --- button), and the preset leaves page_sections' CHECK. --- --- page_sections is rebuilt for that CHECK, keeping its ids (its --- blocks are owned by them), with its index and cleanup trigger. --- ═══════════════════════════════════════════════════════════════ - -INSERT INTO content_blocks (owner_kind, owner_id, slot, sort_order, type, text, href) -SELECT 'page_section', CAST(s.id AS TEXT), 'body', b.sort_order, b.type, b.text, b.href - FROM page_sections s - CROSS JOIN ( - SELECT 1000 AS sort_order, 'paragraph' AS type, - '1901 NW Blue Parkway' || char(10) || 'Unity Village, MO 64065' || char(10) || - '*(Physical address, not for mail)*' AS text, - NULL AS href - UNION ALL - SELECT 1001, 'paragraph', - 'Next Generation of Unity is a qualified 501(c)(3) nonprofit organization. Tax ID: 33-2819320.', NULL - UNION ALL - SELECT 1002, 'button', 'info@nextgenerationofunity.org', 'mailto:info@nextgenerationofunity.org' - ) b - WHERE s.preset = 'organization_details'; - -UPDATE page_sections SET preset = NULL WHERE preset = 'organization_details'; - -CREATE TABLE page_sections_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES site_pages (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - anchor TEXT NOT NULL - CONSTRAINT "A section's URL ID can use only lowercase letters, numbers and hyphens, eg. leadership." - CHECK (anchor <> '' AND anchor NOT GLOB '*[^a-z0-9-]*'), - title TEXT NOT NULL - CONSTRAINT "A section title can be 30 characters at most (it's listed in the page's side nav)." - CHECK (length(title) <= 30), - blurb TEXT, - accent TEXT CHECK (accent IN ('teal', 'deep', 'green', 'amber')), - preset TEXT CHECK (preset IN ('community_blog', 'group_map', 'region_list', 'partner_list', - 'events', 'timeline')), - -- An events preset's filter and first view. - scope_id TEXT REFERENCES event_scopes (id) ON DELETE SET NULL, - event_type TEXT CHECK (event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other')), - view TEXT CHECK (view IN ('carousel', 'grid', 'map')), - UNIQUE (page_id, anchor) -) STRICT; - -INSERT INTO page_sections_new - (id, page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view) -SELECT id, page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view - FROM page_sections; - -PRAGMA legacy_alter_table = ON; -DROP TABLE page_sections; -ALTER TABLE page_sections_new RENAME TO page_sections; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX page_sections_page_idx ON page_sections (page_id, sort_order); - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER page_sections_cleanup -AFTER DELETE ON page_sections -BEGIN - DELETE FROM content_blocks WHERE owner_kind = 'page_section' AND owner_id = CAST(old.id AS TEXT); -END; diff --git a/server/src/migrations/059_events_view.sql b/server/src/migrations/059_events_view.sql deleted file mode 100644 index 64963e0..0000000 --- a/server/src/migrations/059_events_view.sql +++ /dev/null @@ -1,50 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 059 EVENTS VIEW: FIRST PUBLISHED HOST, READ DIRECTLY --- --- v_events took its host (name, logo, color) from the first row of --- v_event_hosts, published or not, so a draft partner hosting a --- published event showed in its page's structured data and preview --- image. It now takes the first published host, as loadHosts does. --- --- It also joins event_hosts, organizations and people itself: --- through the v_event_hosts view, SQLite built every host of every --- event for each lookup, even one event's page. Same columns. --- --- person_awards gets the index its event_id lookups (an event's --- awards, and the SET NULL when an event is deleted) were missing. --- ═══════════════════════════════════════════════════════════════ - -DROP VIEW v_events; - -CREATE VIEW v_events AS -SELECT - e.*, - CASE WHEN eh.id IS NULL THEN NULL - WHEN eh.person_id IS NULL THEN 'organization' ELSE 'person' END - AS host_kind, - COALESCE(eh.org_id, eh.person_id) AS host_id, - COALESCE(o.name, p.display_name) AS host_name, - o.kind AS host_org_kind, - COALESCE(e.org_logo, o.logo) AS effective_org_logo, - COALESCE(e.color, o.color) AS effective_color, - COALESCE( - e.status, - CASE WHEN e.ends_on IS NOT NULL AND e.ends_on < date('now') - THEN 'past' ELSE 'upcoming' END - ) AS effective_status -FROM events e -LEFT JOIN event_hosts eh - ON eh.id = ( - SELECT x.id - FROM event_hosts x - LEFT JOIN organizations xo ON xo.id = x.org_id - LEFT JOIN people xp ON xp.id = x.person_id - WHERE x.event_id = e.id - AND COALESCE(xo.is_published, xp.is_published) = 1 - ORDER BY x.sort_order, x.id - LIMIT 1 - ) -LEFT JOIN organizations o ON o.id = eh.org_id -LEFT JOIN people p ON p.id = eh.person_id; - -CREATE INDEX person_awards_event_idx ON person_awards (event_id); diff --git a/server/src/migrations/060_newsletter_layout.sql b/server/src/migrations/060_newsletter_layout.sql deleted file mode 100644 index d6f9286..0000000 --- a/server/src/migrations/060_newsletter_layout.sql +++ /dev/null @@ -1,47 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 060 NEWSLETTER LAYOUT --- --- A newsletter is one ordered list of parts now, each movable and --- each with its own settings (src/lib/newsletter.ts reads them): --- the header band, the title, any email block, a section of picked --- events, posts or front page cards, and the footer. It's kept as --- JSON in `layout`, the builder's only editor. --- --- That replaces 057's fixed fields (intro, footer, picks) and the --- drafts' content_blocks. 057 never reached a live database, so --- there are no drafts to carry over: the table is rebuilt keeping --- each row's id, title and dates, and its blocks are deleted. --- `title` stays as its own column, for the list of drafts. --- ═══════════════════════════════════════════════════════════════ - -DELETE FROM content_blocks WHERE owner_kind = 'newsletter'; - -DROP TRIGGER newsletters_touch; -DROP TRIGGER newsletters_cleanup; - -CREATE TABLE newsletters_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - title TEXT, - layout TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(layout) AND json_type(layout) = 'array'), - created_at TEXT NOT NULL DEFAULT (datetime('now')), - updated_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - -INSERT INTO newsletters_new (id, title, created_at, updated_at) -SELECT id, title, created_at, updated_at FROM newsletters; - --- content_blocks_owner_exists names this table. -PRAGMA legacy_alter_table = ON; -DROP TABLE newsletters; -ALTER TABLE newsletters_new RENAME TO newsletters; -PRAGMA legacy_alter_table = OFF; - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER newsletters_touch -AFTER UPDATE ON newsletters -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE newsletters SET updated_at = datetime('now') WHERE id = new.id; -END; diff --git a/server/src/migrations/061_event_photo.sql b/server/src/migrations/061_event_photo.sql deleted file mode 100644 index 66f02a9..0000000 --- a/server/src/migrations/061_event_photo.sql +++ /dev/null @@ -1,20 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 061 EVENTS: EVENT PHOTO --- --- An event's own 16:9 photo, shown whole: at the top of its page, as --- the front page's featured event, on featured cards, in newsletter --- picks and as its page's share preview. photo_alt says what it --- shows, for screen readers (blank: decoration). --- --- card_image (029) goes back to being only the faded background of --- the event's card, which crops it to the card's shape. Until now it --- did both jobs, so each event's photo starts as its card --- background, to keep the front page and previews as they were. --- --- v_events selects e.*, so it carries the new columns as it is. --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE events ADD COLUMN photo TEXT; -ALTER TABLE events ADD COLUMN photo_alt TEXT; - -UPDATE events SET photo = card_image WHERE card_image IS NOT NULL; diff --git a/server/src/migrations/062_people_tags.sql b/server/src/migrations/062_people_tags.sql deleted file mode 100644 index 9728d0c..0000000 --- a/server/src/migrations/062_people_tags.sql +++ /dev/null @@ -1,89 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 062 PEOPLE TAGS AND THE PEOPLE DIRECTORY --- --- A tag marks people for a directory, rather than making a team of --- them: Musician first, more (Speakers, Teachers) added in the admin --- (Data → People tags) with no code. --- --- person_tag_types the tags: a name, the full directory page's --- intro (/directory/) and their order --- person_tags which people carry which tags; a person's --- own repeater, so deleting a tag takes its --- rows with it (cascade) --- people.specialty one line shown in a directory, eg. "Vocals, --- piano · Gospel, folk" --- page_sections a 'people_directory' preset drawing one tag's --- people (tag_id), a short list linking to the --- full page; rebuilt for the preset CHECK as 058 --- did, then its index and trigger again --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE person_tag_types ( - id TEXT PRIMARY KEY - CONSTRAINT "A tag's URL ID can use only lowercase letters, numbers and hyphens, eg. musician." - CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'), - name TEXT NOT NULL, -- 'Musicians', the directory's title - blurb TEXT, -- the full directory page's intro - sort_order INTEGER NOT NULL DEFAULT 0 -) STRICT; - -INSERT INTO person_tag_types (id, name, blurb, sort_order) VALUES - ('musician', 'Musicians', 'Musicians in the NGU community, for services, retreats and events.', 0); - -CREATE TABLE person_tags ( - person_id TEXT NOT NULL REFERENCES people (id) ON DELETE CASCADE, - tag_id TEXT NOT NULL REFERENCES person_tag_types (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - PRIMARY KEY (person_id, tag_id) -) STRICT; - -CREATE INDEX person_tags_tag_idx ON person_tags (tag_id); - -ALTER TABLE people ADD COLUMN specialty TEXT; - - --- ── page_sections: the directory preset ──────────────────────── - -CREATE TABLE page_sections_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES site_pages (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - anchor TEXT NOT NULL - CONSTRAINT "A section's URL ID can use only lowercase letters, numbers and hyphens, eg. leadership." - CHECK (anchor <> '' AND anchor NOT GLOB '*[^a-z0-9-]*'), - title TEXT NOT NULL - CONSTRAINT "A section title can be 30 characters at most (it's listed in the page's side nav)." - CHECK (length(title) <= 30), - blurb TEXT, - accent TEXT CHECK (accent IN ('teal', 'deep', 'green', 'amber')), - preset TEXT CHECK (preset IN ('community_blog', 'group_map', 'region_list', 'partner_list', - 'events', 'timeline', 'people_directory')), - -- An events preset's filter and first view. - scope_id TEXT REFERENCES event_scopes (id) ON DELETE SET NULL, - event_type TEXT CHECK (event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other')), - view TEXT CHECK (view IN ('carousel', 'grid', 'map')), - -- A people_directory preset's tag. - tag_id TEXT REFERENCES person_tag_types (id) ON DELETE SET NULL, - UNIQUE (page_id, anchor) -) STRICT; - -INSERT INTO page_sections_new - (id, page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view) -SELECT id, page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view - FROM page_sections; - -PRAGMA legacy_alter_table = ON; -DROP TABLE page_sections; -ALTER TABLE page_sections_new RENAME TO page_sections; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX page_sections_page_idx ON page_sections (page_id, sort_order); - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER page_sections_cleanup -AFTER DELETE ON page_sections -BEGIN - DELETE FROM content_blocks WHERE owner_kind = 'page_section' AND owner_id = CAST(old.id AS TEXT); -END; diff --git a/server/src/migrations/063_ministries.sql b/server/src/migrations/063_ministries.sql deleted file mode 100644 index 1f32099..0000000 --- a/server/src/migrations/063_ministries.sql +++ /dev/null @@ -1,114 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 063 MINISTRIES --- --- A Unity ministry (a church) is an organization of its own kind, so --- the list of them is kept here and an NGU group can name the one it --- belongs to. Ministries have no page and no list on the public site: --- a group's page says "Ministry: ", linked to the ministry's --- website when it has one. --- --- organizations.kind gains 'ministry' (the CHECK changes, so the --- table is rebuilt as 052 did, then its indexes --- and triggers again) --- groups.ministry_id the group's ministry, cleared if the ministry --- is deleted; the trigger below keeps it to --- ministries --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE organizations_new ( - id TEXT PRIMARY KEY, -- slug: 'northwest', 'lynnwood' - kind TEXT NOT NULL - CHECK (kind IN ('national', 'region', 'group', 'partner', 'ministry')), - - name TEXT NOT NULL, - short_name TEXT, - tagline TEXT, -- one line, for the card - color TEXT, - logo TEXT, -- an upload's filename - - venue TEXT, - address TEXT, - locality TEXT, - state_code TEXT, -- US only - country TEXT NOT NULL DEFAULT 'US', - location_label TEXT, - latitude REAL, - longitude REAL, - is_online INTEGER NOT NULL DEFAULT 0 CHECK (is_online IN (0, 1)), - - is_published INTEGER NOT NULL DEFAULT 1 CHECK (is_published IN (0, 1)), - sort_order INTEGER NOT NULL DEFAULT 0, - created_at TEXT NOT NULL DEFAULT (datetime('now')), - updated_at TEXT NOT NULL DEFAULT (datetime('now')), - in_timeline INTEGER NOT NULL DEFAULT 0 CHECK (in_timeline IN (0, 1)), - is_listed INTEGER NOT NULL DEFAULT 1 CHECK (is_listed IN (0, 1)) -) STRICT; - -INSERT INTO organizations_new - (id, kind, name, short_name, tagline, color, logo, - venue, address, locality, state_code, country, location_label, - latitude, longitude, is_online, - is_published, sort_order, created_at, updated_at, in_timeline, is_listed) -SELECT id, kind, name, short_name, tagline, color, logo, - venue, address, locality, state_code, country, location_label, - latitude, longitude, is_online, - is_published, sort_order, created_at, updated_at, in_timeline, is_listed - FROM organizations; - -PRAGMA legacy_alter_table = ON; -DROP TABLE organizations; -ALTER TABLE organizations_new RENAME TO organizations; -PRAGMA legacy_alter_table = OFF; - -CREATE INDEX organizations_kind_idx ON organizations (kind, is_published, sort_order); -CREATE INDEX organizations_state_idx ON organizations (state_code); - - --- ── groups.ministry_id ───────────────────────────────────────── - -ALTER TABLE groups ADD COLUMN ministry_id TEXT REFERENCES organizations (id) ON DELETE SET NULL; - - --- ── Triggers last (see CLAUDE.md, Migrations) ── - -CREATE TRIGGER organizations_cleanup -AFTER DELETE ON organizations -BEGIN - DELETE FROM content_blocks WHERE owner_kind = 'organization' AND owner_id = old.id; - DELETE FROM links WHERE owner_kind = 'organization' AND owner_id = old.id; -END; - -CREATE TRIGGER timeline_organizations_cleanup -AFTER DELETE ON organizations -BEGIN - DELETE FROM timeline_entries WHERE ref_kind = 'organization' AND ref_id = old.id; -END; - -CREATE TRIGGER organizations_featured_cleanup -AFTER DELETE ON organizations -BEGIN - DELETE FROM featured_cards WHERE ref_kind = 'organization' AND ref_id = old.id; -END; - -CREATE TRIGGER organizations_touch -AFTER UPDATE ON organizations -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE organizations SET updated_at = datetime('now') WHERE id = new.id; -END; - -CREATE TRIGGER groups_ministry_kind -BEFORE INSERT ON groups -FOR EACH ROW WHEN new.ministry_id IS NOT NULL - AND (SELECT kind FROM organizations WHERE id = new.ministry_id) IS NOT 'ministry' -BEGIN - SELECT RAISE(ABORT, 'A group''s ministry must be a ministry.'); -END; - -CREATE TRIGGER groups_ministry_kind_update -BEFORE UPDATE OF ministry_id ON groups -FOR EACH ROW WHEN new.ministry_id IS NOT NULL - AND (SELECT kind FROM organizations WHERE id = new.ministry_id) IS NOT 'ministry' -BEGIN - SELECT RAISE(ABORT, 'A group''s ministry must be a ministry.'); -END; diff --git a/server/src/migrations/064_org_contacts.sql b/server/src/migrations/064_org_contacts.sql deleted file mode 100644 index 21ca21a..0000000 --- a/server/src/migrations/064_org_contacts.sql +++ /dev/null @@ -1,38 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 064 ORGANIZATION CONTACTS --- --- Who to write to at an organization, by role, so a mailing list can --- be exported (Tools → Newsletter → Recipients) filtered by role, --- kind and region. Private: never sent to the public site. --- --- contact_types the roles, made in the admin (Data → --- Contact types), eg. Minister, General --- info; none are seeded --- organization_contacts an organization's contacts, each with a --- role; its own repeater on the organization. --- A role still in use can't be deleted (the --- foreign key refuses it) --- ═══════════════════════════════════════════════════════════════ - -CREATE TABLE contact_types ( - id TEXT PRIMARY KEY - CONSTRAINT "A contact type's URL ID can use only lowercase letters, numbers and hyphens, eg. minister." - CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'), - name TEXT NOT NULL, -- 'Minister' - sort_order INTEGER NOT NULL DEFAULT 0 -) STRICT; - -CREATE TABLE organization_contacts ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - org_id TEXT NOT NULL REFERENCES organizations (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - type_id TEXT NOT NULL REFERENCES contact_types (id), - name TEXT, - email TEXT, - phone TEXT, - CONSTRAINT "A contact needs an email or a phone number." - CHECK (email IS NOT NULL OR phone IS NOT NULL) -) STRICT; - -CREATE INDEX organization_contacts_org_idx ON organization_contacts (org_id, sort_order); -CREATE INDEX organization_contacts_type_idx ON organization_contacts (type_id); diff --git a/server/src/migrations/065_analytics_reports.sql b/server/src/migrations/065_analytics_reports.sql deleted file mode 100644 index fec1e6f..0000000 --- a/server/src/migrations/065_analytics_reports.sql +++ /dev/null @@ -1,19 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 065 ANALYTICS REPORTS --- --- Plausible's numbers posted to Discord (server/src/analyticsReport.js). --- --- site_settings.report_daily 'on': yesterday's numbers each morning --- site_settings.report_weekly 'on': last week's each Monday morning --- Blank or 'off': not sent --- analytics_reports the local date each kind was last sent --- for, so a restart doesn't post twice --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE site_settings ADD COLUMN report_daily TEXT CHECK (report_daily IN ('on', 'off')); -ALTER TABLE site_settings ADD COLUMN report_weekly TEXT CHECK (report_weekly IN ('on', 'off')); - -CREATE TABLE analytics_reports ( - kind TEXT PRIMARY KEY CHECK (kind IN ('daily', 'weekly')), - sent_for TEXT NOT NULL -) STRICT; diff --git a/server/src/migrations/023_schema.sql b/server/src/migrations/066_schema.sql similarity index 57% rename from server/src/migrations/023_schema.sql rename to server/src/migrations/066_schema.sql index 56dbee4..799dd95 100644 --- a/server/src/migrations/023_schema.sql +++ b/server/src/migrations/066_schema.sql @@ -1,97 +1,28 @@ -- ═══════════════════════════════════════════════════════════════ --- 023 SCHEMA +-- 066 SCHEMA (baseline) -- --- The whole database in one file: what migrations 001–023 built, --- consolidated. A fresh database runs this and lands at v23. A --- database already at v23 skips it. One partway (v1–v22) has to be --- brought to v23 by a release from before the consolidation first; --- migrate() refuses to run this file over it (see db.js). +-- The whole schema as of v66, consolidated on 2026-10-04 from +-- 023_schema.sql and the migrations 024 to 066 after it (their +-- history is in git). Written from the live schema, so each +-- statement is exactly what SQLite keeps; the comments inside a +-- table are the ones its migrations wrote. -- --- The history of how each table got here is in git: every earlier --- migration explained itself, and the reasoning that still applies --- is kept below, next to what it explains. +-- It only runs on an empty database (see migrate() in db.js), with +-- 066_seed.sql after it. A database already at v66 skips both. One +-- between v1 and v65 has to be brought to v66 by a release from +-- before this consolidation first. Changes go in new files: 067_ ... -- --- Conventions: --- --- STRICT every table but meta, so a column declared TEXT --- refuses an integer rather than quietly storing one. --- Worth it when the writer is a web form. --- Booleans INTEGER with CHECK (x IN (0, 1)). --- Dates TEXT, 'YYYY-MM-DD'; timestamps 'YYYY-MM-DD HH:MM:SS'. --- Slugs text primary keys on anything with a URL. Immutable: --- polymorphic children (content_blocks, links, --- timeline_entries) reference their owner by free-text --- id, so renaming one would orphan them. --- updated_at kept current by a *_touch trigger, and compared by --- the admin engine on save so two editors can't silently --- overwrite each other. --- --- Order: tables with their indexes, then views, then seed rows, then --- triggers. Triggers go last because the migration runner may drop --- statements that follow a BEGIN...END body. +-- Order: each table with its indexes, then the views, then the +-- triggers (the runner wants triggers last). -- ═══════════════════════════════════════════════════════════════ - --- ── Meta ──────────────────────────────────────────────────────── --- Key/value notes about the database itself. Not STRICT: it --- predates the convention and holds nothing typed. +-- ── Tables ────────────────────────────────────────────────── CREATE TABLE meta ( key TEXT PRIMARY KEY, value TEXT NOT NULL ); - --- ═══════════════════════════════════════════════════════════════ --- ORGANIZATIONS --- ═══════════════════════════════════════════════════════════════ --- --- Regions, chapters, partners and NGU itself. They differ in a --- handful of fields, which live in side tables keyed by the same id --- (regions, chapters), so everything that points at an organization --- gets one real foreign key instead of a type/id pair SQLite can't --- check. Partners get no side table: a table holding nothing but a --- primary key is a place for confusion rather than data. --- --- location_label is the display override for what the structured --- fields can't express: "Online", "Various venues", "Unity Village, --- MO". Read it first, fall back to composing from the parts. --- --- in_timeline drives the admin's "put this on the history page" --- checkbox: ticked, the engine upserts a timeline_entries row; --- unticked, it deletes it. - -CREATE TABLE organizations ( - id TEXT PRIMARY KEY, -- slug: 'northwest', 'lynnwood' - kind TEXT NOT NULL - CHECK (kind IN ('national', 'region', 'chapter', 'partner')), - - name TEXT NOT NULL, - short_name TEXT, - tagline TEXT, -- one line, for the card - color TEXT, - logo TEXT, -- filename in public/org-logos/ - - venue TEXT, - address TEXT, - locality TEXT, - state_code TEXT, -- US only - country TEXT NOT NULL DEFAULT 'US', - location_label TEXT, - latitude REAL, - longitude REAL, - is_online INTEGER NOT NULL DEFAULT 0 CHECK (is_online IN (0, 1)), - - is_published INTEGER NOT NULL DEFAULT 1 CHECK (is_published IN (0, 1)), - sort_order INTEGER NOT NULL DEFAULT 0, - created_at TEXT NOT NULL DEFAULT (datetime('now')), - updated_at TEXT NOT NULL DEFAULT (datetime('now')), - in_timeline INTEGER NOT NULL DEFAULT 0 CHECK (in_timeline IN (0, 1)) -) STRICT; - -CREATE INDEX organizations_kind_idx ON organizations (kind, is_published, sort_order); -CREATE INDEX organizations_state_idx ON organizations (state_code); - CREATE TABLE regions ( id TEXT PRIMARY KEY REFERENCES organizations (id) ON DELETE CASCADE, scope TEXT NOT NULL @@ -99,16 +30,6 @@ CREATE TABLE regions ( map_note TEXT ) STRICT; --- Which map areas a region covers, and how much of each. --- --- area_code is a plain string matched at render time against the --- keys in mapGrid.ts. No foreign key, because the thing it points --- at isn't in this database. An unrecognised code paints nothing, --- which is how Africa and the UK exist as regions with no tile. --- --- A region owning a whole area has share 1.0 and no edge. A shared --- area gets one row per region, each naming its own slice, so --- there's no primary and secondary to keep straight. CREATE TABLE region_areas ( region_id TEXT NOT NULL REFERENCES regions (id) ON DELETE CASCADE, area_code TEXT NOT NULL, -- 'WA', 'CA', 'CANADA' @@ -117,91 +38,23 @@ CREATE TABLE region_areas ( note TEXT, -- 'north', 'Salt Lake City area' PRIMARY KEY (region_id, area_code) ) STRICT; - CREATE INDEX region_areas_area_idx ON region_areas (area_code); --- region_id is stored rather than derived from the state; deriving --- it is what forced per-chapter overrides in split states. No --- `leads` column: who runs a chapter is an affiliation, exactly as --- it is for every other organization. -CREATE TABLE chapters ( +CREATE TABLE "groups" ( id TEXT PRIMARY KEY REFERENCES organizations (id) ON DELETE CASCADE, region_id TEXT REFERENCES regions (id) ON DELETE SET NULL, meets TEXT, -- '2nd Sundays, 6:00pm' - started TEXT -- 'Since 2021' + started TEXT, -- 'Since 2021' + ministry_id TEXT REFERENCES organizations (id) ON DELETE SET NULL ) STRICT; +CREATE INDEX groups_region_idx ON groups (region_id); -CREATE INDEX chapters_region_idx ON chapters (region_id); - - --- ═══════════════════════════════════════════════════════════════ --- EVENTS --- ═══════════════════════════════════════════════════════════════ - --- Whose gathering an event is: national, regional, partner, local, --- international, other. A table rather than a CHECK because --- Retreats.tsx keys presentation (title, accent, background) on the --- id, so an unrecognised value would make an event vanish from the --- page with no error; the foreign key stops that. `name` is the --- admin dropdown's label. sort_order is scope order, widest first, --- in gaps of ten so one can be slotted in without renumbering. CREATE TABLE event_scopes ( id TEXT PRIMARY KEY, -- 'national', 'regional', 'partner' name TEXT NOT NULL, sort_order INTEGER NOT NULL DEFAULT 0 ) STRICT; --- Dates are stored three ways on purpose: --- --- starts_on / ends_on ISO dates, nullable. What sorting and the --- upcoming/past split run on. --- date_label what the card shows. Real data includes --- "March/April 2026", which no date type --- holds and no formatter should reproduce. --- status an override. Null derives from ends_on --- (effective_status in v_events), so there's --- no flag to remember to flip. --- --- event_type is what kind of gathering it is, orthogonal to --- scope_id: a region can run a class, a partner can run a retreat. --- A CHECK rather than a table because a type carries no --- presentation: an unknown value renders as its own name rather --- than disappearing. The DEFAULT is also what lets the admin clear --- the field: coerceValue omits an empty NOT NULL column rather than --- writing NULL into it. --- --- A repeating event (a weekly class, a monthly meeting) is still --- one row. is_series says the dates repeat; the series_ columns say --- how. Occurrences are never stored: they're a pure function of --- these columns plus starts_on and ends_on, worked out by the site --- (src/lib/eventSeries.ts). --- --- starts_on the first meeting, and the anchor: which week --- an every-other-week series is "on", which day --- of the month a monthly one keeps, and the --- weekday used when none is ticked --- ends_on when set, the last day it can meet, which --- also keeps effective_status right --- series_count when set, stops it after that many meetings, --- whichever comes first --- series_frequency weekly on the ticked weekdays, --- every N weeks --- monthly_date on starts_on's day of the --- month, every N months; a --- short month uses its last day --- monthly_weekday on starts_on's weekday --- position (2nd Tuesday), every --- N months; a 5th becomes "last" --- series_sun..sat one boolean per weekday, each a checkbox --- series_*_time 'HH:MM', 24-hour, local to the event. The GLOB --- is a backstop; the admin checks the range. --- --- frequency and interval are NOT NULL with defaults so a box ticked --- with nothing else filled in is still a complete schedule (weekly, --- on starts_on's weekday). All of them are ignored while is_series --- is 0. --- --- There is no sort_order: events sort by date. CREATE TABLE events ( id TEXT PRIMARY KEY, scope_id TEXT NOT NULL REFERENCES event_scopes (id), @@ -227,8 +80,6 @@ CREATE TABLE events ( org_logo TEXT, -- null → first host's logo event_logo TEXT, color TEXT, -- null → first host's, then the page's - gradient TEXT, - is_published INTEGER NOT NULL DEFAULT 1 CHECK (is_published IN (0, 1)), created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')), @@ -250,38 +101,27 @@ CREATE TABLE events ( series_start_time TEXT CHECK (series_start_time GLOB '[0-2][0-9]:[0-5][0-9]'), series_end_time TEXT CHECK (series_end_time GLOB '[0-2][0-9]:[0-5][0-9]'), series_count INTEGER CHECK (series_count >= 1) +, is_listed INTEGER NOT NULL DEFAULT 1 + CHECK (is_listed IN (0, 1)), + card_image TEXT, + photo TEXT, + photo_alt TEXT ) STRICT; - CREATE INDEX events_date_idx ON events (starts_on); CREATE INDEX events_scope_idx ON events (scope_id, is_published, starts_on); CREATE INDEX events_type_idx ON events (event_type, is_published, starts_on); --- Hosts are a list, and each is an organization or a person: a --- retreat can be run jointly by two regions, and some events are --- one person's. Two nullable foreign keys rather than a polymorphic --- kind/id pair, so the references stay real and cascade on their --- own. Deleting an organization drops it from the host list and --- leaves the event standing. --- --- The first host by sort_order supplies the logo and colour --- fallbacks in v_events. A person supplies neither (a photo is a --- headshot, not a logo), so an event hosted only by a person falls --- through to the page's default. --- --- UNIQUE (event_id, org_id, person_id) would not stop duplicates: --- SQLite treats NULLs as distinct. Two partial indexes, one per kind. CREATE TABLE event_hosts ( id INTEGER PRIMARY KEY AUTOINCREMENT, event_id TEXT NOT NULL REFERENCES events (id) ON DELETE CASCADE, org_id TEXT REFERENCES organizations (id) ON DELETE CASCADE, person_id TEXT REFERENCES people (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, + sort_order INTEGER NOT NULL DEFAULT 0, team_id TEXT REFERENCES teams (id) ON DELETE SET NULL, -- Exactly one of the two. (x IS NULL) evaluates to 0 or 1, so -- <> between them is xor. CHECK ((org_id IS NULL) <> (person_id IS NULL)) ) STRICT; - CREATE INDEX event_hosts_event_idx ON event_hosts (event_id, sort_order); CREATE INDEX event_hosts_org_idx ON event_hosts (org_id); CREATE INDEX event_hosts_person_idx ON event_hosts (person_id); @@ -290,19 +130,6 @@ CREATE UNIQUE INDEX event_hosts_org_uniq CREATE UNIQUE INDEX event_hosts_person_uniq ON event_hosts (event_id, person_id) WHERE person_id IS NOT NULL; - --- ═══════════════════════════════════════════════════════════════ --- PEOPLE --- ═══════════════════════════════════════════════════════════════ --- --- Public by design. Everything in this table can appear on a card, --- and is_published = 0 is the only thing between a row and the open --- web, hence the default of 0, unlike organizations. Anything that --- must never be served lives in person_private, so a careless --- SELECT * can't leak it. Bios and pages go in content_blocks, --- socials in links. People sort by sort_name; there is no --- sort_order. - CREATE TABLE people ( id TEXT PRIMARY KEY, -- slug: 'jane-doe' display_name TEXT NOT NULL, -- 'Jane Doe' @@ -324,15 +151,13 @@ CREATE TABLE people ( updated_at TEXT NOT NULL DEFAULT (datetime('now')), bio TEXT, primary_org_id TEXT REFERENCES organizations (id) ON DELETE SET NULL +, is_listed INTEGER NOT NULL DEFAULT 1 + CHECK (is_listed IN (0, 1)), + specialty TEXT ) STRICT; - CREATE INDEX people_sort_idx ON people (is_published, sort_name); CREATE INDEX people_primary_org ON people (primary_org_id); --- Never joined into a public response. A separate table rather than --- extra columns so the boundary is structural instead of a rule --- someone has to remember. birth_date rather than age: an age column --- is wrong within a year of being written. CREATE TABLE person_private ( person_id TEXT PRIMARY KEY REFERENCES people (id) ON DELETE CASCADE, birth_date TEXT, -- 'YYYY-MM-DD' @@ -343,12 +168,6 @@ CREATE TABLE person_private ( updated_at TEXT NOT NULL DEFAULT (datetime('now')) ) STRICT; --- A team belongs to exactly one organization: NGU national has a --- Board and a Leadership Team, a region or chapter can have its own. --- UNIQUE (id, org_id) looks redundant against the primary key, and --- is, except that it gives affiliations a composite foreign key to --- point at, which stops someone filing a person under a team --- belonging to a different organization. CREATE TABLE teams ( id TEXT PRIMARY KEY, -- slug: 'board', 'nw-leadership' org_id TEXT NOT NULL REFERENCES organizations (id) ON DELETE CASCADE, @@ -359,24 +178,12 @@ CREATE TABLE teams ( is_published INTEGER NOT NULL DEFAULT 1 CHECK (is_published IN (0, 1)), sort_order INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL DEFAULT (datetime('now')), - updated_at TEXT NOT NULL DEFAULT (datetime('now')), + updated_at TEXT NOT NULL DEFAULT (datetime('now')), is_listed INTEGER NOT NULL DEFAULT 1 + CHECK (is_listed IN (0, 1)), UNIQUE (id, org_id) ) STRICT; - CREATE INDEX teams_org_idx ON teams (org_id, sort_order); --- The leadership list for every organization. A chapter lead, a --- regional coordinator and a national board member are the same --- kind of row; only org_id differs, and one person can hold several. --- --- ended_on null means current; past roles are kept, not deleted. --- is_owner marks authority within the organization and drives --- billing order. It is deliberately orthogonal to role, and it is --- NOT an edit permission. --- --- Deleting a team that still has members fails rather than --- silently detaching them: the composite foreign key has no ON --- DELETE action. Clear or reassign the members first. CREATE TABLE affiliations ( id INTEGER PRIMARY KEY AUTOINCREMENT, person_id TEXT NOT NULL REFERENCES people (id) ON DELETE CASCADE, @@ -395,15 +202,11 @@ CREATE TABLE affiliations ( FOREIGN KEY (team_id, org_id) REFERENCES teams (id, org_id) ) STRICT; - CREATE INDEX affiliations_person_idx ON affiliations (person_id); CREATE INDEX affiliations_org_idx ON affiliations (org_id, is_public, is_owner DESC, sort_order); CREATE INDEX affiliations_team_idx ON affiliations (team_id, sort_order); --- Both the public billing (speakers, leaders) and the private record --- of who attended, told apart by is_public. It defaults to 0, so a --- new row is invisible until someone decides otherwise. CREATE TABLE event_people ( id INTEGER PRIMARY KEY AUTOINCREMENT, event_id TEXT NOT NULL REFERENCES events (id) ON DELETE CASCADE, @@ -418,14 +221,9 @@ CREATE TABLE event_people ( UNIQUE (event_id, person_id, role) ) STRICT; - CREATE INDEX event_people_event_idx ON event_people (event_id, is_public, sort_order); CREATE INDEX event_people_person_idx ON event_people (person_id); --- An award exists independently of who won it. org_id is who gives --- it: nullable, because an award can predate that decision and --- person_awards rows must survive the awarding org being deleted. --- An unpublished award is a draft, off the site entirely. CREATE TABLE awards ( id TEXT PRIMARY KEY, name TEXT NOT NULL, @@ -434,8 +232,8 @@ CREATE TABLE awards ( sort_order INTEGER NOT NULL DEFAULT 0, org_id TEXT REFERENCES organizations (id) ON DELETE SET NULL, is_published INTEGER NOT NULL DEFAULT 1 CHECK (is_published IN (0, 1)) -) STRICT; - +, is_listed INTEGER NOT NULL DEFAULT 1 + CHECK (is_listed IN (0, 1))) STRICT; CREATE INDEX awards_org_idx ON awards (org_id, sort_order); CREATE INDEX awards_published_idx ON awards (is_published, sort_order); @@ -449,44 +247,9 @@ CREATE TABLE person_awards ( is_public INTEGER NOT NULL DEFAULT 1 CHECK (is_public IN (0, 1)), UNIQUE (person_id, award_id, awarded_on) ) STRICT; - CREATE INDEX person_awards_person_idx ON person_awards (person_id); - - --- ═══════════════════════════════════════════════════════════════ --- CONTENT BLOCKS AND LINKS --- ═══════════════════════════════════════════════════════════════ --- --- Shared by the four things that own a card and a page: --- organizations, events, people and teams. A bio, an event --- description and a region's page all render through one component. --- --- owner_kind + owner_id is polymorphic, so SQLite can't hold it as --- a foreign key. The *_owner_exists triggers check it on insert and --- the *_cleanup triggers remove a deleted owner's rows. 'award' is --- not an owner kind; adding it is a table rebuild for this CHECK. --- --- slot 'card' is the short version on the tile, 'body' the full --- page. Same renderer, different query. - -CREATE TABLE content_blocks ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_kind TEXT NOT NULL - CHECK (owner_kind IN ('organization', 'event', 'person', 'team')), - owner_id TEXT NOT NULL, - slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), - sort_order INTEGER NOT NULL DEFAULT 0, - - type TEXT NOT NULL - CHECK (type IN ('heading', 'subheading', 'paragraph', - 'list', 'links', 'quote', 'image', 'divider')), - text TEXT, - media TEXT, - href TEXT -) STRICT; - -CREATE INDEX content_blocks_owner_idx - ON content_blocks (owner_kind, owner_id, slot, sort_order); +CREATE INDEX person_awards_award_idx ON person_awards (award_id); +CREATE INDEX person_awards_event_idx ON person_awards (event_id); CREATE TABLE content_block_items ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -495,8 +258,13 @@ CREATE TABLE content_block_items ( text TEXT NOT NULL, detail TEXT, url TEXT -- null → plain list item +, day TEXT, time TEXT, location TEXT, person_id TEXT + REFERENCES people (id) ON DELETE SET NULL, + description TEXT, + media TEXT, + map TEXT, + media_alt TEXT ) STRICT; - CREATE INDEX content_block_items_block_idx ON content_block_items (block_id, sort_order); @@ -514,23 +282,8 @@ CREATE TABLE links ( url TEXT NOT NULL, is_primary INTEGER NOT NULL DEFAULT 0 CHECK (is_primary IN (0, 1)) ) STRICT; - CREATE INDEX links_owner_idx ON links (owner_kind, owner_id, kind, sort_order); - --- ═══════════════════════════════════════════════════════════════ --- TIMELINE --- ═══════════════════════════════════════════════════════════════ --- --- The history page's spine. A row that points at a record holds --- almost nothing of its own: title, date and logo are read back --- from the record at query time (v_timeline), so editing the event --- edits the timeline and there is no second copy to drift. Decade --- headers are not here; they live in src/data/historyDecades.ts. --- --- ref_kind + ref_id is polymorphic, like content_blocks and links, --- and checked by the same kind of trigger. - CREATE TABLE timeline_entries ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -584,7 +337,6 @@ CREATE TABLE timeline_entries ( -- hand-authored entries are unaffected. UNIQUE (ref_kind, ref_id) ) STRICT; - CREATE INDEX timeline_entries_date_idx ON timeline_entries (is_published, occurred_on DESC); @@ -595,59 +347,9 @@ CREATE TABLE timeline_entry_people ( sort_order INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (entry_id, person_id) ) STRICT; - CREATE INDEX timeline_entry_people_person_idx ON timeline_entry_people (person_id); - --- ═══════════════════════════════════════════════════════════════ --- FRONT PAGE --- ═══════════════════════════════════════════════════════════════ --- --- The home page's editable half. One row in front_page, the CHECK --- on id makes a second one impossible, and the admin engine treats --- it as a singleton, and ordered collections hanging off it, each --- replaced wholesale on save. Nothing has a foreign key into them, --- which is what makes that safe. --- --- What stays in code: how each section looks, and the list of --- section keys. A section is a component, so the CHECK on --- front_page_sections.section is the list of components that exist; --- a row can reorder, retitle or hide one, never invent one. --- --- hero_mode is switched by hand; 'livestream' shows the embed until --- someone switches it back. countdown_event_id pins the countdown; --- null counts down to the next upcoming published event. --- --- Stats: 'manual' prints value as typed, 'years_since' reads value --- as a year and counts up from it, everything else is a COUNT the --- API runs. Adding a source is this CHECK, the enum in both --- descriptor halves, and the query in routes/home.js. - -CREATE TABLE front_page ( - id TEXT PRIMARY KEY CHECK (id = 'home'), - - hero_mode TEXT NOT NULL DEFAULT 'brand' - CHECK (hero_mode IN ('brand', 'photos', 'livestream')), - eyebrow TEXT, - headline TEXT NOT NULL DEFAULT 'Next Generation of Unity', - subhead TEXT, - primary_label TEXT, - primary_url TEXT, - secondary_label TEXT, - secondary_url TEXT, - - slide_seconds INTEGER NOT NULL DEFAULT 7 - CHECK (slide_seconds BETWEEN 3 AND 60), - - livestream_url TEXT, - livestream_title TEXT, - - countdown_event_id TEXT REFERENCES events (id) ON DELETE SET NULL, - - updated_at TEXT NOT NULL DEFAULT (datetime('now')) -) STRICT; - CREATE TABLE front_page_slides ( id INTEGER PRIMARY KEY AUTOINCREMENT, page_id TEXT NOT NULL REFERENCES front_page (id) ON DELETE CASCADE, @@ -658,34 +360,6 @@ CREATE TABLE front_page_slides ( link_url TEXT ) STRICT; -CREATE TABLE front_page_sections ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES front_page (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - section TEXT NOT NULL - CHECK (section IN ('countdown', 'retreats', 'calendar', 'stats', - 'timeline', 'connect')), - title TEXT, - blurb TEXT, - is_hidden INTEGER NOT NULL DEFAULT 0 CHECK (is_hidden IN (0, 1)), - UNIQUE (page_id, section) -) STRICT; - -CREATE TABLE front_page_stats ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - page_id TEXT NOT NULL REFERENCES front_page (id) ON DELETE CASCADE, - sort_order INTEGER NOT NULL DEFAULT 0, - label TEXT NOT NULL, - source TEXT NOT NULL DEFAULT 'manual' - CHECK (source IN ('manual', 'years_since', 'regions', 'chapters', - 'partners', 'events_held', 'retreats_held', - 'people', 'awards_given')), - value TEXT, - suffix TEXT, -- '+', 'k', ' states' - note TEXT -) STRICT; - --- The connect section's "I want to…" choices, each with its actions. CREATE TABLE front_page_paths ( id INTEGER PRIMARY KEY AUTOINCREMENT, page_id TEXT NOT NULL REFERENCES front_page (id) ON DELETE CASCADE, @@ -703,17 +377,8 @@ CREATE TABLE front_page_path_actions ( description TEXT, url TEXT NOT NULL ) STRICT; - CREATE INDEX front_page_path_actions_path_idx ON front_page_path_actions (path_id, sort_order); - --- ═══════════════════════════════════════════════════════════════ --- FEEDBACK --- ═══════════════════════════════════════════════════════════════ --- --- The public form's submissions. section_id is the page section the --- visitor picked (a subnav hash), nothing to do with events. - CREATE TABLE feedback ( id INTEGER PRIMARY KEY AUTOINCREMENT, created_at TEXT NOT NULL DEFAULT (datetime('now')), @@ -731,20 +396,11 @@ CREATE TABLE feedback ( admin_note TEXT, user_agent TEXT, ip_hash TEXT -- hashed, never the address -) STRICT; - +, request_action TEXT + CHECK (request_action IN ('new', 'update')), subject TEXT, details TEXT CHECK (details IS NULL OR json_valid(details)), category TEXT + CHECK (category IN ('blog', 'event', 'group', 'region', 'partner', 'team', 'award', 'person'))) STRICT; CREATE INDEX feedback_triage_idx ON feedback (status, created_at DESC); - --- ═══════════════════════════════════════════════════════════════ --- AUTHENTICATION --- ═══════════════════════════════════════════════════════════════ --- --- Who may sign in, and who currently is. There is no self-signup: --- accounts are created with admin-cli.js, on the box, by someone --- with shell access. No invite flow, no email delivery, no --- password-reset surface for anyone to attack. - CREATE TABLE admin_users ( id INTEGER PRIMARY KEY AUTOINCREMENT, created_at TEXT NOT NULL DEFAULT (datetime('now')), @@ -777,11 +433,12 @@ CREATE TABLE admin_users ( CHECK (role IN ('viewer', 'editor', 'admin', 'superadmin')), is_active INTEGER NOT NULL DEFAULT 1 CHECK (is_active IN (0, 1)), last_login_at TEXT +, access_source TEXT NOT NULL DEFAULT 'manual' + CHECK (access_source IN ('manual', 'group')), group_disabled INTEGER NOT NULL DEFAULT 0 + CHECK (group_disabled IN (0, 1)), + groups_checked_at TEXT ) STRICT; --- One row per active login. The cookie holds a random token; this --- table holds only its SHA-256, so a database leak doesn't hand --- anyone a working session. CREATE TABLE sessions ( id INTEGER PRIMARY KEY AUTOINCREMENT, token_hash TEXT NOT NULL UNIQUE, @@ -794,70 +451,395 @@ CREATE TABLE sessions ( user_agent TEXT, ip_hash TEXT ) STRICT; - CREATE INDEX sessions_user_idx ON sessions (user_id); CREATE INDEX sessions_expiry_idx ON sessions (expires_at); +CREATE TABLE "front_page" ( + id TEXT PRIMARY KEY CHECK (id = 'home'), --- ═══════════════════════════════════════════════════════════════ --- VIEWS --- ═══════════════════════════════════════════════════════════════ + eyebrow TEXT, + headline TEXT NOT NULL DEFAULT 'Next Generation of Unity', + subhead TEXT, + primary_label TEXT, + primary_url TEXT, + secondary_label TEXT, + secondary_url TEXT, --- Every host of every event, resolved to a name and the bits the --- fallbacks need. is_published travels with the row rather than --- being filtered here, so the public routes can hide an unpublished --- host and the admin can still see one. -CREATE VIEW v_event_hosts AS -SELECT - eh.id, - eh.event_id, - eh.sort_order, - CASE WHEN eh.person_id IS NULL THEN 'organization' ELSE 'person' END - AS host_kind, - COALESCE(eh.org_id, eh.person_id) AS host_id, - COALESCE(o.name, p.display_name) AS host_name, - o.kind AS host_org_kind, - o.logo AS host_logo, - o.color AS host_color, - p.photo AS host_photo, - COALESCE(o.is_published, p.is_published) AS host_is_published -FROM event_hosts eh -LEFT JOIN organizations o ON o.id = eh.org_id -LEFT JOIN people p ON p.id = eh.person_id; + slide_seconds INTEGER NOT NULL DEFAULT 7 + CHECK (slide_seconds BETWEEN 3 AND 60), --- Events with their fallbacks resolved, so components read one --- field: effective_org_logo and effective_color from the event or --- its first host, effective_status from status or the dates. e.* so --- a new events column reaches /events with no change here. --- --- A correlated subquery picks the first host rather than GROUP BY --- with bare columns beside MIN(sort_order): the bare-column form --- works only in SQLite and resolves a tie differently run to run. -CREATE VIEW v_events AS -SELECT - e.*, - h.host_kind, - h.host_id, - h.host_name, - h.host_org_kind, - COALESCE(e.org_logo, h.host_logo) AS effective_org_logo, - COALESCE(e.color, h.host_color) AS effective_color, - COALESCE( - e.status, - CASE WHEN e.ends_on IS NOT NULL AND e.ends_on < date('now') - THEN 'past' ELSE 'upcoming' END - ) AS effective_status -FROM events e -LEFT JOIN v_event_hosts h - ON h.id = ( - SELECT x.id - FROM v_event_hosts x - WHERE x.event_id = e.id - ORDER BY x.sort_order, x.id - LIMIT 1 - ); + livestream_url TEXT, + livestream_title TEXT, + + video_url TEXT, + video_title TEXT, + + countdown_event_id TEXT REFERENCES events (id) ON DELETE SET NULL, + + updated_at TEXT NOT NULL DEFAULT (datetime('now')) +, hero_backdrop TEXT NOT NULL DEFAULT 'brand' + CHECK (hero_backdrop IN ('brand', 'photos')), countdown_scope_id TEXT + REFERENCES event_scopes (id) ON DELETE SET NULL, countdown_event_type TEXT + CHECK (countdown_event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other')), hero_feature TEXT NOT NULL DEFAULT 'none' + CHECK (hero_feature IN ('none', 'livestream', 'video', 'event')), hero_event_id TEXT + REFERENCES events (id) ON DELETE SET NULL, + video_captions TEXT +) STRICT; + +CREATE TABLE media ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + filename TEXT NOT NULL UNIQUE, + original_name TEXT NOT NULL, + content_type TEXT NOT NULL, + bytes INTEGER NOT NULL CHECK (bytes >= 0), + width INTEGER, + height INTEGER, + processed INTEGER NOT NULL DEFAULT 1 CHECK (processed IN (0, 1)), + uploaded_by INTEGER REFERENCES admin_users (id) ON DELETE SET NULL, + created_at TEXT NOT NULL DEFAULT (datetime('now')) +) STRICT; +CREATE INDEX media_created_idx ON media (created_at DESC); + +CREATE TABLE "front_page_sections" ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + page_id TEXT NOT NULL REFERENCES front_page (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + section TEXT NOT NULL + CHECK (section IN ('countdown', 'retreats', 'calendar', 'stats', + 'timeline', 'connect', 'featured')), + title TEXT, + blurb TEXT, + is_hidden INTEGER NOT NULL DEFAULT 0 CHECK (is_hidden IN (0, 1)), + UNIQUE (page_id, section) +) STRICT; + +CREATE TABLE blog_posts ( + id TEXT PRIMARY KEY, -- slug: 'finding-unity-at-camp' + title TEXT NOT NULL, + excerpt TEXT, -- the card's text; else the body's start + cover_image TEXT, -- '/uploads/…', a filename, or a URL + published_on TEXT, -- 'YYYY-MM-DD'; newest first + tags TEXT, -- 'Reflection, Event recap' + guest_author TEXT, -- someone with no people row + guest_photo TEXT, + is_published INTEGER NOT NULL DEFAULT 0 CHECK (is_published IN (0, 1)), + is_listed INTEGER NOT NULL DEFAULT 1 CHECK (is_listed IN (0, 1)), + created_at TEXT NOT NULL DEFAULT (datetime('now')), + updated_at TEXT NOT NULL DEFAULT (datetime('now')) +, cover_alt TEXT, show_contents INTEGER NOT NULL DEFAULT 0 + CHECK (show_contents IN (0, 1))) STRICT; +CREATE INDEX blog_posts_newest_idx ON blog_posts (is_published, is_listed, published_on DESC); + +CREATE TABLE blog_post_authors ( + post_id TEXT NOT NULL REFERENCES blog_posts (id) ON DELETE CASCADE, + person_id TEXT NOT NULL REFERENCES people (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + PRIMARY KEY (post_id, person_id) +) STRICT; +CREATE INDEX blog_post_authors_person_idx ON blog_post_authors (person_id); + +CREATE TABLE community_page ( + id TEXT PRIMARY KEY CHECK (id = 'community'), + internal_title TEXT, -- null → 'From NGU' + internal_slots INTEGER NOT NULL DEFAULT 3 CHECK (internal_slots BETWEEN 0 AND 12), + external_title TEXT, -- null → 'From our community' + external_slots INTEGER NOT NULL DEFAULT 3 CHECK (external_slots BETWEEN 0 AND 12), + external_url TEXT, -- the Substack home, for its button + external_label TEXT, -- null → 'Read more on Substack' + updated_at TEXT NOT NULL DEFAULT (datetime('now')) +) STRICT; + +CREATE TABLE community_page_pinned_posts ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + page_id TEXT NOT NULL REFERENCES community_page (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + post_id TEXT NOT NULL REFERENCES blog_posts (id) ON DELETE CASCADE, + UNIQUE (page_id, post_id) +) STRICT; + +CREATE TABLE community_page_feeds ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + page_id TEXT NOT NULL REFERENCES community_page (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + url TEXT NOT NULL, -- 'https://ngu.substack.com/feed' + label TEXT -- shown on its items; else the feed's own title +) STRICT; + +CREATE TABLE "featured_cards" ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + owner_kind TEXT NOT NULL CHECK (owner_kind IN ('front_page', 'community_page')), + owner_id TEXT NOT NULL, + sort_order INTEGER NOT NULL DEFAULT 0, + + kind TEXT NOT NULL DEFAULT 'link' + CHECK (kind IN ('record', 'link', 'video')), + + ref_kind TEXT CHECK (ref_kind IN ('event', 'organization', 'person', 'team', 'award')), + ref_id TEXT, + url TEXT, + + eyebrow TEXT, + title TEXT, + blurb TEXT, + image TEXT, + + CHECK ((ref_kind IS NULL) = (ref_id IS NULL)), + CONSTRAINT "A record card needs a record to point at." + CHECK (kind != 'record' OR ref_kind IS NOT NULL), + CONSTRAINT "A link or video card needs a URL." + CHECK (kind = 'record' OR url IS NOT NULL) +) STRICT; +CREATE INDEX featured_cards_owner_idx ON featured_cards (owner_kind, owner_id, sort_order); + +CREATE TABLE site_settings ( + id TEXT PRIMARY KEY CHECK (id = 'site'), + site_name TEXT, + description TEXT, + preview_image TEXT, + favicon TEXT, + apple_touch_icon TEXT, + indexing TEXT CHECK (indexing IN ('on', 'off')), + updated_at TEXT NOT NULL DEFAULT (datetime('now')), + privacy_email TEXT, + notify_emails TEXT, + access_group_viewer TEXT, + access_group_editor TEXT, + access_group_admin TEXT, + report_daily TEXT CHECK (report_daily IN ('on', 'off')), + report_weekly TEXT CHECK (report_weekly IN ('on', 'off')) +) STRICT; + +CREATE TABLE site_setting_pages ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + settings_id TEXT NOT NULL REFERENCES site_settings (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + path TEXT NOT NULL, -- '/retreats' + title TEXT, + description TEXT, + UNIQUE (settings_id, path) +) STRICT; + +CREATE TABLE clip_jobs ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + kind TEXT NOT NULL CHECK (kind IN ('source', 'clip')), + status TEXT NOT NULL DEFAULT 'queued' + CHECK (status IN ('queued', 'running', 'done', 'failed')), + progress REAL NOT NULL DEFAULT 0 CHECK (progress BETWEEN 0 AND 1), + + source_url TEXT, -- kind 'source' + source_id INTEGER REFERENCES clip_jobs (id) ON DELETE CASCADE, -- kind 'clip' + params TEXT, -- kind 'clip': JSON + + title TEXT, + duration REAL, -- seconds + file TEXT, -- a name in CLIPS_DIR, once done + bytes INTEGER, + error TEXT, + saved_media_id INTEGER REFERENCES media (id) ON DELETE SET NULL, + downloaded_at TEXT, -- a clip's file went out, and was deleted + + created_by INTEGER REFERENCES admin_users (id) ON DELETE SET NULL, + created_at TEXT NOT NULL DEFAULT (datetime('now')), + finished_at TEXT, saved_drive_file_id INTEGER REFERENCES drive_files (id) ON DELETE SET NULL, + + CHECK ((kind = 'source') = (source_url IS NOT NULL)), + CHECK ((kind = 'clip') = (source_id IS NOT NULL)) +) STRICT; +CREATE INDEX clip_jobs_queue_idx ON clip_jobs (status, id); +CREATE INDEX clip_jobs_source_idx ON clip_jobs (source_id); + +CREATE TABLE feedback_files ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + feedback_id INTEGER NOT NULL REFERENCES feedback (id) ON DELETE CASCADE, + drive_id TEXT NOT NULL, + name TEXT NOT NULL, + mime TEXT NOT NULL, + size INTEGER NOT NULL +) STRICT; +CREATE INDEX feedback_files_owner_idx ON feedback_files (feedback_id); + +CREATE TABLE drive_files ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + drive_id TEXT NOT NULL UNIQUE, + name TEXT NOT NULL, + mime TEXT NOT NULL, + bytes INTEGER NOT NULL CHECK (bytes >= 0), + url TEXT NOT NULL, + preview TEXT, + uploaded_by INTEGER REFERENCES admin_users (id) ON DELETE SET NULL, + created_at TEXT NOT NULL DEFAULT (datetime('now')), + folder TEXT NOT NULL DEFAULT '' +) STRICT; +CREATE INDEX drive_files_created_idx ON drive_files (created_at DESC); + +CREATE TABLE "front_page_stats" ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + page_id TEXT NOT NULL REFERENCES front_page (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + label TEXT NOT NULL, + source TEXT NOT NULL DEFAULT 'manual' + CHECK (source IN ('manual', 'years_since', 'regions', 'groups', + 'partners', 'events_held', 'retreats_held', + 'people', 'awards_given')), + value TEXT, + suffix TEXT, -- '+', 'k', ' states' + note TEXT +) STRICT; + +CREATE TABLE "site_setting_colors" ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + settings_id TEXT NOT NULL REFERENCES site_settings (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + token TEXT NOT NULL CHECK (token IN ( + 'ink', 'body', 'muted', 'link', 'brand', 'action', 'action-hover', + 'surface', 'tint', 'tint-soft', 'danger', 'danger-tint')), + light TEXT CONSTRAINT "A color must be written #rrggbb, eg. #0f7183." + CHECK (light IS NULL OR (length(light) = 7 AND light GLOB '#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]')), + dark TEXT CONSTRAINT "A dark color must be written #rrggbb, eg. #5ccbdc." + CHECK (dark IS NULL OR (length(dark) = 7 AND dark GLOB '#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]')), + UNIQUE (settings_id, token) +) STRICT; + +CREATE TABLE site_pages ( + id TEXT PRIMARY KEY + CHECK (id IN ('community', 'retreats', 'resources', 'organization', 'history')), + updated_at TEXT NOT NULL DEFAULT (datetime('now')) +) STRICT; + +CREATE TABLE "content_blocks" ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + owner_kind TEXT NOT NULL + CHECK (owner_kind IN ('organization', 'event', 'person', 'team', 'blog_post', 'page_section', + 'newsletter')), + owner_id TEXT NOT NULL, + slot TEXT NOT NULL DEFAULT 'body' CHECK (slot IN ('card', 'body')), + sort_order INTEGER NOT NULL DEFAULT 0, + + type TEXT NOT NULL + CHECK (type IN ('heading', 'subheading', 'paragraph', + 'list', 'links', 'quote', 'image', 'divider', + 'video', 'button', 'callout', 'schedule', 'table', 'cards', + 'people')), + text TEXT, + media TEXT, + href TEXT, + alt TEXT, + cite TEXT, + team_id TEXT REFERENCES teams (id) ON DELETE SET NULL, + captions TEXT +) STRICT; +CREATE INDEX content_blocks_owner_idx + ON content_blocks (owner_kind, owner_id, slot, sort_order); + +CREATE TABLE "newsletters" ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + title TEXT, + layout TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(layout) AND json_type(layout) = 'array'), + created_at TEXT NOT NULL DEFAULT (datetime('now')), + updated_at TEXT NOT NULL DEFAULT (datetime('now')) +) STRICT; + +CREATE TABLE person_tag_types ( + id TEXT PRIMARY KEY + CONSTRAINT "A tag's URL ID can use only lowercase letters, numbers and hyphens, eg. musician." + CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'), + name TEXT NOT NULL, -- 'Musicians', the directory's title + blurb TEXT, -- the full directory page's intro + sort_order INTEGER NOT NULL DEFAULT 0 +) STRICT; + +CREATE TABLE person_tags ( + person_id TEXT NOT NULL REFERENCES people (id) ON DELETE CASCADE, + tag_id TEXT NOT NULL REFERENCES person_tag_types (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + PRIMARY KEY (person_id, tag_id) +) STRICT; +CREATE INDEX person_tags_tag_idx ON person_tags (tag_id); + +CREATE TABLE "page_sections" ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + page_id TEXT NOT NULL REFERENCES site_pages (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + anchor TEXT NOT NULL + CONSTRAINT "A section's URL ID can use only lowercase letters, numbers and hyphens, eg. leadership." + CHECK (anchor <> '' AND anchor NOT GLOB '*[^a-z0-9-]*'), + title TEXT NOT NULL + CONSTRAINT "A section title can be 30 characters at most (it's listed in the page's side nav)." + CHECK (length(title) <= 30), + blurb TEXT, + accent TEXT CHECK (accent IN ('teal', 'deep', 'green', 'amber')), + preset TEXT CHECK (preset IN ('community_blog', 'group_map', 'region_list', 'partner_list', + 'events', 'timeline', 'people_directory')), + -- An events preset's filter and first view. + scope_id TEXT REFERENCES event_scopes (id) ON DELETE SET NULL, + event_type TEXT CHECK (event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other')), + view TEXT CHECK (view IN ('carousel', 'grid', 'map')), + -- A people_directory preset's tag. + tag_id TEXT REFERENCES person_tag_types (id) ON DELETE SET NULL, + UNIQUE (page_id, anchor) +) STRICT; +CREATE INDEX page_sections_page_idx ON page_sections (page_id, sort_order); + +CREATE TABLE "organizations" ( + id TEXT PRIMARY KEY, -- slug: 'northwest', 'lynnwood' + kind TEXT NOT NULL + CHECK (kind IN ('national', 'region', 'group', 'partner', 'ministry')), + + name TEXT NOT NULL, + short_name TEXT, + tagline TEXT, -- one line, for the card + color TEXT, + logo TEXT, -- an upload's filename + + venue TEXT, + address TEXT, + locality TEXT, + state_code TEXT, -- US only + country TEXT NOT NULL DEFAULT 'US', + location_label TEXT, + latitude REAL, + longitude REAL, + is_online INTEGER NOT NULL DEFAULT 0 CHECK (is_online IN (0, 1)), + + is_published INTEGER NOT NULL DEFAULT 1 CHECK (is_published IN (0, 1)), + sort_order INTEGER NOT NULL DEFAULT 0, + created_at TEXT NOT NULL DEFAULT (datetime('now')), + updated_at TEXT NOT NULL DEFAULT (datetime('now')), + in_timeline INTEGER NOT NULL DEFAULT 0 CHECK (in_timeline IN (0, 1)), + is_listed INTEGER NOT NULL DEFAULT 1 CHECK (is_listed IN (0, 1)) +) STRICT; +CREATE INDEX organizations_kind_idx ON organizations (kind, is_published, sort_order); +CREATE INDEX organizations_state_idx ON organizations (state_code); + +CREATE TABLE contact_types ( + id TEXT PRIMARY KEY + CONSTRAINT "A contact type's URL ID can use only lowercase letters, numbers and hyphens, eg. minister." + CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'), + name TEXT NOT NULL, -- 'Minister' + sort_order INTEGER NOT NULL DEFAULT 0 +) STRICT; + +CREATE TABLE organization_contacts ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + org_id TEXT NOT NULL REFERENCES organizations (id) ON DELETE CASCADE, + sort_order INTEGER NOT NULL DEFAULT 0, + type_id TEXT NOT NULL REFERENCES contact_types (id), + name TEXT, + email TEXT, + phone TEXT, + CONSTRAINT "A contact needs an email or a phone number." + CHECK (email IS NOT NULL OR phone IS NOT NULL) +) STRICT; +CREATE INDEX organization_contacts_org_idx ON organization_contacts (org_id, sort_order); +CREATE INDEX organization_contacts_type_idx ON organization_contacts (type_id); + +CREATE TABLE analytics_reports ( + kind TEXT PRIMARY KEY CHECK (kind IN ('daily', 'weekly')), + sent_for TEXT NOT NULL +) STRICT; + +-- ── Views ─────────────────────────────────────────────────── --- An event's public billing: published people, public rows only. CREATE VIEW v_event_people AS SELECT ep.event_id, ep.person_id, ep.role, ep.title, ep.sort_order, @@ -866,39 +848,6 @@ FROM event_people ep JOIN people p ON p.id = ep.person_id AND p.is_published = 1 WHERE ep.is_public = 1; --- Current, public leadership for every organization, with the --- person's primary organization named for cross-links. -CREATE VIEW v_org_leadership AS -SELECT - a.org_id, - a.team_id, - t.name AS team_name, - t.sort_order AS team_sort_order, - a.person_id, - a.title, - a.role, - a.is_owner, - a.sort_order, - p.display_name, - p.sort_name, - p.pronouns, - p.tagline, - p.photo, - p.public_email, - p.location_label, - p.bio, - o.id AS primary_org_id, - o.name AS primary_org_name -FROM affiliations a -JOIN people p ON p.id = a.person_id AND p.is_published = 1 -LEFT JOIN teams t ON t.id = a.team_id -LEFT JOIN organizations o ON o.id = p.primary_org_id -WHERE a.is_public = 1 - AND a.ended_on IS NULL -ORDER BY a.org_id, a.is_owner DESC, a.sort_order, p.sort_name; - --- Timeline entries with everything inherited from the referenced --- record resolved: date, title, blurb, logo. CREATE VIEW v_timeline AS SELECT t.id, @@ -958,113 +907,88 @@ LEFT JOIN person_awards pa ON t.ref_kind = 'award' AND pa.award_id = t.re AND pa.id = (SELECT MIN(id) FROM person_awards WHERE award_id = t.ref_id); +CREATE VIEW v_org_leadership AS +SELECT + a.org_id, + a.team_id, + t.name AS team_name, + t.sort_order AS team_sort_order, + a.person_id, + a.title, + a.role, + a.is_owner, + a.sort_order, + p.display_name, + p.sort_name, + p.pronouns, + p.tagline, + p.photo, + p.public_email, + p.location_label, + p.bio, + o.id AS primary_org_id, + o.name AS primary_org_name +FROM affiliations a +JOIN people p ON p.id = a.person_id AND p.is_published = 1 +LEFT JOIN teams t ON t.id = a.team_id +LEFT JOIN organizations o ON o.id = p.primary_org_id AND o.is_published = 1 +WHERE a.is_public = 1 + AND a.ended_on IS NULL +ORDER BY a.org_id, a.is_owner DESC, a.sort_order, p.sort_name; --- ═══════════════════════════════════════════════════════════════ --- SEED --- ═══════════════════════════════════════════════════════════════ --- --- What a new database needs before anyone signs in: the scopes an --- event can be filed under, and the front page as it ships, every --- section, the stats that need no typing, and the Church Center --- forms sorted into paths. Everything else comes in through the --- admin. +CREATE VIEW v_event_hosts AS +SELECT + eh.id, + eh.event_id, + eh.sort_order, + CASE WHEN eh.person_id IS NULL THEN 'organization' ELSE 'person' END + AS host_kind, + COALESCE(eh.org_id, eh.person_id) AS host_id, + COALESCE(o.name, p.display_name) AS host_name, + o.kind AS host_org_kind, + o.logo AS host_logo, + o.color AS host_color, + p.photo AS host_photo, + COALESCE(o.is_published, p.is_published) AS host_is_published, + t.id AS host_team_id, + t.name AS host_team_name +FROM event_hosts eh +LEFT JOIN organizations o ON o.id = eh.org_id +LEFT JOIN people p ON p.id = eh.person_id +LEFT JOIN teams t ON t.id = eh.team_id AND eh.org_id IS NOT NULL AND t.is_published = 1; -INSERT INTO meta (key, value) VALUES ('created_at', datetime('now')); +CREATE VIEW v_events AS +SELECT + e.*, + CASE WHEN eh.id IS NULL THEN NULL + WHEN eh.person_id IS NULL THEN 'organization' ELSE 'person' END + AS host_kind, + COALESCE(eh.org_id, eh.person_id) AS host_id, + COALESCE(o.name, p.display_name) AS host_name, + o.kind AS host_org_kind, + COALESCE(e.org_logo, o.logo) AS effective_org_logo, + COALESCE(e.color, o.color) AS effective_color, + COALESCE( + e.status, + CASE WHEN e.ends_on IS NOT NULL AND e.ends_on < date('now') + THEN 'past' ELSE 'upcoming' END + ) AS effective_status +FROM events e +LEFT JOIN event_hosts eh + ON eh.id = ( + SELECT x.id + FROM event_hosts x + LEFT JOIN organizations xo ON xo.id = x.org_id + LEFT JOIN people xp ON xp.id = x.person_id + WHERE x.event_id = e.id + AND COALESCE(xo.is_published, xp.is_published) = 1 + ORDER BY x.sort_order, x.id + LIMIT 1 + ) +LEFT JOIN organizations o ON o.id = eh.org_id +LEFT JOIN people p ON p.id = eh.person_id; -INSERT INTO event_scopes (id, name, sort_order) VALUES - ('national', 'National', 10), - ('regional', 'Regional', 20), - ('local', 'Local', 30), - ('international', 'International', 40), - ('partner', 'Partner', 50), - ('other', 'Other', 60); - -INSERT INTO front_page - (id, eyebrow, headline, subhead, - primary_label, primary_url, secondary_label, secondary_url) -VALUES - ('home', - 'Young adults of the Unity movement', - 'Next Generation of Unity', - 'A community for 18–40 year olds, rooted in spiritual growth, leadership and sacred service.', - 'Find a retreat', '/retreats', - 'Find your way in', '#connect'); - -INSERT INTO front_page_sections (page_id, sort_order, section, title, blurb) VALUES - ('home', 0, 'countdown', NULL, NULL), - ('home', 1, 'retreats', 'National Retreats', 'Our flagship gatherings, open to young adults across the country.'), - ('home', 2, 'calendar', 'What''s on', 'Every gathering, class and meeting in one place.'), - ('home', 3, 'stats', 'NGU by the numbers', NULL), - ('home', 4, 'timeline', 'Moments that shaped us', 'Highlights from our history.'), - ('home', 5, 'connect', 'Find your way in', 'Tell us what you''re looking for.'); - -INSERT INTO front_page_stats (page_id, sort_order, label, source) VALUES - ('home', 0, 'Regions', 'regions'), - ('home', 1, 'Chapters', 'chapters'), - ('home', 2, 'Retreats held', 'retreats_held'), - ('home', 3, 'Awards given', 'awards_given'); - -INSERT INTO front_page_paths (page_id, sort_order, label, icon, blurb) VALUES - ('home', 0, 'Attend', '🧭', 'Come to a gathering near you or across the country.'), - ('home', 1, 'Serve', '🤲', 'Help create transformative experiences for young adults.'), - ('home', 2, 'Belong', '🌱', 'Make NGU your community.'), - ('home', 3, 'Partner', '🤝', 'Bring your ministry or organization alongside us.'); - -INSERT INTO front_page_path_actions (path_id, sort_order, label, description, url) -SELECT p.id, a.sort_order, a.label, a.description, a.url - FROM front_page_paths p - JOIN ( - SELECT 'Attend' AS path, 0 AS sort_order, 'See upcoming retreats' AS label, - 'National, regional and partner gatherings.' AS description, - '/retreats' AS url - UNION ALL SELECT 'Attend', 1, 'NGU calendar', - 'Everything on the schedule, in one place.', - 'https://ngu.churchcenter.com/calendar?view=gallery' - UNION ALL SELECT 'Serve', 0, 'Volunteer', - 'Lend a hand at a retreat or event.', - 'https://ngu.churchcenter.com/people/forms/1176908' - UNION ALL SELECT 'Serve', 1, 'Speaker & Musician Directory', - 'Join our network of speakers, musicians and facilitators.', - 'https://ngu.churchcenter.com/people/forms/1173181' - UNION ALL SELECT 'Belong', 0, 'Become a member', - 'Join the NGU community officially.', - 'https://ngu.churchcenter.com/people/forms/1135816' - UNION ALL SELECT 'Belong', 1, 'Find your region', - 'Chapters and regions across the country.', - '/community' - UNION ALL SELECT 'Partner', 0, 'Affiliation form', - 'Affiliate your ministry or spiritual organization with NGU.', - 'https://ngu.churchcenter.com/people/forms/1135750' - ) a ON a.path = p.label - WHERE p.page_id = 'home'; - - --- ═══════════════════════════════════════════════════════════════ --- TRIGGERS --- ═══════════════════════════════════════════════════════════════ --- --- Last in the file: nothing may follow a BEGIN...END body. - --- ── Polymorphic owners exist ─────────────────────────────────── - -CREATE TRIGGER content_blocks_owner_exists -BEFORE INSERT ON content_blocks -BEGIN - SELECT CASE - WHEN new.owner_kind = 'event' - AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such event') - WHEN new.owner_kind = 'organization' - AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such organization') - WHEN new.owner_kind = 'person' - AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such person') - WHEN new.owner_kind = 'team' - AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) - THEN RAISE(ABORT, 'content_blocks: no such team') - END; -END; +-- ── Triggers ──────────────────────────────────────────────── CREATE TRIGGER links_owner_exists BEFORE INSERT ON links @@ -1129,15 +1053,6 @@ BEGIN END; END; --- ── A deleted owner takes its blocks, links and timeline entry ── - -CREATE TRIGGER organizations_cleanup -AFTER DELETE ON organizations -BEGIN - DELETE FROM content_blocks WHERE owner_kind = 'organization' AND owner_id = old.id; - DELETE FROM links WHERE owner_kind = 'organization' AND owner_id = old.id; -END; - CREATE TRIGGER events_cleanup AFTER DELETE ON events BEGIN @@ -1165,12 +1080,6 @@ BEGIN DELETE FROM timeline_entries WHERE ref_kind = 'event' AND ref_id = old.id; END; -CREATE TRIGGER timeline_organizations_cleanup -AFTER DELETE ON organizations -BEGIN - DELETE FROM timeline_entries WHERE ref_kind = 'organization' AND ref_id = old.id; -END; - CREATE TRIGGER timeline_awards_cleanup AFTER DELETE ON awards BEGIN @@ -1189,17 +1098,6 @@ BEGIN DELETE FROM timeline_entries WHERE ref_kind = 'team' AND ref_id = old.id; END; --- ── updated_at ───────────────────────────────────────────────── --- An UPDATE that doesn't set updated_at itself gets it set, which --- is what the admin engine's optimistic concurrency compares. - -CREATE TRIGGER organizations_touch -AFTER UPDATE ON organizations -FOR EACH ROW WHEN new.updated_at = old.updated_at -BEGIN - UPDATE organizations SET updated_at = datetime('now') WHERE id = new.id; -END; - CREATE TRIGGER events_touch AFTER UPDATE ON events FOR EACH ROW WHEN new.updated_at = old.updated_at @@ -1234,3 +1132,188 @@ FOR EACH ROW WHEN new.updated_at = old.updated_at BEGIN UPDATE front_page SET updated_at = datetime('now') WHERE id = new.id; END; + +CREATE TRIGGER events_featured_cleanup +AFTER DELETE ON events +BEGIN + DELETE FROM featured_cards WHERE ref_kind = 'event' AND ref_id = old.id; +END; + +CREATE TRIGGER people_featured_cleanup +AFTER DELETE ON people +BEGIN + DELETE FROM featured_cards WHERE ref_kind = 'person' AND ref_id = old.id; +END; + +CREATE TRIGGER teams_featured_cleanup +AFTER DELETE ON teams +BEGIN + DELETE FROM featured_cards WHERE ref_kind = 'team' AND ref_id = old.id; +END; + +CREATE TRIGGER awards_featured_cleanup +AFTER DELETE ON awards +BEGIN + DELETE FROM featured_cards WHERE ref_kind = 'award' AND ref_id = old.id; +END; + +CREATE TRIGGER featured_cards_ref_exists +BEFORE INSERT ON featured_cards +BEGIN + SELECT CASE + WHEN new.ref_kind = 'event' + AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such event') + WHEN new.ref_kind = 'organization' + AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such organization') + WHEN new.ref_kind = 'person' + AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such person') + WHEN new.ref_kind = 'team' + AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such team') + WHEN new.ref_kind = 'award' + AND NOT EXISTS (SELECT 1 FROM awards WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such award') + END; +END; + +CREATE TRIGGER featured_cards_ref_exists_update +BEFORE UPDATE OF ref_kind, ref_id ON featured_cards +BEGIN + SELECT CASE + WHEN new.ref_kind = 'event' + AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such event') + WHEN new.ref_kind = 'organization' + AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such organization') + WHEN new.ref_kind = 'person' + AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such person') + WHEN new.ref_kind = 'team' + AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such team') + WHEN new.ref_kind = 'award' + AND NOT EXISTS (SELECT 1 FROM awards WHERE id = new.ref_id) + THEN RAISE(ABORT, 'featured_cards: no such award') + END; +END; + +CREATE TRIGGER blog_posts_cleanup +AFTER DELETE ON blog_posts +BEGIN + DELETE FROM content_blocks WHERE owner_kind = 'blog_post' AND owner_id = old.id; +END; + +CREATE TRIGGER blog_posts_touch +AFTER UPDATE ON blog_posts +FOR EACH ROW WHEN new.updated_at = old.updated_at +BEGIN + UPDATE blog_posts SET updated_at = datetime('now') WHERE id = new.id; +END; + +CREATE TRIGGER community_page_touch +AFTER UPDATE ON community_page +FOR EACH ROW WHEN new.updated_at = old.updated_at +BEGIN + UPDATE community_page SET updated_at = datetime('now') WHERE id = new.id; +END; + +CREATE TRIGGER site_settings_touch +AFTER UPDATE ON site_settings +FOR EACH ROW WHEN new.updated_at = old.updated_at +BEGIN + UPDATE site_settings SET updated_at = datetime('now') WHERE id = new.id; +END; + +CREATE TRIGGER site_pages_touch +AFTER UPDATE ON site_pages +FOR EACH ROW WHEN new.updated_at = old.updated_at +BEGIN + UPDATE site_pages SET updated_at = datetime('now') WHERE id = new.id; +END; + +CREATE TRIGGER content_blocks_owner_exists +BEFORE INSERT ON content_blocks +BEGIN + SELECT CASE + WHEN new.owner_kind = 'event' + AND NOT EXISTS (SELECT 1 FROM events WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such event') + WHEN new.owner_kind = 'organization' + AND NOT EXISTS (SELECT 1 FROM organizations WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such organization') + WHEN new.owner_kind = 'person' + AND NOT EXISTS (SELECT 1 FROM people WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such person') + WHEN new.owner_kind = 'team' + AND NOT EXISTS (SELECT 1 FROM teams WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such team') + WHEN new.owner_kind = 'blog_post' + AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE id = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such blog post') + WHEN new.owner_kind = 'page_section' + AND NOT EXISTS (SELECT 1 FROM page_sections WHERE CAST(id AS TEXT) = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such page section') + WHEN new.owner_kind = 'newsletter' + AND NOT EXISTS (SELECT 1 FROM newsletters WHERE CAST(id AS TEXT) = new.owner_id) + THEN RAISE(ABORT, 'content_blocks: no such newsletter') + END; +END; + +CREATE TRIGGER newsletters_touch +AFTER UPDATE ON newsletters +FOR EACH ROW WHEN new.updated_at = old.updated_at +BEGIN + UPDATE newsletters SET updated_at = datetime('now') WHERE id = new.id; +END; + +CREATE TRIGGER page_sections_cleanup +AFTER DELETE ON page_sections +BEGIN + DELETE FROM content_blocks WHERE owner_kind = 'page_section' AND owner_id = CAST(old.id AS TEXT); +END; + +CREATE TRIGGER organizations_cleanup +AFTER DELETE ON organizations +BEGIN + DELETE FROM content_blocks WHERE owner_kind = 'organization' AND owner_id = old.id; + DELETE FROM links WHERE owner_kind = 'organization' AND owner_id = old.id; +END; + +CREATE TRIGGER timeline_organizations_cleanup +AFTER DELETE ON organizations +BEGIN + DELETE FROM timeline_entries WHERE ref_kind = 'organization' AND ref_id = old.id; +END; + +CREATE TRIGGER organizations_featured_cleanup +AFTER DELETE ON organizations +BEGIN + DELETE FROM featured_cards WHERE ref_kind = 'organization' AND ref_id = old.id; +END; + +CREATE TRIGGER organizations_touch +AFTER UPDATE ON organizations +FOR EACH ROW WHEN new.updated_at = old.updated_at +BEGIN + UPDATE organizations SET updated_at = datetime('now') WHERE id = new.id; +END; + +CREATE TRIGGER groups_ministry_kind +BEFORE INSERT ON groups +FOR EACH ROW WHEN new.ministry_id IS NOT NULL + AND (SELECT kind FROM organizations WHERE id = new.ministry_id) IS NOT 'ministry' +BEGIN + SELECT RAISE(ABORT, 'A group''s ministry must be a ministry.'); +END; + +CREATE TRIGGER groups_ministry_kind_update +BEFORE UPDATE OF ministry_id ON groups +FOR EACH ROW WHEN new.ministry_id IS NOT NULL + AND (SELECT kind FROM organizations WHERE id = new.ministry_id) IS NOT 'ministry' +BEGIN + SELECT RAISE(ABORT, 'A group''s ministry must be a ministry.'); +END; diff --git a/server/src/migrations/066_seed.sql b/server/src/migrations/066_seed.sql new file mode 100644 index 0000000..cf67282 --- /dev/null +++ b/server/src/migrations/066_seed.sql @@ -0,0 +1,66 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 066 SEED (with the baseline) +-- +-- The least a new database needs for every page to work. Runs right +-- after 066_schema.sql, on an empty database only. +-- +-- meta, site_settings, the single rows the site reads and the +-- front_page, admin edits in place, each left at its +-- community_page defaults (blank means "use site.json" +-- or the built-in default) +-- event_scopes the fixed scopes events and Retreats +-- sections filter by +-- front_page_sections the home page's sections, in order +-- site_pages, page_sections the Community, Retreats, Resources, +-- Organization and History pages and +-- their sections (presets: map, lists, +-- events, timeline) +-- person_tag_types Musicians, the directory the people +-- section and /directory/musician show +-- +-- Not seeded: content an editor types in (the hero's words, paths, +-- stats, the Organization page's address and tax ID). Fill those in +-- through the admin. +-- ═══════════════════════════════════════════════════════════════ + +INSERT INTO meta (key, value) VALUES ('created_at', datetime('now')); +INSERT INTO site_settings (id) VALUES ('site'); +INSERT INTO front_page (id) VALUES ('home'); +INSERT INTO community_page (id) VALUES ('community'); + +INSERT INTO event_scopes (id, name, sort_order) VALUES ('national', 'National', 10); +INSERT INTO event_scopes (id, name, sort_order) VALUES ('regional', 'Regional', 20); +INSERT INTO event_scopes (id, name, sort_order) VALUES ('local', 'Local', 30); +INSERT INTO event_scopes (id, name, sort_order) VALUES ('international', 'International', 40); +INSERT INTO event_scopes (id, name, sort_order) VALUES ('partner', 'Partner', 50); +INSERT INTO event_scopes (id, name, sort_order) VALUES ('other', 'Other', 60); + +INSERT INTO front_page_sections (page_id, sort_order, section, is_hidden) VALUES ('home', 0, 'countdown', 0); +INSERT INTO front_page_sections (page_id, sort_order, section, title, blurb, is_hidden) VALUES ('home', 1, 'retreats', 'National Retreats', 'Our flagship gatherings, open to young adults across the country.', 0); +INSERT INTO front_page_sections (page_id, sort_order, section, title, blurb, is_hidden) VALUES ('home', 2, 'calendar', 'What''s on', 'Every gathering, class and meeting in one place.', 0); +INSERT INTO front_page_sections (page_id, sort_order, section, title, is_hidden) VALUES ('home', 3, 'stats', 'NGU by the numbers', 0); +INSERT INTO front_page_sections (page_id, sort_order, section, title, blurb, is_hidden) VALUES ('home', 4, 'timeline', 'Moments that shaped us', 'Highlights from our history.', 0); +INSERT INTO front_page_sections (page_id, sort_order, section, title, blurb, is_hidden) VALUES ('home', 5, 'connect', 'Find your way in', 'Tell us what you''re looking for.', 0); + +INSERT INTO site_pages (id) VALUES ('community'); +INSERT INTO site_pages (id) VALUES ('retreats'); +INSERT INTO site_pages (id) VALUES ('resources'); +INSERT INTO site_pages (id) VALUES ('organization'); +INSERT INTO site_pages (id) VALUES ('history'); + +INSERT INTO page_sections (page_id, sort_order, anchor, title, accent, preset) VALUES ('community', 0, 'blog', 'Community Blog', 'teal', 'community_blog'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset, view) VALUES ('community', 1, 'groups', 'Local Groups', 'Young adult groups meeting in person and online across the movement.', 'teal', 'group_map', 'map'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset) VALUES ('community', 2, 'regions', 'Unity Regions', 'The regional organizations that support groups and host their own gatherings.', 'deep', 'region_list'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset) VALUES ('community', 3, 'partners', 'Partner Organizations', 'Organizations we collaborate with across the Unity movement and beyond.', 'amber', 'partner_list'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view) VALUES ('retreats', 0, 'national', 'National Retreats', 'Our flagship gatherings, open to young adults across the country.', 'teal', 'events', 'national', 'retreat', 'carousel'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view) VALUES ('retreats', 1, 'regional', 'Regional Retreats', 'Smaller gatherings hosted by regions throughout the year.', 'green', 'events', 'regional', 'retreat', 'grid'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view) VALUES ('retreats', 2, 'partner', 'Partner Events', 'Retreats hosted by organizations we collaborate with.', 'amber', 'events', 'partner', 'retreat', 'grid'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent) VALUES ('resources', 0, 'unity', 'Unity Teachings', 'Core principles, readings, and study material from the Unity movement.', 'teal'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent) VALUES ('resources', 1, 'branding', 'Branding & Marketing', 'Logos, colors, templates, and guidelines for representing NGU.', 'green'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent) VALUES ('resources', 2, 'partner', 'Partner Resources', 'Material for the organizations we collaborate with.', 'amber'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, blurb, accent, preset) VALUES ('history', 0, 'timeline', 'NGU Timeline', 'Open a year to see what happened.', 'teal', 'timeline'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, accent) VALUES ('organization', 2, 'contact', 'Details & Contact', 'deep'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, accent) VALUES ('organization', 0, 'mission', 'Mission, Vision & Values', 'teal'); +INSERT INTO page_sections (page_id, sort_order, anchor, title, accent) VALUES ('organization', 1, 'leadership', 'Leadership', 'green'); + +INSERT INTO person_tag_types (id, name, blurb, sort_order) VALUES ('musician', 'Musicians', 'Musicians in the NGU community, for services, retreats and events.', 0); diff --git a/server/src/migrations/066_video_captions.sql b/server/src/migrations/066_video_captions.sql deleted file mode 100644 index 50a31e6..0000000 --- a/server/src/migrations/066_video_captions.sql +++ /dev/null @@ -1,13 +0,0 @@ --- ═══════════════════════════════════════════════════════════════ --- 066 VIDEO CAPTIONS --- --- A WebVTT file for an uploaded video, drawn as its captions track --- (WCAG 1.2.2). YouTube, Vimeo and Facebook embeds bring their own. --- The file is an upload in /uploads/captions/ (media.js). --- --- content_blocks.captions a video block's --- front_page.video_captions the hero's featured video's --- ═══════════════════════════════════════════════════════════════ - -ALTER TABLE content_blocks ADD COLUMN captions TEXT; -ALTER TABLE front_page ADD COLUMN video_captions TEXT;