A schedule block's entries (migration 034) each have a day, time, title, detail, location, person and link, and fold out for a longer description, the person's photo and page, a graphic and a Google map of a place or address. Entries sit in one tab per day, in the order entered; the tab for today's weekday opens first, and a one-day schedule draws no tabs. In the editor, the entry fields show only under a schedule block: repeater `when` can now look at the parent row (scope "parent"), and a field's label can depend on the row. The block preview names an entry's person. The showcase retreat and post each have a schedule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
4.4 KiB
SQL
99 lines
4.4 KiB
SQL
-- ═══════════════════════════════════════════════════════════════
|
|
-- 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;
|