-- ═══════════════════════════════════════════════════════════════ -- 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;