diff --git a/server/src/migrations/044_table_block.sql b/server/src/migrations/044_table_block.sql index 26fad48..121b902 100644 --- a/server/src/migrations/044_table_block.sql +++ b/server/src/migrations/044_table_block.sql @@ -1,20 +1,12 @@ -- ═══════════════════════════════════════════════════════════════ --- 044 TABLE AND CARD BLOCKS +-- 044 TABLE BLOCKS -- --- Two content block types: --- --- 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)). --- 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 (all as today's item --- columns). Fetch preview in the admin fills them. --- --- ContentBlocks.tsx draws both. +-- 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 @@ -33,7 +25,7 @@ CREATE TABLE content_blocks_new ( type TEXT NOT NULL CHECK (type IN ('heading', 'subheading', 'paragraph', 'list', 'links', 'quote', 'image', 'divider', - 'video', 'button', 'callout', 'schedule', 'table', 'cards')), + 'video', 'button', 'callout', 'schedule', 'table')), text TEXT, media TEXT, href TEXT, diff --git a/server/src/migrations/045_card_block.sql b/server/src/migrations/045_card_block.sql new file mode 100644 index 0000000..48feb2a --- /dev/null +++ b/server/src/migrations/045_card_block.sql @@ -0,0 +1,70 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 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;