People directories, ministries, organization contacts (migrations 062 to 064)
- People tags (062): Data → People tags (Musicians seeded); a person's Directories repeater tags them and their Specialty line shows on their tile. A People directory section preset shows a tag's first 12 and links to its full page, /directory/<tag>, with page meta and a sitemap entry. Tiles' details panels show a person's links. - Ministries (063): a new organization kind. A group picks its ministry and its page says "Ministry: <name>", linked to the ministry's website. Ministries have no public page, list, sitemap or timeline entry, and aren't offered where a record links to its organization. organizations is rebuilt for the kind CHECK. - Organization contacts (064): Data → Contact types; a private Contacts repeater on each organization (editors and up, readRole on a child collection). Tools → Newsletter → Recipients filters them by type, kind, region and published and downloads a Mailchimp CSV. - A trigger refusing a save with a sentence is shown as that message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
07e56bfd20
commit
0ed7315156
38 changed files with 1108 additions and 29 deletions
89
server/src/migrations/062_people_tags.sql
Normal file
89
server/src/migrations/062_people_tags.sql
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 062 PEOPLE TAGS AND THE PEOPLE DIRECTORY
|
||||
--
|
||||
-- A tag marks people for a directory, rather than making a team of
|
||||
-- them: Musician first, more (Speakers, Teachers) added in the admin
|
||||
-- (Data → People tags) with no code.
|
||||
--
|
||||
-- person_tag_types the tags: a name, the full directory page's
|
||||
-- intro (/directory/<id>) and their order
|
||||
-- person_tags which people carry which tags; a person's
|
||||
-- own repeater, so deleting a tag takes its
|
||||
-- rows with it (cascade)
|
||||
-- people.specialty one line shown in a directory, eg. "Vocals,
|
||||
-- piano · Gospel, folk"
|
||||
-- page_sections a 'people_directory' preset drawing one tag's
|
||||
-- people (tag_id), a short list linking to the
|
||||
-- full page; rebuilt for the preset CHECK as 058
|
||||
-- did, then its index and trigger again
|
||||
-- ═══════════════════════════════════════════════════════════════
|
||||
|
||||
CREATE TABLE person_tag_types (
|
||||
id TEXT PRIMARY KEY
|
||||
CONSTRAINT "A tag's URL ID can use only lowercase letters, numbers and hyphens, eg. musician."
|
||||
CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'),
|
||||
name TEXT NOT NULL, -- 'Musicians', the directory's title
|
||||
blurb TEXT, -- the full directory page's intro
|
||||
sort_order INTEGER NOT NULL DEFAULT 0
|
||||
) STRICT;
|
||||
|
||||
INSERT INTO person_tag_types (id, name, blurb, sort_order) VALUES
|
||||
('musician', 'Musicians', 'Musicians in the NGU community, for services, retreats and events.', 0);
|
||||
|
||||
CREATE TABLE person_tags (
|
||||
person_id TEXT NOT NULL REFERENCES people (id) ON DELETE CASCADE,
|
||||
tag_id TEXT NOT NULL REFERENCES person_tag_types (id) ON DELETE CASCADE,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (person_id, tag_id)
|
||||
) STRICT;
|
||||
|
||||
CREATE INDEX person_tags_tag_idx ON person_tags (tag_id);
|
||||
|
||||
ALTER TABLE people ADD COLUMN specialty TEXT;
|
||||
|
||||
|
||||
-- ── page_sections: the directory preset ────────────────────────
|
||||
|
||||
CREATE TABLE page_sections_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
page_id TEXT NOT NULL REFERENCES site_pages (id) ON DELETE CASCADE,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
anchor TEXT NOT NULL
|
||||
CONSTRAINT "A section's URL ID can use only lowercase letters, numbers and hyphens, eg. leadership."
|
||||
CHECK (anchor <> '' AND anchor NOT GLOB '*[^a-z0-9-]*'),
|
||||
title TEXT NOT NULL
|
||||
CONSTRAINT "A section title can be 30 characters at most (it's listed in the page's side nav)."
|
||||
CHECK (length(title) <= 30),
|
||||
blurb TEXT,
|
||||
accent TEXT CHECK (accent IN ('teal', 'deep', 'green', 'amber')),
|
||||
preset TEXT CHECK (preset IN ('community_blog', 'group_map', 'region_list', 'partner_list',
|
||||
'events', 'timeline', 'people_directory')),
|
||||
-- An events preset's filter and first view.
|
||||
scope_id TEXT REFERENCES event_scopes (id) ON DELETE SET NULL,
|
||||
event_type TEXT CHECK (event_type IN ('retreat', 'class', 'workshop', 'meeting', 'other')),
|
||||
view TEXT CHECK (view IN ('carousel', 'grid', 'map')),
|
||||
-- A people_directory preset's tag.
|
||||
tag_id TEXT REFERENCES person_tag_types (id) ON DELETE SET NULL,
|
||||
UNIQUE (page_id, anchor)
|
||||
) STRICT;
|
||||
|
||||
INSERT INTO page_sections_new
|
||||
(id, page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view)
|
||||
SELECT id, page_id, sort_order, anchor, title, blurb, accent, preset, scope_id, event_type, view
|
||||
FROM page_sections;
|
||||
|
||||
PRAGMA legacy_alter_table = ON;
|
||||
DROP TABLE page_sections;
|
||||
ALTER TABLE page_sections_new RENAME TO page_sections;
|
||||
PRAGMA legacy_alter_table = OFF;
|
||||
|
||||
CREATE INDEX page_sections_page_idx ON page_sections (page_id, sort_order);
|
||||
|
||||
|
||||
-- ── Triggers last (see CLAUDE.md, Migrations) ──
|
||||
|
||||
CREATE TRIGGER page_sections_cleanup
|
||||
AFTER DELETE ON page_sections
|
||||
BEGIN
|
||||
DELETE FROM content_blocks WHERE owner_kind = 'page_section' AND owner_id = CAST(old.id AS TEXT);
|
||||
END;
|
||||
114
server/src/migrations/063_ministries.sql
Normal file
114
server/src/migrations/063_ministries.sql
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 063 MINISTRIES
|
||||
--
|
||||
-- A Unity ministry (a church) is an organization of its own kind, so
|
||||
-- the list of them is kept here and an NGU group can name the one it
|
||||
-- belongs to. Ministries have no page and no list on the public site:
|
||||
-- a group's page says "Ministry: <name>", linked to the ministry's
|
||||
-- website when it has one.
|
||||
--
|
||||
-- organizations.kind gains 'ministry' (the CHECK changes, so the
|
||||
-- table is rebuilt as 052 did, then its indexes
|
||||
-- and triggers again)
|
||||
-- groups.ministry_id the group's ministry, cleared if the ministry
|
||||
-- is deleted; the trigger below keeps it to
|
||||
-- ministries
|
||||
-- ═══════════════════════════════════════════════════════════════
|
||||
|
||||
CREATE TABLE organizations_new (
|
||||
id TEXT PRIMARY KEY, -- slug: 'northwest', 'lynnwood'
|
||||
kind TEXT NOT NULL
|
||||
CHECK (kind IN ('national', 'region', 'group', 'partner', 'ministry')),
|
||||
|
||||
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, 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
|
||||
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);
|
||||
|
||||
|
||||
-- ── groups.ministry_id ─────────────────────────────────────────
|
||||
|
||||
ALTER TABLE groups ADD COLUMN ministry_id TEXT REFERENCES organizations (id) ON DELETE SET NULL;
|
||||
|
||||
|
||||
-- ── Triggers last (see CLAUDE.md, Migrations) ──
|
||||
|
||||
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;
|
||||
|
||||
CREATE TRIGGER groups_ministry_kind
|
||||
BEFORE INSERT ON groups
|
||||
FOR EACH ROW WHEN new.ministry_id IS NOT NULL
|
||||
AND (SELECT kind FROM organizations WHERE id = new.ministry_id) IS NOT 'ministry'
|
||||
BEGIN
|
||||
SELECT RAISE(ABORT, 'A group''s ministry must be a ministry.');
|
||||
END;
|
||||
|
||||
CREATE TRIGGER groups_ministry_kind_update
|
||||
BEFORE UPDATE OF ministry_id ON groups
|
||||
FOR EACH ROW WHEN new.ministry_id IS NOT NULL
|
||||
AND (SELECT kind FROM organizations WHERE id = new.ministry_id) IS NOT 'ministry'
|
||||
BEGIN
|
||||
SELECT RAISE(ABORT, 'A group''s ministry must be a ministry.');
|
||||
END;
|
||||
38
server/src/migrations/064_org_contacts.sql
Normal file
38
server/src/migrations/064_org_contacts.sql
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 064 ORGANIZATION CONTACTS
|
||||
--
|
||||
-- Who to write to at an organization, by role, so a mailing list can
|
||||
-- be exported (Tools → Newsletter → Recipients) filtered by role,
|
||||
-- kind and region. Private: never sent to the public site.
|
||||
--
|
||||
-- contact_types the roles, made in the admin (Data →
|
||||
-- Contact types), eg. Minister, General
|
||||
-- info; none are seeded
|
||||
-- organization_contacts an organization's contacts, each with a
|
||||
-- role; its own repeater on the organization.
|
||||
-- A role still in use can't be deleted (the
|
||||
-- foreign key refuses it)
|
||||
-- ═══════════════════════════════════════════════════════════════
|
||||
|
||||
CREATE TABLE contact_types (
|
||||
id TEXT PRIMARY KEY
|
||||
CONSTRAINT "A contact type's URL ID can use only lowercase letters, numbers and hyphens, eg. minister."
|
||||
CHECK (id <> '' AND id NOT GLOB '*[^a-z0-9-]*'),
|
||||
name TEXT NOT NULL, -- 'Minister'
|
||||
sort_order INTEGER NOT NULL DEFAULT 0
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE organization_contacts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
org_id TEXT NOT NULL REFERENCES organizations (id) ON DELETE CASCADE,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
type_id TEXT NOT NULL REFERENCES contact_types (id),
|
||||
name TEXT,
|
||||
email TEXT,
|
||||
phone TEXT,
|
||||
CONSTRAINT "A contact needs an email or a phone number."
|
||||
CHECK (email IS NOT NULL OR phone IS NOT NULL)
|
||||
) STRICT;
|
||||
|
||||
CREATE INDEX organization_contacts_org_idx ON organization_contacts (org_id, sort_order);
|
||||
CREATE INDEX organization_contacts_type_idx ON organization_contacts (type_id);
|
||||
Loading…
Add table
Add a link
Reference in a new issue