Status: accepted · Date: 2026-11-16 · Spec: docs/bjj-journey/specs/team-trips.md · Builds on: ADR-0003, ADR-0009, ADR-0016, ADR-0017, ADR-0022
A professor takes students to a competition. The students are not Members of the professor's Organization, and must not become Members to join: that would show them the academy's files and todos. So a Team Trip cannot be scoped by the Active Organization like every other tenant table.
Decision
Ownership. A Team Trip (team_trip) belongs to one Organization: an Academy's, when its owner or admin creates it there, or the organizer's personal Organization. The owner Organization's owners and admins administer the trip (app.org_admin). Creating a trip needs Pro (owner decision 2), enforced by the server through the User's billing entitlements (billing.service#hasPaidAccess; where billing is not configured nothing is sold, so nothing is withheld) and in the app by useProGate("teamTripCreate"). Joining is free.
Visibility follows Trip Membership. Procedures run as the signed-in User (userProcedure) with no Active Organization. Row-level policies admit rows through SECURITY DEFINER helpers in app (kept in packages/db/scripts/rls-baseline.mjs and verified by db:verify-rls), which avoid recursion on team_trip_member:
trip_state(trip)andtrip_role(trip): the caller's membership state, and Trip Role while joined;trip_inviter(trip): whose link the caller joined through;org_admin(org)andtrip_admin(trip): owner or admin of the (trip's) Organization;trip_counts(trip): going and maybe totals, for anyone in the trip and its admins.
| Table | Who reads | Who writes |
|---|---|---|
team_trip | joined or pending members, owning admins | insert: an owner/admin of the Organization as created_by; update: organizers and owning admins |
team_trip_member | own row; every row for organizers and owning admins; for anyone in the trip, the organizers', their own Inviter's and the rows of members visible to the group | insert: own row only, as member (or as organizer of a trip one administers); update: own Attendance and Shared Fields (never one's own state or role); organizers approve; delete: organizers decline pending joins |
team_trip_invite | its creator, organizers, owning admins | insert: organizers, or members while the trip allows member invites |
team_trip_consent | own rows | insert own rows; append-only |
RLS is per row; the service projects columns per role. A plain member's roster has totals (from trip_counts) and the names and belts of members visible to the group, nothing else. An organizer never sees a member's email, phone, location, archive, results, weight, Breaks or injuries — those columns do not exist.
The public invite page crosses tenants once. Reading an invite by its code hash, before the reader is a member, is the system read team-trips.invite-preview (asSystem, reviewed in system-call-sites.txt). It returns the event, the trip title, the academy name, the organizer's and the Inviter's display names and the count going — never other member names. The same read resolves a join; the join itself is a tenant write as the joining User.
Invite Links. One active link per (trip, inviter), created on the first share. The code is 8 Crockford base32 characters (40 bits) derived as an HMAC of the invite id under the server secret, so the same link can be shown again without storing it; the database holds only its SHA-256. Links expire 7 days after the event; a link stops working when revoked, when its Inviter is no longer a joined member, or when member links are switched off. URLs are https://<web domain>/t/<code>; the app opens them as universal / App Links (apple-app-site-association, assetlinks.json) and bjj-journey://join/<code>.
Join policy (owner decision 1): through an organizer's or co-organizer's link a person joins at once; through a member's link they are pending until an organizer approves. The organizer may switch to "everyone needs approval" or "anyone with a link". Joining needs the optional account and an explicit 16+ confirmation (owner decision 3); the birth year never leaves the device.
Data shared (ADR-0016/0017): display name and Attendance (Art. 6(1)(b)); Shared Fields — visible to the group, belt and stripes, division as Mode, Age Division and Weight Class name — are each an opt-in consent (Art. 6(1)(a)), off by default, logged in team_trip_consent on every grant and withdrawal. A field switched off stores no value (CHECK constraints). The contract's share values are a strict schema: no kg, birth year, Break, injury or budget field can be sent.
Consequences
- Every new trip-scoped table needs its policy expressed through these helpers, not
inActiveOrganization; the isolation suiteteam-trips.rls.test.tsruns intest:rls-matrix. - Counts for members are computed in SQL by a definer function, so hidden rows never reach them.
- S9 adds notices, co-organizer management, leaving and account deletion (the member row, Shared Fields and acknowledgements go at once; consent rows stay as the legal record until the account is deleted), abuse controls (rate limits, active-trip and member caps, revoke all links) and the web dashboard. Release to real academies waits for S9 and the lawyer note on the controller role.
- The production web domain is
[TBD]; until it exists, universal links stay off and the custom scheme carries the code.
Amendment 1 (2026-11-17, S9: US-46..US-51)
Notices. team_trip_notice (read by joined members and owning admins; written by organizers, co-organizers and admins) and team_trip_notice_ack (own rows; organizers read all). An acknowledgement references its member row through a composite foreign key with ON DELETE CASCADE, so leaving, removal and account deletion take the acknowledgements with the row, as the decision above requires. Deleting a notice is soft (text cleared at once, row purged with the rest 90 days after the event) so it keeps counting toward the 5-a-day and 15-a-week limit. A notice's optional time is the event's wall clock, sent with a zero offset and shown in UTC, because catalogue events carry no time zone.
Push. The spec named a separate trip-notice-fanout crossing; the fan-out runs instead inside the cron tick's existing jobs.tick crossing (team-trips.jobs.ts), which already addresses push devices across Organizations. It writes push_delivery rows with a new trip_notice_id (cascade on the notice) per device of a joined, unmuted member other than the author; the existing push job sends them, re-checks the membership and builds the text in the member's language when it sends: neutral by default, the notice text only for members who turned notice_preview on for that trip (owner decision 4). With server push off the fan-out completes without deliveries.
Roles. The policies let nobody write an organizer row, and a member cannot change their own role or state. Handing the organizer role over is the reviewed system write team-trips.organizer, after the caller's right was checked as the tenant and again inside the system transaction. When an organizer's account is deleted, the cron job hands the trip to the oldest co-organizer, else the owning Organization's oldest owner or admin (who joins as organizer under their account name), else sets orphaned_at: the trip is read-only, its members get one system notice, and it is archived 30 days later.
Leaving and retention. A member deletes their own row (never a blocked one, never the organizer's); organizers delete anyone's but the organizer's. Blocking keeps an empty blocked row. The cron job ends a trip after its event, archives it 30 days later (freezing aggregate counts in team_trip.summary, never names or ids, and purging seat, bed, companions and "registered") and deletes notices 90 days after the event. "My Team Trips" in the full export (exportMine) is not behind team.trips, so what a User shared stays exportable if the flag is switched off.
Abuse controls. The "3 active trips per free user" rule is superseded by owner decision 2 (only Pro creates). Kept: 300 joined or pending members per trip, 20 joins per link per hour, notice rate limits, revoke all links, noindex public pages, and team_trip_report (written by anyone in the trip, one open report each; platform admins list and resolve them through adminProcedure, optionally archiving the trip).
Amendment 2 (2026-11-17, S9 review fixes and §4.5/§4.6 pushes)
Joins are a reviewed system write. The decision above made the join a tenant write as the joining User. The 300-member cap and the per-link rate must be checked and spent in one transaction, and the joiner (not a member yet) cannot see the other members through the policies. So join resolves the code through team-trips.invite-preview, then runs one transaction under the new system reason team-trips.join: it locks the team_trip row (FOR UPDATE), re-reads the trip state, the invite and the caller's row, counts joined and pending members, checks the link's hourly window, inserts the member row and its consent rows, and spends one join on the invite. Concurrent joins queue on the lock. The caller's identity comes from the session; the row is always member with the state from the join policy.
The per-link rate is a durable counter on the invite. team_trip_invite.join_window_start and join_window_count count joins in the hour that began at the window start; leaving deletes the member row but never gives a join back. The counter goes with the invite, which goes with the trip. The window is fixed per hour, not sliding.
Notice limits hold under concurrency. postNotice counts and inserts in one tenant transaction that first locks the trip row (SELECT … FOR UPDATE, admitted by the update policy for organizers and owning admins), so overlapping posts queue.
Approvals batch and nudge. The cron tick also queues (a) one neutral push per trip per hour to joined, unmuted organizers and co-organizers when members joined pending since the last batch (team_trip.approvals_pushed_at), and (b) one neutral "are you going?" push to each joined, unmuted member with no Attendance in the 7 days before the next price rise (else the event's first day), at most one per trip per week (team_trip_member.nudged_at). Both are push_delivery rows with trip_id and trip_push (approvals or nudge, cascade on the trip); the push job re-checks eligibility and builds the text in the member's language at send time, and drops the push when nobody is pending or the member has answered. Mute stops both.