Call local chapters groups, everywhere
The organization kind is 'group', its side table is groups, pages live at /groups/<id> and the Community page's section is #groups. Migration 052 converts existing databases: the kind and the tables whose CHECKs name chapters are rebuilt, the front page count and request category follow, and the site's own /chapters/ and #chapters links in records are rewritten. Request files now go in Requests/Groups on the shared drive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
175a18976d
commit
38aff34c97
42 changed files with 473 additions and 254 deletions
219
server/src/migrations/052_groups.sql
Normal file
219
server/src/migrations/052_groups.sql
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 052 CHAPTERS BECOME GROUPS
|
||||
--
|
||||
-- Local chapters are called groups now, everywhere: the kind value,
|
||||
-- the side table, the front page count, the Request form's type, the
|
||||
-- pages (/groups/<id>, the Community page's #groups section).
|
||||
--
|
||||
-- organizations.kind 'chapter' → 'group' (CHECK changes, so
|
||||
-- the table is rebuilt as 045 did, then
|
||||
-- its indexes and triggers again)
|
||||
-- chapters renamed groups, its index with it
|
||||
-- front_page_stats.source 'chapters' → 'groups' (rebuilt), and
|
||||
-- the seeded "Chapters" label
|
||||
-- feedback.category 'chapter' → 'group' (a column CHECK
|
||||
-- only, so a new column replaces it)
|
||||
-- links in records the site's own /chapters/ and
|
||||
-- #chapters links, in link columns and
|
||||
-- [text](url) formatting
|
||||
--
|
||||
-- Names and prose written in the admin (an organization called
|
||||
-- "Lynnwood Chapter", a post's paragraph) are left as written.
|
||||
-- ═══════════════════════════════════════════════════════════════
|
||||
|
||||
-- ── organizations.kind ─────────────────────────────────────────
|
||||
|
||||
CREATE TABLE organizations_new (
|
||||
id TEXT PRIMARY KEY, -- slug: 'northwest', 'lynnwood'
|
||||
kind TEXT NOT NULL
|
||||
CHECK (kind IN ('national', 'region', 'group', 'partner')),
|
||||
|
||||
name TEXT NOT NULL,
|
||||
short_name TEXT,
|
||||
tagline TEXT, -- one line, for the card
|
||||
color TEXT,
|
||||
logo TEXT, -- an upload's filename
|
||||
|
||||
venue TEXT,
|
||||
address TEXT,
|
||||
locality TEXT,
|
||||
state_code TEXT, -- US only
|
||||
country TEXT NOT NULL DEFAULT 'US',
|
||||
location_label TEXT,
|
||||
latitude REAL,
|
||||
longitude REAL,
|
||||
is_online INTEGER NOT NULL DEFAULT 0 CHECK (is_online IN (0, 1)),
|
||||
|
||||
is_published INTEGER NOT NULL DEFAULT 1 CHECK (is_published IN (0, 1)),
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
in_timeline INTEGER NOT NULL DEFAULT 0 CHECK (in_timeline IN (0, 1)),
|
||||
is_listed INTEGER NOT NULL DEFAULT 1 CHECK (is_listed IN (0, 1))
|
||||
) STRICT;
|
||||
|
||||
INSERT INTO organizations_new
|
||||
(id, kind, name, short_name, tagline, color, logo,
|
||||
venue, address, locality, state_code, country, location_label,
|
||||
latitude, longitude, is_online,
|
||||
is_published, sort_order, created_at, updated_at, in_timeline, is_listed)
|
||||
SELECT id, CASE kind WHEN 'chapter' THEN 'group' ELSE kind END,
|
||||
name, short_name, tagline, color, logo,
|
||||
venue, address, locality, state_code, country, location_label,
|
||||
latitude, longitude, is_online,
|
||||
is_published, sort_order, created_at, updated_at, in_timeline, is_listed
|
||||
FROM organizations;
|
||||
|
||||
PRAGMA legacy_alter_table = ON;
|
||||
DROP TABLE organizations;
|
||||
ALTER TABLE organizations_new RENAME TO organizations;
|
||||
PRAGMA legacy_alter_table = OFF;
|
||||
|
||||
CREATE INDEX organizations_kind_idx ON organizations (kind, is_published, sort_order);
|
||||
CREATE INDEX organizations_state_idx ON organizations (state_code);
|
||||
|
||||
|
||||
-- ── chapters → groups ──────────────────────────────────────────
|
||||
|
||||
ALTER TABLE chapters RENAME TO groups;
|
||||
DROP INDEX chapters_region_idx;
|
||||
CREATE INDEX groups_region_idx ON groups (region_id);
|
||||
|
||||
|
||||
-- ── front_page_stats.source ────────────────────────────────────
|
||||
|
||||
CREATE TABLE front_page_stats_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
page_id TEXT NOT NULL REFERENCES front_page (id) ON DELETE CASCADE,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
label TEXT NOT NULL,
|
||||
source TEXT NOT NULL DEFAULT 'manual'
|
||||
CHECK (source IN ('manual', 'years_since', 'regions', 'groups',
|
||||
'partners', 'events_held', 'retreats_held',
|
||||
'people', 'awards_given')),
|
||||
value TEXT,
|
||||
suffix TEXT, -- '+', 'k', ' states'
|
||||
note TEXT
|
||||
) STRICT;
|
||||
|
||||
INSERT INTO front_page_stats_new
|
||||
(id, page_id, sort_order, label, source, value, suffix, note)
|
||||
SELECT id, page_id, sort_order,
|
||||
CASE label WHEN 'Chapters' THEN 'Groups' ELSE label END,
|
||||
CASE source WHEN 'chapters' THEN 'groups' ELSE source END,
|
||||
value, suffix, note
|
||||
FROM front_page_stats;
|
||||
|
||||
PRAGMA legacy_alter_table = ON;
|
||||
DROP TABLE front_page_stats;
|
||||
ALTER TABLE front_page_stats_new RENAME TO front_page_stats;
|
||||
PRAGMA legacy_alter_table = OFF;
|
||||
|
||||
|
||||
-- ── feedback.category ──────────────────────────────────────────
|
||||
|
||||
ALTER TABLE feedback ADD COLUMN category_new TEXT
|
||||
CHECK (category_new IN ('blog', 'event', 'group', 'region', 'partner', 'team', 'award', 'person'));
|
||||
UPDATE feedback SET category_new = CASE category WHEN 'chapter' THEN 'group' ELSE category END;
|
||||
ALTER TABLE feedback DROP COLUMN category;
|
||||
ALTER TABLE feedback RENAME COLUMN category_new TO category;
|
||||
|
||||
UPDATE feedback SET section_id = 'groups' WHERE section_id = 'chapters';
|
||||
UPDATE feedback SET page_path = '/groups/' || substr(page_path, 11)
|
||||
WHERE page_path LIKE '/chapters/%';
|
||||
|
||||
|
||||
-- ── Seeded text ────────────────────────────────────────────────
|
||||
|
||||
UPDATE front_page_path_actions SET description = 'Groups and regions across the country.'
|
||||
WHERE description = 'Chapters and regions across the country.';
|
||||
|
||||
UPDATE affiliations SET title = replace(replace(title, 'Chapter', 'Group'), 'chapter', 'group')
|
||||
WHERE title LIKE '%chapter%';
|
||||
|
||||
|
||||
-- ── The site's own links ───────────────────────────────────────
|
||||
-- A link to one of our group pages or the Community page's section:
|
||||
-- '/chapters/<id>', '/community#chapters', or either on our domain.
|
||||
-- Someone else's site with a /chapters/ path is left alone.
|
||||
|
||||
UPDATE links SET url = replace(replace(url, '/chapters/', '/groups/'), '#chapters', '#groups')
|
||||
WHERE url LIKE '/chapters/%' OR url LIKE '%nextgenerationofunity.org/chapters/%'
|
||||
OR url LIKE '%/community#chapters' OR url = '#chapters';
|
||||
|
||||
UPDATE content_block_items SET url = replace(replace(url, '/chapters/', '/groups/'), '#chapters', '#groups')
|
||||
WHERE url LIKE '/chapters/%' OR url LIKE '%nextgenerationofunity.org/chapters/%'
|
||||
OR url LIKE '%/community#chapters' OR url = '#chapters';
|
||||
|
||||
UPDATE content_blocks SET href = replace(replace(href, '/chapters/', '/groups/'), '#chapters', '#groups')
|
||||
WHERE href LIKE '/chapters/%' OR href LIKE '%nextgenerationofunity.org/chapters/%'
|
||||
OR href LIKE '%/community#chapters' OR href = '#chapters';
|
||||
|
||||
UPDATE featured_cards SET url = replace(replace(url, '/chapters/', '/groups/'), '#chapters', '#groups')
|
||||
WHERE url LIKE '/chapters/%' OR url LIKE '%nextgenerationofunity.org/chapters/%'
|
||||
OR url LIKE '%/community#chapters' OR url = '#chapters';
|
||||
|
||||
UPDATE timeline_entries SET link_url = replace(replace(link_url, '/chapters/', '/groups/'), '#chapters', '#groups')
|
||||
WHERE link_url LIKE '/chapters/%' OR link_url LIKE '%nextgenerationofunity.org/chapters/%'
|
||||
OR link_url LIKE '%/community#chapters' OR link_url = '#chapters';
|
||||
|
||||
UPDATE front_page_slides SET link_url = replace(replace(link_url, '/chapters/', '/groups/'), '#chapters', '#groups')
|
||||
WHERE link_url LIKE '/chapters/%' OR link_url LIKE '%nextgenerationofunity.org/chapters/%'
|
||||
OR link_url LIKE '%/community#chapters' OR link_url = '#chapters';
|
||||
|
||||
UPDATE front_page_path_actions SET url = replace(replace(url, '/chapters/', '/groups/'), '#chapters', '#groups')
|
||||
WHERE url LIKE '/chapters/%' OR url LIKE '%nextgenerationofunity.org/chapters/%'
|
||||
OR url LIKE '%/community#chapters' OR url = '#chapters';
|
||||
|
||||
UPDATE front_page SET primary_url = replace(replace(primary_url, '/chapters/', '/groups/'), '#chapters', '#groups')
|
||||
WHERE primary_url LIKE '/chapters/%' OR primary_url LIKE '%nextgenerationofunity.org/chapters/%'
|
||||
OR primary_url LIKE '%/community#chapters' OR primary_url = '#chapters';
|
||||
|
||||
UPDATE front_page SET secondary_url = replace(replace(secondary_url, '/chapters/', '/groups/'), '#chapters', '#groups')
|
||||
WHERE secondary_url LIKE '/chapters/%' OR secondary_url LIKE '%nextgenerationofunity.org/chapters/%'
|
||||
OR secondary_url LIKE '%/community#chapters' OR secondary_url = '#chapters';
|
||||
|
||||
-- [text](url) formatting in block and item text.
|
||||
UPDATE content_blocks
|
||||
SET text = replace(replace(replace(text, '](/chapters/', '](/groups/'),
|
||||
'](/community#chapters)', '](/community#groups)'),
|
||||
'nextgenerationofunity.org/chapters/', 'nextgenerationofunity.org/groups/')
|
||||
WHERE text LIKE '%](/chapters/%' OR text LIKE '%](/community#chapters)%'
|
||||
OR text LIKE '%nextgenerationofunity.org/chapters/%';
|
||||
|
||||
UPDATE content_block_items
|
||||
SET text = replace(replace(replace(text, '](/chapters/', '](/groups/'),
|
||||
'](/community#chapters)', '](/community#groups)'),
|
||||
'nextgenerationofunity.org/chapters/', 'nextgenerationofunity.org/groups/')
|
||||
WHERE text LIKE '%](/chapters/%' OR text LIKE '%](/community#chapters)%'
|
||||
OR text LIKE '%nextgenerationofunity.org/chapters/%';
|
||||
|
||||
|
||||
-- ── Triggers last (see CLAUDE.md, Migrations) ──
|
||||
-- Dropping organizations took its own triggers with it.
|
||||
|
||||
CREATE TRIGGER organizations_cleanup
|
||||
AFTER DELETE ON organizations
|
||||
BEGIN
|
||||
DELETE FROM content_blocks WHERE owner_kind = 'organization' AND owner_id = old.id;
|
||||
DELETE FROM links WHERE owner_kind = 'organization' AND owner_id = old.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER timeline_organizations_cleanup
|
||||
AFTER DELETE ON organizations
|
||||
BEGIN
|
||||
DELETE FROM timeline_entries WHERE ref_kind = 'organization' AND ref_id = old.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER organizations_featured_cleanup
|
||||
AFTER DELETE ON organizations
|
||||
BEGIN
|
||||
DELETE FROM featured_cards WHERE ref_kind = 'organization' AND ref_id = old.id;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER organizations_touch
|
||||
AFTER UPDATE ON organizations
|
||||
FOR EACH ROW WHEN new.updated_at = old.updated_at
|
||||
BEGIN
|
||||
UPDATE organizations SET updated_at = datetime('now') WHERE id = new.id;
|
||||
END;
|
||||
Loading…
Add table
Add a link
Reference in a new issue