CRM: schema and permission model
Design doc for the CRM’s Directus data model, per the plan agreed on issue cyc-seattle/isthmia#69. Covers person
identity, provenance, and permission policies — see schemas/crm.yaml and
schemas/clubspot.yaml for collections and fields; deployment and rollout are tracked in
the sibling issues (cyc-seattle/isthmia#92-cyc-seattle/isthmia#95) that decompose cyc-seattle/isthmia#69.
Scope and non-goals
- Models what Clubspot actually gives us: people, their guardian/emergency-contact relationships,
the camp schedule (camps/sessions/classes/capacity), registrations, and billing. Clubspot has no
household, only per-registration guardians and emergency contacts, so the sync makes
householdsfrom the guardian links (Households). - The CRM’s terms are ours, and Clubspot’s appear only in its mirrors and the sync
(cyc-seattle/isthmia#241). A program is a lasting thing CYC runs, such as Guppies or J-Pod, and
is what a Google Group or a Crew term attaches to. A program with
teamset is a team, such as a race team. An offering is the catalog’s: what CSC sells, one product, such as a program, for one dated period (cyc-seattle/platform#332, cyc-seattle/platform#395). A Clubspot camp (clubspot_camps) is only how people sign up, built from a registration form’s offerings each season, and staff link each offering to the Clubspot class, and session, that sells it. A registration is ours, made from Clubspot’s entries (Collections). We say registration, not “enrollment.” - Registration status and person contact fields get history, not just a current value — see Change tracking and provenance.
- Person identity is resolved once, at creation, and never re-resolved — see Person identity and merging.
- Auth identity is deliberately separate from person data — see Auth identity below.
- Apps, such as sail-team, call this API as the signed-in user, and Directus applies that user’s rules (access.md).
Collections
Collections and fields are defined in schemas/crm.yaml and schemas/clubspot.yaml
— the Clubspot-shaped collections (clubspot_camps, clubspot_sessions, clubspot_classes, registrations, and custom
fields) live in the latter, split out because they wouldn’t survive Clubspot being replaced. Both
are the source of truth Pulumi applies to Directus as one merged snapshot. The sections below cover
identity, provenance, and permissions — behavior that isn’t visible in either schema file itself.
Every collection that mirrors Clubspot carries the clubspot_ prefix, since Directus keeps every
collection in one namespace and Clubspot’s terms are ours only at the sync boundary
(cyc-seattle/isthmia#241). The CRM’s own registrations are made from them:
- A catalog offering (
offerings, inschemas/core.yaml) is one Clubspot class in one session (cyc-seattle/platform#395), so it links to both, or to neither, which a check on the table keeps. A registration form is one Clubspot camp. A Catalog Writer sets the links. The link fields are declared inschemas/clubspot.yaml, beside the mirrors they point at. When Clubspot deletes the class or the session, a trigger clears both links, and doesn’t delete the offering. Thecatalog-ruleshook installs the check, the triggers, and the index that keeps one offering to a class and session. - A registration is one person in one offering, from one
clubspot_registration_entriesrow, with its status. An entry waits until its participant is matched to a person, and until an offering is linked to its class and session. A cleared or changed link never deletes a registration.
clubspot-sync makes the registrations after each run’s camps, from every camp’s mirrors, archived ones
included, and deletes one only with its Clubspot entry. Staff read them, and no one edits them. It
also writes each offering’s confirmed_count, which the public website reads in place of the
registrations, and reports an offering whose dates or cap differ from its Clubspot class and session
(offering_differs). An offering with registrations can’t be deleted.
Until cyc-seattle/platform#332’s migration cyc0027, clubspot-sync made the offerings themselves. The
migration kept each one, with its ID, as a catalog offering on a registration form for its camp.
clubspot_registration_entries also carries five nullable columns for Clubspot’s own per-entry status and
waitlist bookkeeping: clubspot_status, confirmed_at, waitlist_number, accepted_from_waitlist,
priority. Their field notes in schema.yaml cover the why. This file does not repeat it.
programs is a hand-maintained catalog, not synced from Clubspot. Who does what in a program or
program area, such as its Parent Coordinator or Director, is a Crew term
(crew-schema.md). The cyc0028 migration moved the old program roles there.
A program’s revenue account is its program area’s, or its product’s own for a product in no area. gsuite-sync’s audit
reads it to flag a Clubspot Camp whose classes map to programs with more than one distinct account
(cyc-seattle/isthmia#149).
programs and program_areas live in schemas/core.yaml, the catalog.
programs.product_id makes each program a subtype of a product of kind program, per AGENTS.md’s
subtype pattern, so every program has one. gsuite-sync’s audit reports a program whose product is
of another kind.
gsuite-sync extends collections it doesn’t own rather than owning separate ones: it declares
programs.google_group_id in its own schema, even though programs belongs to core, not this
package - groups hang off programs only. clubspot_classes.program_id, by contrast, is a plain field
declared directly in schemas/clubspot.yaml, since clubspot-sync owns the collection it
came from. clubspot-sync sets it from the offerings linked to the class, for gsuite-sync, which still
reads it. Every package’s schema is merged into one snapshot and applied together, so a
collection here can carry another package’s field without this package knowing about that
provider.
Every Clubspot collection keys on the Clubspot objectId itself, entered by the sync rather than
generated (schemas/clubspot.yaml’s field notes cover each collection). clubspot_session_classes
and clubspot_custom_field_responses have no Clubspot id of their own, so their key is their two parents’
ids joined ("<parent id>:<parent id>"); both parents stay as real FK columns alongside it.
Person identity and merging
A contacts row links two people: subject_id is the person the record is about (a minor, usually
— the same person clubspot_registrations.participant_id -> clubspot_participants.person_id points to), and
contact_id is their guardian or emergency contact. Both are resolved once, when the row is
created, and never re-resolved. A later sync run leaves an existing row’s person field alone —
that’s what makes a manual merge (below) durable: nothing undoes it on the next run.
Matching a new row to an existing person. Directus’s REST filters give only _eq and
_icontains, so “fuzzy” means: normalize the incoming data, fetch a small candidate set with an
indexable filter, then compare in the client.
- Participant — same normalized first and last name, and the same date of birth. Without a date of birth, also require the same normalized email.
- Guardian — same normalized email and last name, allowing one character of edit distance on the first name. With no email match, falls back to the emergency-contact rule below (name and phone) — a parent first seen as an emergency contact has no email on file to match against.
- Emergency contact — same normalized full name and phone, or the same email when Clubspot has one.
A guardian or emergency contact never matches the minor it’s a contact for, nor anyone else under 18.
An email alone is never a match — families share one address across two different adults. No match
creates a new people row. The matcher is deliberately reluctant: a false split just makes a
duplicate staff merge in a minute, but a false merge silently attaches one family’s registration to
another person’s medical and emergency data.
Updating an existing person follows one rule for every curated field — people, medical_profiles,
a guardian/emergency contact’s own people row, and a promoted field (cyc-seattle/isthmia#137): the latest edit
always wins, whether it was made in Directus or in Clubspot (cyc-seattle/platform#157). A
person’s newest linked participant is ranked non-archived registrations first, then
registered_at descending, then clubspot_registrations.id as a tiebreak — the same order clubspot_promoted_fields
falls back to below. The mirror itself — clubspot_participants for every field but a promoted one,
clubspot_custom_field_responses for that — keeps Clubspot’s last non-blank answer: a blank form value
never overwrites a value already stored there. The sync compares base (the mirror’s own stored
value) against v (what Clubspot sends now): v equal to base writes nothing, so a staff edit
holds; v different from base writes v, and counts a replaced staff edit if the CRM value was
neither base nor null; a null v is never written, for any field — a removed allergy or a blanked
phone number stays on the CRM record until staff clear it. Only the newest linked participant may
write at all — an older registration’s form never overwrites a newer one’s.
That rule settles Clubspot against itself. When someone other than clubspot-sync set the field’s
current value, edit times settle it instead: Clubspot’s answer replaces that edit only if it was
given later, whether or not it repeats base, and a blank is still never written. The edit’s time
is its latest revision in Directus, read only for a row the sync is about to change. An edit made
outside the Directus API, or one whose revision was pruned, isn’t seen, so the base rule applies.
An answer is dated by its registration’s confirmation, or by the participant’s updatedAt when it
differs from this participant’s own mirrored answer, since updatedAt moves when any answer
changes. Clubspot doesn’t date its answers against each other, so two siblings’ forms naming the
same guardian differently fall to the base rule, not to time.
A people.phone is compared and written in E.164 (+12065550100), the form the club’s apps save,
taking a number with no country code as US. Clubspot’s bare digits for the number a family entered
then compare equal, and don’t overwrite it. A number that isn’t valid, or has an extension or a note E.164 can’t hold, is kept as typed.
Only a participant mirrored for the first time ever — base entirely unknown, not merely a known
blank — falls back to the person’s previous newest other linked participant’s own value, so a new
season’s changed answer still has something to compare against instead of only ever filling a null
column. Only with neither an own value nor a fallback does a field fill a null CRM column and
nothing else. A fallback drawn from an older registration’s guardian or emergency-contact slot is
used only when its name still matches the person that slot links to today — an older registration’s
different guardian in the same slot order (last season’s other parent, say) must never become the
base for a staff correction on the person actually linked now.
Merging a duplicate. clubspot-sync raises a duplicate_person finding for two people rows
sharing a normalized name, naming the one with the most linked participants as keeper. Review it in
the Data Studio: read detail for each row’s id and date of birth, and check my_contacts,
contact_for, and participant_links on each one’s detail page if you need to see more. Two people
who are genuinely different (a parent and child sharing a name, say) get the finding dismissed. Two
who are the same person get it set to approved.
The next sync run does the merge: it relinks every duplicate’s participants to the keeper, folds
medical profiles and contacts onto it, moves every duplicate’s logins to it, fills the keeper’s null
fields from the duplicates, and deletes each duplicate once nothing references it any more. The
finding then reads resolved. If a run can’t finish a merge — the group no longer shares a name,
or something still references a duplicate after the merge — it sets the finding back to open and
logs why, for another look.
Unmerging is manual: create a new person, and point the wrongly-merged participant’s
person_id at it in the Data Studio. The sync never re-resolves a linked participant, so this is
durable. Move that participant’s contacts and contact_points rows onto the new person by hand.
Deleting a person by hand in the Data Studio is refused while anything still references them —
every FK to people except clubspot_participants.person_id is on_delete: RESTRICT. Delete or repoint
their contacts, contact points, medical profile, and role assignments first, or approve a
duplicate_person merge instead.
Households
A household is everyone joined through a sailor: the sailor, each of their guardians, and those
guardians’ other children, transitively (cyc-seattle/sail-team#29). Parents with separate Clubspot
accounts land in one. Emergency contacts join none. Each person is in at most one,
people.household_id, which only clubspot-sync writes.
Clubspot decides who’s linked to whom, so no one edits membership. clubspot-sync makes every
household again at the end of each run (src/syncs/clubspot/households.ts), from the contacts
guardian links and the people clubspot_participants links to. A staff merge or unmerge of people
changes those links, so the next run follows it. A household keeps its id while most of its people
stay together:
- Two households joined by a new link become the larger one, and the other is deleted.
- A household split in two keeps its id in the larger part, and the smaller part gets a new one.
- A household with no one left in it is deleted.
One wrong guardian link joins two unrelated families into one household. That’s a known trade-off: the sync guards against nothing here, and a bad link is fixed in Clubspot.
households.share_contact is the opt-in for its adults’ email and phone (Community).
When two households join, any no wins, then any yes, and otherwise it stays blank. A split copies it
to both. A household made where none was takes its people’s old people.share_contact by the same
rule, and so does someone who joins a household from none. That’s how the first run moved the per-adult answers onto households.
people.share_contact is read-only, and goes in a later release.
people.display_name is the name apps show, set by the person or their household (cyc-seattle/sail-team#31). No
sync writes it. A merge fills a keeper’s blank one from a duplicate’s.
Change tracking and provenance
Directus already does this: every API-driven create/update/delete is logged in directus_activity
(who, when, on what) with a paired directus_revisions row holding the full item snapshot and a
delta — for every collection, no opt-in needed, so there’s no need for bespoke history
tables here, as long as the sync always writes through the Directus API (never raw SQL):
- Registration status (waitlist → confirmed → cancelled) doesn’t need its own event log — the
revision history on a
clubspot_registration_entriesrow already shows every state it’s been in and when Directus recorded each change. If Clubspot’s own historical timestamps (RegistrationCampSession.waitlist_updates) matter and not just “when we noticed,” the sync’s first import of a registration can replay each transition as its own sequential write so the revision order matches reality — though the revision timestamp is always “when Directus saw the write,” not the original Clubspot moment; a backfill can’t inject history at an arbitrary past time. - Person contact-field changes (a guardian’s email changing between registrations two years
apart) are the same story: the revision history on a
peoplerow already shows every valueemail/phone/first_name/last_namehas held, including the ones the one CRM field rule above replaced. Confirmed by looking at the live participants spreadsheet (the thing the sync replaces) — it’s a fully-rebuilt-every-run flat snapshot with no timestamp or version on any row today, which is the actual gap here, and Directus’s activity log closes it without any schema of our own.
This is row history, not run history. Which sync tasks ran, retried, or failed is tracked
separately, in the sync_tasks queue (src/syncs/runtime/) — infrastructure shared by every sync,
not part of this schema.
What the activity log doesn’t give us: a revision is attributed to the Directus user who made
the write — for the sync’s automated updates that’s always its own service account, not which
registration supplied a given value. No dedicated pointer for that here: clubspot_registrations.participant_id
-> clubspot_participants.person_id already gives every registration a person touched, so “which one most
recently supplied this email” is a join against that plus the revision timestamps, not a separate FK
on people. That join is untested against real staff workflows; revisit if it turns out too awkward
to actually use.
Schools
people.school_id is the school someone sails for, which may not be the one they attend, picked from
schools. A school not on the list is people.school, in the family’s own words, with school_id
blank: a person has one or the other, never both. The school-choice hook keeps it so for every
writer through Directus: setting one clears the other, and setting both is refused. Staff keep the list, and each school’s aliases
hold the other ways families write it. Families pick from it in the club’s apps.
The sync files a Clubspot answer under the school whose name or alias matches it, ignoring case and punctuation and counting a run of spaces as one, and otherwise keeps it as their own words. A name that matches two schools matches neither. There’s no fuzzy match: staff add an alias, and the next answer matches. It compares answers by the school they name, so a family’s pick stands until Clubspot names a different school.
Promoted fields
clubspot_promoted_fields maps a Clubspot custom-field question — asked per camp, so
clubspot_custom_field_definitions has no single row for it — onto a people column. school is the only
target today, written as school_id and school (Schools); adding another means adding it to PROMOTABLE_PERSON_FIELDS
(src/model/clubspot/promoted-fields.ts) and deploying, not editing config. It follows the same
one CRM field rule as every other curated field (cyc-seattle/isthmia#137): per registration, clubspot_custom_field_responses
is itself the mirror, keeping its own last non-blank answer the same way clubspot_participants does, so
base is the response’s own stored value before this run’s write and v is what Clubspot sends
now, gated on the same newest-linked-participant check. A separate pass runs
once more at the end of every run, across every camp, purely as a gap-fill fallback for a
registration the per-registration pass didn’t reach this run — ranking candidate responses the same
way (non-archived before archived, then most recent, with a stable tiebreak) and filling only a
still-null column.
The row is staff-maintained, not Pulumi-managed: applying it from schema.yaml would revert a
staff edit to its labels on the next deploy.
Auth identity
Auth info does not live on people. Directus already has its own identity table — directus_users
— with roles, policies, and OIDC provider/external_identifier fields for linking a Google login.
Reusing it instead of a homegrown field means:
directus_users.person_idis a nullable FK topeople.id, declared inschemas/access.yaml, so a person can have any number of logins, such as a personal and a work email.people.loginslists them. The group hook links a person’s first login by email, and an admin links any other. No policy a person can hold writes it. Deleting a person empties it on their logins and keeps the logins.- Directus’s own OIDC config matches a sign-in to its
directus_usersrow (provider+external_identifier). The group hook then links that login to a person by email, once (access.md). Rules match the signed-in user by that link, not by email.
Community
sail-team’s roster page, at cycsail.team/roster, shows a signed-in family their own family, and a
family on a team every team’s roster, through the Community and Team policies
(stacks/backend/community-rules.ts, access.md). A team member’s email and
phone show only for an adult whose household chose to share. Crew sees everyone’s contact details and medical
information, shared or not. A position in a program, such as Parent Coordinator, gives no access.
Directus runs a filter or sort against the raw column once any rule grants the field, and joins a
relational filter’s rows with no rules at all. So backend mounts the query guard
(access.md), which refuses a query filtering, sorting, grouping, or
aggregating on a field some of the user’s rules withhold, or crossing a relation into a collection
they read only in part.
The opt-in is households.share_contact, nullable, one per household. An adult in the household
changes it. Clubspot asks the sharing question on each sign-up, and clubspot-sync keeps the answer
on the sign-up, clubspot_registrations.share_contact, and copies it to the sailor’s household
(syncs.md). The latest answer wins.
Permission model
access.md has the roles, the policies, and the groups that give them.
- Emergency contacts get no role or login. They’re informational rows staff can see on a minor’s
record (
contactswhererelationship_type == 'emergency_contact'), not a portal audience.