v1.13.1-data: links/redirects, captions, partner picks, Plausible reports, migration baseline #28
48 changed files with 763 additions and 3322 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 } = {}) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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'));
|
||||
|
|
@ -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));
|
||||
|
|
@ -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/<file>',
|
||||
-- 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 <Logo> and <img> 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);
|
||||
|
|
@ -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/<file>' 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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -1,254 +0,0 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 031 BLOG
|
||||
--
|
||||
-- Posts of our own, at /blog/<id>, 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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
@ -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));
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
@ -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));
|
||||
|
|
@ -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 '';
|
||||
|
|
@ -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;
|
||||
|
|
@ -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/<id>, 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/<id>', '/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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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 <team>" 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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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/<id>) 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;
|
||||
|
|
@ -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: <name>", 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;
|
||||
|
|
@ -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);
|
||||
|
|
@ -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;
|
||||
File diff suppressed because it is too large
Load diff
66
server/src/migrations/066_seed.sql
Normal file
66
server/src/migrations/066_seed.sql
Normal file
|
|
@ -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);
|
||||
|
|
@ -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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue