- A "People" content block: a team's members as people tiles, people
picked one by one as items (each with a title), or both.
content_blocks gains team_id (migration 054 rebuilds it for the
type CHECK); a picked person rides on the item's person_id.
- An organization host can name a team (any organization's) to show
in its place: event_hosts.team_id, carried by v_event_hosts. The
event page reads "Hosted by" the team, linked to its page.
- Admin fields can show on `when: { path, filled: true }`.
- The showcase post has a people block; the past showcase event is
hosted by the region shown as its team.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
140 lines
5.8 KiB
SQL
140 lines
5.8 KiB
SQL
-- ═══════════════════════════════════════════════════════════════
|
|
-- 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;
|