Newsletter drafts with content blocks, a footer and Post as blog post; Home has no header dropdown
Tools → Newsletter saves drafts (migration 057: newsletters, with content blocks owned 'newsletter'), adds blocks written for the issue and an editable footer (no unsubscribe link: Mailchimp adds one), and turns a draft into an unpublished blog post. The admin engine binds child owner ids as text, so an auto-numbered record's blocks are owned by '1', not '1.0'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9daf7b1a4f
commit
e8ac242e6d
8 changed files with 575 additions and 34 deletions
111
server/src/migrations/057_newsletters.sql
Normal file
111
server/src/migrations/057_newsletters.sql
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue