Redesign Phases 3-6: multi-event model, APPE Admin, Convivo App behaviors, APPE branding

- Phase 3: new migration 20260824000000_redesign.sql (contacts/events/registrations/sponsors, slot types, session speakers + feedback/material), seed rewrite
- Phase 4: APPE Admin rebrand + Contacts/Registrations/Sponsors/Schedule/Activity/Events views
- Phase 5: Convivo App (24h login, 5s polling, QR type badge, red dot, speaker material)
- Phase 6: APPE favicon + PWA icons for both apps
- Docs: schema/rpcs/rls/seed/screens/api-client/admin-app/architecture/next-steps/README/roadmap updated
This commit is contained in:
Lago committed 2026-08-23 02:53:16 +02:00
1 parent 5adb5785aa
commit 22f5f1d317
64 files changed
+4593 -1371

No files matched your search

+9 -6
View File
@@ -7,23 +7,24 @@ Postgres. This folder documents that core.
| File | What it covers |
|---|---|
| [supabase-core.md](./supabase-core.md) | The local stack: containers, ports, how to start/reset, config |
| [schema.md](./schema.md) | All 9 tables, columns, constraints, indexes |
| [schema.md](./schema.md) | All 13 tables, columns, constraints, indexes |
| [rpcs.md](./rpcs.md) | The transactional points RPCs (the business logic) |
| [rls.md](./rls.md) | Row Level Security policies + which key the app uses |
| [seed.md](./seed.md) | Seed data + the 13 demo accounts |
| [seed.md](./seed.md) | Seed data + the demo accounts |
| [docker.md](./docker.md) | Docker: the app image + root compose (how the core + app run together) |
## The big picture
```
Postgres 17 ── schema (9 tables)
Postgres 17 ── schema (13 tables, multi-event model)
── RLS (who can read/write what)
── RPCs (security definer, transactional points logic)
── seed (demo data)
```
- **Data + logic live in the database.** The app never computes points or writes
to `profiles.points` directly — it calls RPCs, and Postgres enforces the rules.
to `registrations.points` directly — it calls RPCs, and Postgres enforces the
rules.
- **RLS is the security boundary.** The app uses the **anon key + the user's
session JWT**; RLS decides what that user may see and do. The service-role key
is never shipped to the app. See [rls.md](./rls.md).
@@ -33,7 +34,9 @@ Postgres 17 ── schema (9 tables)
## Source of truth
- Schema + RPCs + RLS: [`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql)
- Admin app (Phase 2): admin read RLS + `reset_qr_token` RPC — [`supabase/migrations/20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql)
- Schema + RPCs + RLS (the Redesign, **current**): [`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql)
- Earlier migrations (still applied, then replaced by the Redesign):
[`20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql) and
[`20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql)
- Seed: [`supabase/seed.sql`](../../supabase/seed.sql)
- Stack config: [`supabase/config.toml`](../../supabase/config.toml)
+1 -1
View File
@@ -56,7 +56,7 @@ same-origin paths to the core:
| `/auth/` | `__SUPABASE_PROXY_TARGET__` | GoTrue |
| `/rest/` | `__SUPABASE_PROXY_TARGET__` | PostgREST (tables + RPCs) |
| `/realtime/` | `__SUPABASE_PROXY_TARGET__` | WebSocket — `Upgrade`/`Connection` headers + long timeouts |
| `/storage/` | `__SUPABASE_PROXY_TARGET__` | Storage (unused in v1) |
| `/storage/` | `__SUPABASE_PROXY_TARGET__` | Storage — the `materials` bucket (session material) |
`__SUPABASE_PROXY_TARGET__` is replaced at start with the value of the
`SUPABASE_PROXY_TARGET` env var (default `supabase_kong_Convivo:8000`).
+103 -61
View File
@@ -1,12 +1,12 @@
# Row Level Security (RLS)
RLS is the security boundary. It is **enabled on all 9 tables**, and every policy
is scoped to the `authenticated` role. The `anon` role has `GRANT select` at the
Postgres level, but RLS blocks it from reading anything — so an unauthenticated
request sees no rows.
RLS is the security boundary. It is **enabled on all 13 tables**, and every
policy is scoped to the `authenticated` role. The `anon` role has `GRANT select`
at the Postgres level, but RLS blocks it from reading anything — so an
unauthenticated request sees no rows.
Source of truth:
[`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql)
[`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql)
(RLS section).
## Which key does the app use?
@@ -26,91 +26,132 @@ Source of truth:
## Role helpers
Two `security definer` functions drive role checks (see [rpcs.md](./rpcs.md#role-helper-functions)):
- `is_admin()` — current user's profile has `role = 'admin'`
- `is_staff_or_admin()` — current user's profile has `role in ('staff','admin')`
`security definer` functions drive role checks (see
[rpcs.md](./rpcs.md#role-helper-functions)):
- `current_email()` — `auth.jwt() ->> 'email'` (the identity; `contacts` is keyed
by email)
- `is_admin()` — current contact has `is_admin = true`
- `is_staff_or_admin()` — = `is_admin()` (staff is merged into admin)
- `is_speaker_or_admin()` — admin, or a speaker of an active-event session, or a
`speaker`-type registration
## Policies by table
| Table | SELECT | INSERT | UPDATE | DELETE |
|---|---|---|---|---|
| `profiles` | own **or** admin | — | admin only | admin only |
| `contacts` | own **or** admin | — | admin only | admin only |
| `events` | all authenticated | admin only | admin only | admin only |
| `registrations` | own **or** admin | admin only | admin only | admin only |
| `sponsors` | admin **or** `paid` | admin only | admin only | admin only |
| `slots` | all authenticated | admin only | admin only | admin only |
| `sessions` | all authenticated | admin only | admin only | admin only |
| `preferences` | own **or** admin | — | — | — |
| `session_speakers` | all authenticated | admin only | admin only | admin only |
| `preferences` | own | — | — | — |
| `connections` | rows you're in **or** admin | — | — | — |
| `checkins` | own **or** staff/admin | — | — | — |
| `checkins` | own **or** admin | — | — | — |
| `feedback` | own **or** admin | — | — | — |
| `leaderboard` | all authenticated | — | — | — |
| `points_log` | own **or** admin | — | — | — |
> **Phase 2 addition** ([`20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql)):
> admin-only `select` policies were added to `preferences`, `connections`, and
> `feedback` so the Admin console can read the full activity. The per-user
> policies above are unchanged — these are additive `OR is_admin()` reads.
**"—" (no policy)** means normal users have **no direct write access** — those
tables are written only by the `security definer` RPCs, which bypass RLS. This is
deliberate: a client cannot `UPDATE profiles SET points = 9999` or insert its own
check-in. See [rpcs.md](./rpcs.md).
deliberate: a client cannot `UPDATE registrations SET points = 9999` or insert its
own check-in. See [rpcs.md](./rpcs.md).
> **Admin reads the full activity.** The `connections`, `checkins`, and `feedback`
> select policies include `or public.is_admin()`, so the APPE Admin console's
> Activity view sees every row (an admin is "involved" in none of them, so a
> pure "involved/own" policy would show 0).
### The exact policies
```sql
-- profiles: read own or admin; write admin only
create policy "profiles_select_own_or_admin" on public.profiles for select to authenticated
using (id = auth.uid() or public.is_admin());
create policy "profiles_update_admin" on public.profiles for update to authenticated
-- contacts: read own or admin; write admin only
create policy "contacts_select_own_or_admin" on public.contacts for select to authenticated
using (email = public.current_email() or public.is_admin());
create policy "contacts_admin_update" on public.contacts for update to authenticated
using (public.is_admin()) with check (public.is_admin());
create policy "profiles_delete_admin" on public.profiles for delete to authenticated
create policy "contacts_admin_delete" on public.contacts for delete to authenticated
using (public.is_admin());
-- slots / sessions: readable by any authenticated user (public agenda); admin writes
-- events: readable by all authenticated; writable by admin
create policy "events_select_all" on public.events for select to authenticated using (true);
create policy "events_admin_insert" on public.events for insert to authenticated with check (public.is_admin());
create policy "events_admin_update" on public.events for update to authenticated
using (public.is_admin()) with check (public.is_admin());
create policy "events_admin_delete" on public.events for delete to authenticated using (public.is_admin());
-- registrations: own or admin
create policy "registrations_select_own_or_admin" on public.registrations for select to authenticated
using (contact_email = public.current_email() or public.is_admin());
-- (admin-only insert/update/delete)
-- sponsors: admin sees all; non-admin sees only paid sponsors
create policy "sponsors_select" on public.sponsors for select to authenticated
using (public.is_admin() or paid);
-- (admin-only insert/update/delete)
-- slots / sessions / session_speakers: readable by any authenticated user; admin writes
create policy "slots_select_all" on public.slots for select to authenticated using (true);
create policy "slots_admin_insert" on public.slots for insert to authenticated with check (public.is_admin());
create policy "slots_admin_update" on public.slots for update to authenticated using (public.is_admin()) with check (public.is_admin());
create policy "slots_admin_delete" on public.slots for delete to authenticated using (public.is_admin());
-- (sessions: identical four policies)
create policy "sessions_select_all" on public.sessions for select to authenticated using (true);
create policy "session_speakers_select_all" on public.session_speakers for select to authenticated using (true);
-- (each has admin-only insert/update/delete)
-- preferences: read own
create policy "prefs_select_own" on public.preferences for select to authenticated
using (profile_id = auth.uid());
using (contact_email = public.current_email());
-- connections: read rows you're involved in
create policy "conn_select_involved" on public.connections for select to authenticated
using (from_id = auth.uid() or to_id = auth.uid());
-- connections: read rows you're part of (or all if admin)
create policy "conn_select_involved_or_admin" on public.connections for select to authenticated
using (from_email = public.current_email() or to_email = public.current_email() or public.is_admin());
-- checkins: read own or staff/admin
create policy "checkins_select_own_or_staff" on public.checkins for select to authenticated
using (profile_id = auth.uid() or public.is_staff_or_admin());
-- checkins: read own, or all if admin
create policy "checkins_select_own_or_admin" on public.checkins for select to authenticated
using (contact_email = public.current_email() or public.is_admin());
-- feedback: read own
create policy "feedback_select_own" on public.feedback for select to authenticated
using (profile_id = auth.uid());
-- feedback: read own, or all if admin
create policy "feedback_select_own_or_admin" on public.feedback for select to authenticated
using (contact_email = public.current_email() or public.is_admin());
-- leaderboard: readable by any authenticated user
-- leaderboard: public to all authenticated (Realtime source)
create policy "leaderboard_select_all" on public.leaderboard for select to authenticated using (true);
-- points_log: read own or admin
create policy "points_log_select_own_or_admin" on public.points_log for select to authenticated
using (profile_id = auth.uid() or public.is_admin());
-- Phase 2 (20260823000000_admin_app.sql): additive admin-only reads for the
-- Admin console. These OR with the per-user policies above.
create policy "prefs_select_admin" on public.preferences for select to authenticated using (public.is_admin());
create policy "conn_select_admin" on public.connections for select to authenticated using (public.is_admin());
create policy "feedback_select_admin" on public.feedback for select to authenticated using (public.is_admin());
using (contact_email = public.current_email() or public.is_admin());
```
## Storage — `materials` bucket
The `materials` bucket (public read) stores session material. Policies on
`storage.objects`:
```sql
create policy "materials_read" on storage.objects for select to authenticated
using (bucket_id = 'materials');
create policy "materials_write" on storage.objects for insert to authenticated
with check (bucket_id = 'materials' and public.is_speaker_or_admin());
create policy "materials_update" on storage.objects for update to authenticated
using (bucket_id = 'materials' and public.is_speaker_or_admin());
create policy "materials_delete" on storage.objects for delete to authenticated
using (bucket_id = 'materials' and public.is_speaker_or_admin());
```
Speakers + admins can write; any authenticated attendee can read (download).
Because the `sessions` table is admin-write only, a speaker attaches their
uploaded file via the `set_session_material` RPC (see
[rpcs.md](./rpcs.md#set_session_materialp_session_id-p_material_path--sessions)).
## GRANTs
The new Supabase CLI does **not** auto-expose new tables to the Data API roles, so
the migration grants explicitly (RLS still governs what each role can actually see):
the migration grants explicitly (RLS still governs what each role can actually
see):
```sql
grant usage on schema public to anon, authenticated, service_role;
grant select on <all 9 tables> to anon, authenticated, service_role;
grant insert, update, delete on <all 9 tables> to authenticated, service_role;
grant select on <all 13 tables> to anon, authenticated, service_role;
grant insert, update, delete on <all 13 tables> to authenticated, service_role;
grant execute on function <all public RPCs + helpers> to authenticated;
```
@@ -119,20 +160,21 @@ full DML at the Postgres level, but **RLS narrows it** to the policies above.
## Net effect by role
- **Attendee** — sees their own profile/prefs/connections/feedback, the full
agenda, and the leaderboard; can only act through the RPCs (which re-check role
internally, e.g. only staff can call `checkin_attendee`).
- **Staff** — everything an attendee can do, plus can read all `checkins` and call
the check-in RPC.
- **Admin** — full read on everything (including all `preferences`,
`connections`, and `feedback`), and the only role with **direct** write access
to `profiles` / `slots` / `sessions`. This is exactly what the Admin console
(Phase 2, [`../frontend/admin-app.md`](../frontend/admin-app.md)) uses.
- **Attendee** — sees their own contact/registration/prefs/connections/feedback,
the full agenda, the public contact directory, and the leaderboard; can only act
through the RPCs (which re-check role internally, e.g. only staff can call
`checkin_attendee`).
- **Staff (= admin)** — everything an attendee can do, plus can read all
`checkins` / `connections` / `feedback` and call the check-in RPC.
- **Admin** — full read on everything, and the only role with **direct** write
access to `contacts` / `events` / `registrations` / `sponsors` / `slots` /
`sessions` / `session_speakers`. This is exactly what the APPE Admin console
([../frontend/admin-app.md](../frontend/admin-app.md)) uses.
## Things to revisit later
- `slots` / `sessions` are readable by *any* authenticated user (fine — it's a
public agenda). If you ever want the agenda hidden until the event, that's a
one-line policy change.
- `slots` / `sessions` / `session_speakers` are readable by *any* authenticated
user (fine — it's a public agenda). If you ever want the agenda hidden until the
event, that's a one-line policy change.
- `leaderboard` exposes every attendee's name + points to any authenticated user.
That's the intended product behavior (a public leaderboard).
+82 -44
View File
@@ -1,12 +1,13 @@
# Points RPCs (Business Logic)
All mutations go through **Postgres RPCs** (`security definer`, transactional).
The app never writes to `profiles.points`, `connections`, `checkins`, `feedback`,
or `leaderboard` directly — it calls these functions. This is what makes the
points system race-free and prevents a client from, e.g., setting its own points.
The app never writes to `registrations.points`, `connections`, `checkins`,
`feedback`, or `leaderboard` directly — it calls these functions. This is what
makes the points system race-free and prevents a client from, e.g., setting its
own points.
Source of truth:
[`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql).
[`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql).
## Why RPCs?
@@ -17,6 +18,8 @@ Source of truth:
re-sync the leaderboard* in **one transaction**. Either all happen or none do.
- **Idempotent where it matters** → re-check-in and re-feedback are detected and
never double-award.
- **Event-scoped** → every RPC resolves the **active event** first and scopes all
reads/writes to it.
## Points rules
@@ -30,27 +33,37 @@ Source of truth:
## Internal helpers
### `_award_points(p_profile_id, p_delta, p_category)`
### `_award_points(p_event_id, p_contact_email, p_delta, p_category)`
The single place points change. In one transaction it:
1. `update profiles set points = greatest(0, points + p_delta)` (floored at 0),
2. `insert into points_log (profile_id, delta, category)`,
3. calls `_sync_leaderboard(p_profile_id)`.
1. `update registrations set points = greatest(0, points + p_delta)` (floored at
0) for the (event, contact),
2. `insert into points_log (event_id, contact_email, delta, category)`,
3. calls `_sync_leaderboard(p_event_id, p_contact_email)`.
### `_sync_leaderboard(p_profile_id)`
Upserts the `leaderboard` row for that profile from `profiles`
(`on conflict (profile_id) do update ...`). This is what makes the leaderboard a
consistent, Realtime-friendly mirror.
### `_sync_leaderboard(p_event_id, p_contact_email)`
Upserts the `leaderboard` row for that (event, contact) from `registrations` +
`contacts` (`on conflict (event_id, contact_email) do update ...`). This is what
makes the leaderboard a consistent, Realtime-friendly mirror.
### `_recalc_event_aggregates(p_event_id)`
Recomputes the `events` aggregate columns (`num_sessions`, `num_speakers`,
`num_registrations`, `num_checked_in_registrations`, `avg_feedback`). Called by
triggers and the feedback RPC.
## Public read functions
| Function | Returns | Used for |
|---|---|---|
| `get_public_profiles()` | `id, full_name, company, role, points` (ordered by points) | Leaderboard initial load, id→name lookups |
| `lanyard_lookup(p_qr_token)` | `id, full_name, company, role` | Resolve a scanned QR (pre-login + connect) |
| `get_agenda()` | slots with their sessions (flat rows) | Agenda + Home |
| `get_leaderboard()` | `event_id, contact_email, full_name, points` (active event, ordered by points) | Leaderboard initial load + realtime re-fetch |
| `lanyard_lookup(p_qr_token)` | `email, full_name, linkedin_url` (null unless `show_linkedin`), `show_email`, `registration_type` | Resolve a scanned QR (pre-login + connect) |
| `get_public_contacts()` | `email, full_name, linkedin_url`, `show_email`, `registration_type` (active-event registrants) | Connections name/type lookups |
| `get_agenda()` | flat rows: slot fields + session fields + `speakers` (string_agg) | Agenda + Home |
| `get_active_event()` | the active `events` row (or none) | event name/dates/location |
All three are `security definer` and expose **only public columns** (no email, no
`qr_token`).
All are `security definer` and expose **only public columns** (email is included
because `contacts` is keyed by email and is the identity; `qr_token` is never
exposed). `lanyard_lookup` / `get_public_contacts` respect the contact's
`show_email` / `show_linkedin` visibility toggles.
## Mutation RPCs
@@ -63,28 +76,29 @@ Enforces "one pick per slot".
Removes the caller's pick for a slot.
### `create_connection_request(p_target_qr)` → `connections`
Creates a **pending** connection to the attendee whose QR was scanned.
Creates a **pending** connection to the contact whose QR was scanned.
- Resolves the target by `qr_token`; errors if not found or if it's yourself.
- **Idempotent:** if the pair already has a connection (either direction), returns
the existing one instead of creating a duplicate.
- **Idempotent:** if the pair already has a connection (either direction) for the
active event, returns the existing one instead of creating a duplicate.
### `accept_connection(p_connection_id)` → `connections`
Accepts an **incoming** request.
- Locks the row (`for update`), verifies the caller is the recipient
(`to_id = auth.uid()`) and the status is still `pending`.
(`to_email = current_email()`) and the status is still `pending`.
- Sets `status = 'accepted'`, `resolved_at = now()`.
- **Awards +5 to both** `from_id` and `to_id` (category `connection`).
- **Awards +5 to both** `from_email` and `to_email` (category `connection`).
### `reject_connection(p_connection_id)` → `connections`
Same guards as accept, but sets `status = 'rejected'`. No points.
### `checkin_attendee(p_session_id, p_attendee_qr)` → `(checkin_id, attendee_id, attendee_name, points, already)`
### `checkin_attendee(p_session_id, p_attendee_qr)` → `(checkin_id, attendee_email, attendee_name, points, already)`
Staff checks an attendee into a session.
- **Role check:** `is_staff_or_admin()` or it raises `staff or admin only`.
- **Role check:** `is_staff_or_admin()` (i.e. `is_admin()`) or it raises
`staff or admin only`.
- Resolves the attendee by `qr_token`.
- `insert into checkins ... on conflict (profile_id, session_id) do nothing
returning id` — if no row was inserted, the attendee was **already checked in**:
sets `already = true` and awards **no points**.
- `insert into checkins ... on conflict (event_id, contact_email, session_id) do
nothing returning id` — if no row was inserted, the attendee was **already
checked in**: sets `already = true` and awards **no points**.
- Otherwise awards **+10** to the attendee (category `checkin`).
- Returns the attendee's current total points.
@@ -102,20 +116,22 @@ Post-session feedback.
- **Idempotent:** if feedback already exists for (caller, session), it **updates**
the rating/comment and awards **0** (already rewarded on first submission).
- Otherwise inserts and awards `earned` (category `feedback`).
- Recalculates `sessions.average_feedback`, updates the `ai_generated_feedback`
state machine, and recalcs the event aggregates.
### `adjust_points(p_profile_id, p_delta, p_reason)` → `void`
**Admin-only** manual points adjustment (category `admin`). Used by the Admin
console (Phase 2) to award prizes or correct mistakes. Goes through
### `adjust_points(p_contact_email, p_delta, p_reason)` → `void`
**Admin-only** manual points adjustment (category `admin`) for the active event.
Used by the APPE Admin console to award prizes or correct mistakes. Goes through
`_award_points`, so it floors at 0, writes `points_log`, and re-syncs the
leaderboard.
### `reset_qr_token(p_profile_id)` → `(profile_id, qr_token)`
**Admin-only.** Regenerates an attendee's lanyard QR token.
- Generates a fresh `CVV-XXX-NNNN` token and writes it to `profiles.qr_token`.
- **Re-hashes it as the Auth password** (`extensions.crypt(token, extensions.gen_salt('bf'))`
on `auth.users.encrypted_password`), so the **old token stops working** and the
attendee must re-scan with the new one.
- **Deletes the attendee's existing `auth.sessions`**, forcing a re-login.
### `reset_qr_token(p_contact_email)` → `(email, qr_token)`
**Admin-only.** Regenerates a contact's lanyard QR token.
- Generates a fresh `CVV-XXX-NNNN` token and writes it to `contacts.qr_token`.
- **Re-hashes it as the Auth password** (`extensions.crypt(token,
extensions.gen_salt('bf'))` on `auth.users.encrypted_password`), so the **old
token stops working** and the contact must re-scan with the new one.
- **Deletes the contact's existing `auth.sessions`**, forcing a re-login.
- Returns the new token so the admin can print/show it as a QR code.
> **Implementation note:** pgcrypto's `gen_salt` / `crypt` live in the
@@ -124,22 +140,44 @@ leaderboard.
> `extensions.crypt(...)`. The function owner (`postgres`) can write
> `auth.users` and `auth.sessions`, which is what makes this possible.
Source of truth for this RPC:
[`supabase/migrations/20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql).
### `upsert_contact(p_email, p_full_name, p_linkedin_url, p_is_admin, p_qr_token)` → `contacts`
**Admin-only.** Creates a contact if it doesn't exist (generating a QR token when
none is given) or updates the existing one. Returns the contact row.
### `create_registration(p_contact_email, p_type)` → `registrations`
**Admin-only.** Creates a registration for the active event (enforces the
sponsor-type rule).
### `set_registration_type(p_contact_email, p_type)` → `registrations`
**Admin-only.** Changes a contact's registration type for the active event.
### `evaluate_session_feedback(p_session_id)` → `sessions`
**Admin-only.** The **AI-feedback stub**: sets `ai_generated_feedback` to a
placeholder string ("AI evaluation stub: N comment(s) received. (LLM integration
pending.)"). Real LLM integration is a later phase.
### `set_session_material(p_session_id, p_material_path)` → `sessions`
Sets a session's `material_path`. Allowed for **admins and for any speaker of the
session** (the `sessions` table is admin-write only, so speakers need this
security-definer RPC to attach their uploaded material). The attendee app calls
this after uploading a file to the `materials` bucket.
## Role helper functions
| Function | Returns | Meaning |
|---|---|---|
| `is_admin()` | `boolean` | current user's profile has `role = 'admin'` |
| `is_staff_or_admin()` | `boolean` | current user's profile has `role in ('staff','admin')` |
| `current_email()` | `text` | `auth.jwt() ->> 'email'` (the identity) |
| `is_admin()` | `boolean` | current contact has `is_admin = true` |
| `is_staff_or_admin()` | `boolean` | = `is_admin()` (staff is merged into admin) |
| `is_speaker_or_admin()` | `boolean` | admin, **or** a speaker of a session in the active event (via `session_speakers`), **or** a contact whose registration type is `speaker` |
Both are `security definer` so they can read `profiles` inside RLS checks and RPC
guards.
All are `security definer` so they can read `contacts` / `registrations` /
`session_speakers` inside RLS checks and RPC guards.
## Error handling
RPCs raise Postgres exceptions with human-readable messages (e.g. `you cannot
connect with yourself`, `staff or admin only`, `you must be checked in to this
session to give feedback`). The frontend surfaces these via toasts — see
session to give feedback`, `not a speaker of this session`). The frontend
surfaces these via toasts — see
[../frontend/api-client.md](../frontend/api-client.md).
+164 -50
View File
@@ -1,152 +1,266 @@
# Database Schema
All tables live in the `public` schema. Source of truth:
[`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql).
[`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql)
(the Redesign migration, which **replaces** the old `profiles`-based schema).
There are **9 tables**: people, schedule, and the event's activity.
There are **13 tables**: people (`contacts`), the event (`events`), participation
(`registrations`, `sponsors`), the schedule (`slots`, `sessions`,
`session_speakers`), and the event's activity (`preferences`, `connections`,
`checkins`, `feedback`, `leaderboard`, `points_log`).
The old `profiles` table is **dropped**. People are now `contacts` (keyed by
email), and every activity table is scoped to an **event** + a **contact email**
instead of a single `profile_id`.
```mermaid
erDiagram
profiles ||--o{ preferences : "picks"
profiles ||--o{ connections : "from/to"
profiles ||--o{ checkins : "checked in"
profiles ||--o{ feedback : "rates"
profiles ||--o{ leaderboard : "mirrored"
profiles ||--o{ points_log : "audited"
contacts ||--o{ registrations : "participates"
contacts ||--o{ session_speakers : "speaks"
contacts ||--o{ preferences : "picks"
contacts ||--o{ connections : "from/to"
contacts ||--o{ checkins : "checked in"
contacts ||--o{ feedback : "rates"
contacts ||--o{ leaderboard : "mirrored"
contacts ||--o{ points_log : "audited"
events ||--o{ registrations : "has"
events ||--o{ sponsors : "has"
events ||--o{ slots : "has"
events ||--o{ sessions : "has"
events ||--o{ preferences : "scopes"
events ||--o{ connections : "scopes"
events ||--o{ checkins : "scopes"
events ||--o{ feedback : "scopes"
events ||--o{ leaderboard : "scopes"
events ||--o{ points_log : "scopes"
slots ||--o{ sessions : "contains"
sessions ||--o{ session_speakers : "has speakers"
sessions ||--o{ preferences : "picked"
sessions ||--o{ checkins : "checked into"
sessions ||--o{ feedback : "rated"
```
## `profiles` — people (source of truth)
## `contacts` — people (source of truth)
One row per attendee. `id` **is** the Supabase Auth user id.
One row per person. **`email` is the primary key** (a natural key that matches
`auth.users.email`). The `qr_token` doubles as the Supabase Auth password.
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | = `auth.users(id)`; `on delete cascade` |
| `email` | `text` **unique** | The ticket-purchase email (login identifier) |
| `email` | `text` **PK** | The ticket-purchase email (login identifier) |
| `full_name` | `text` | |
| `company` | `text` | nullable |
| `role` | `text` | `attendee` \| `staff` \| `admin` (default `attendee`) |
| `linkedin_url` | `text` | nullable |
| `show_email` | `boolean` | default `false` — visibility toggle |
| `show_linkedin` | `boolean` | default `false` — visibility toggle |
| `is_admin` | `boolean` | default `false` — **staff = admin (merged)**; grants check-in + APPE Admin access |
| `qr_token` | `text` **unique** | The lanyard token; **doubles as the Auth password** |
| `created_at` | `timestamptz` | |
Index: `contacts_qr_token_idx (qr_token)` — fast lanyard lookups.
## `events` — a conference
At most **one active event** at a time (partial unique index + trigger). The app
queries everything for the active event and handles "no active event" gracefully.
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | `gen_random_uuid()` |
| `name` | `text` | e.g. "APPE 2026" |
| `start_date` / `end_date` | `date` | |
| `location` | `text` | nullable |
| `is_active` | `boolean` | default `false` |
| `avg_feedback` | `numeric` | maintained aggregate |
| `num_sessions` | `integer` | maintained aggregate |
| `num_speakers` | `integer` | maintained aggregate |
| `num_registrations` | `integer` | maintained aggregate |
| `num_checked_in_registrations` | `integer` | maintained aggregate |
| `created_at` | `timestamptz` | |
**Constraint:** `unique index events_one_active on (is_active) where is_active`
— at most one active event. The aggregate columns are kept in sync by triggers
(counts) and the `submit_feedback` RPC (`avg_feedback`).
## `registrations` — a contact's participation in an event
Points are scoped **per event** here (one row per contact per event).
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `contact_email` | `text` FK → `contacts` | `on delete cascade` |
| `type` | `text` | `attendee` \| `speaker` \| `staff` \| `sponsor` (default `attendee`) |
| `checked_in` | `boolean` | default `false` |
| `points` | `integer` | `>= 0`, default 0 |
| `created_at` | `timestamptz` | |
**Constraint:** `unique (event_id, contact_email)` — one registration per contact
per event.
## `sponsors` — a sponsor for an event
Unpaid sponsors are hidden from non-admins (RLS).
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `type` | `text` | `headline` \| `platinum` \| `gold` \| `silver` \| `community` \| `swag` \| `catering` \| `diversity` |
| `name` | `text` | |
| `email` | `text` | nullable |
| `phone` | `text` | nullable |
| `paid` | `boolean` | default `false` — unpaid hidden from non-admins |
| `amount_eur` | `numeric` | nullable |
| `contact_email` | `text` FK → `contacts` | nullable lookup, `on delete set null` |
| `created_at` | `timestamptz` | |
## `slots` — schedule blocks
| Column | Type | Notes |
|---|---|---|
| `id` | `integer` PK | 1–6 |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `type` | `text` | `session` \| `lunch_break` \| `coffee_break` \| `keynote` \| `close_up` (default `session`) |
| `name` | `text` | e.g. "Slot 1" |
| `slot_date` | `date` | `2026-10-23` |
| `start_time` | `time` | |
| `end_time` | `time` | |
| `start_time` / `end_time` | `time` | |
## `sessions` — one per (slot, room)
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | `gen_random_uuid()` |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `slot_id` | `integer` FK → `slots` | `on delete cascade` |
| `title` | `text` | |
| `description` | `text` | nullable |
| `slot_id` | `integer` FK → `slots` | `on delete cascade` |
| `room` | `text` | "Main Stage" / "Room A" / "Room B" |
| `capacity` | `integer` | nullable (not enforced in v1) |
| `speakers` | `text` | |
| `capacity` | `integer` | nullable (not enforced) |
| `average_feedback` | `numeric` | maintained by `submit_feedback` |
| `ai_generated_feedback` | `text` | AI-feedback state (stub) |
| `material_path` | `text` | nullable — storage object path for session material |
| `created_at` | `timestamptz` | |
Index: `sessions_slot_id_idx (slot_id)`.
> **Speakers are no longer a `text` column** — they live in the `session_speakers`
> join table below (1:N). The `get_agenda()` RPC aggregates them into a
> comma-separated `speakers` string for display.
Indexes: `sessions_event_id_idx (event_id)`, `sessions_slot_id_idx (slot_id)`.
## `session_speakers` — M:N between sessions and contacts
A session must have **≥ 1 speaker** (enforced by a trigger).
| Column | Type | Notes |
|---|---|---|
| `session_id` | `uuid` FK → `sessions` | `on delete cascade` |
| `contact_email` | `text` FK → `contacts` | `on delete cascade` |
**PK:** `(session_id, contact_email)`.
## `preferences` — one pick per slot
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | |
| `profile_id` | `uuid` FK → `profiles` | |
| `session_id` | `uuid` FK → `sessions` | |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `contact_email` | `text` FK → `contacts` | `on delete cascade` |
| `session_id` | `uuid` FK → `sessions` | `on delete cascade` |
| `slot_id` | `integer` | denormalized for easy "one per slot" |
| `created_at` | `timestamptz` | |
**Constraint:** `unique (profile_id, slot_id)` — an attendee can pick at most one
session per slot. Enforced in the DB *and* by the `set_preference` RPC (which
deletes the old pick for the slot before inserting).
**Constraint:** `unique (event_id, contact_email, slot_id)` — one pick per slot.
Enforced in the DB *and* by the `set_preference` RPC (which deletes the old pick
for the slot before inserting).
## `connections` — the networking relationship
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | |
| `from_id` | `uuid` FK → `profiles` | the requester |
| `to_id` | `uuid` FK → `profiles` | the recipient |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `from_email` | `text` FK → `contacts` | the requester |
| `to_email` | `text` FK → `contacts` | the recipient |
| `status` | `text` | `pending` \| `accepted` \| `rejected` (default `pending`) |
| `created_at` | `timestamptz` | |
| `resolved_at` | `timestamptz` | set when accepted/rejected |
**Constraint:** unique per **unordered pair** via
`unique index connections_pair_uniq on (least(from_id, to_id), greatest(from_id, to_id))`.
So Ana→Bruno and Bruno→Ana are the *same* connection — a pair can only ever have
one.
**Constraint:** unique per **unordered pair per event** via
`unique index connections_pair_uniq on (event_id, least(from_email, to_email),
greatest(from_email, to_email))`. So Ana→Bruno and Bruno→Ana are the *same*
connection.
## `checkins` — staff check-in of an attendee
## `checkins` — staff check-in of a contact
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | |
| `profile_id` | `uuid` FK → `profiles` | the attendee being checked in |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `contact_email` | `text` FK → `contacts` | the attendee being checked in |
| `session_id` | `uuid` FK → `sessions` | |
| `staff_id` | `uuid` FK → `profiles` | the staff member who scanned |
| `staff_email` | `text` FK → `contacts` | the staff member who scanned |
| `created_at` | `timestamptz` | |
**Constraint:** `unique (profile_id, session_id)` — one check-in per attendee per
session (prevents double points).
**Constraint:** `unique (event_id, contact_email, session_id)` — one check-in per
contact per session (prevents double points).
## `feedback` — post-session rating
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | |
| `profile_id` | `uuid` FK → `profiles` | |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `contact_email` | `text` FK → `contacts` | |
| `session_id` | `uuid` FK → `sessions` | |
| `rating` | `integer` | `1–5` |
| `comment` | `text` | nullable (bonus points if present) |
| `created_at` | `timestamptz` | |
**Constraint:** `unique (profile_id, session_id)` — one feedback per attendee per
session.
**Constraint:** `unique (event_id, contact_email, session_id)` — one feedback per
contact per session.
## `leaderboard` — Realtime mirror
A public, Realtime-friendly mirror of points. **Not** the source of truth — it is
kept in sync transactionally by the RPCs (see [rpcs.md](./rpcs.md#_sync_leaderboard)).
A public, Realtime-friendly mirror of points **per event**. **Not** the source of
truth — it is kept in sync transactionally by the RPCs (see
[rpcs.md](./rpcs.md#_sync_leaderboard)).
| Column | Type | Notes |
|---|---|---|
| `profile_id` | `uuid` PK FK → `profiles` | |
| `event_id` | `uuid` PK FK → `events` | |
| `contact_email` | `text` PK FK → `contacts` | |
| `full_name` | `text` | denormalized for display |
| `company` | `text` | denormalized |
| `points` | `integer` | |
| `updated_at` | `timestamptz` | |
The app subscribes to `postgres_changes` on this table to update the leaderboard
live. See [../frontend/screens.md#leaderboard](../frontend/screens.md#leaderboard).
**PK:** `(event_id, contact_email)`. The app subscribes to `postgres_changes` on
this table to update the leaderboard live. See
[../frontend/screens.md#leaderboard](../frontend/screens.md#leaderboard).
## `points_log` — audit trail
Powers the per-category points breakdown on the Profile screen.
Powers the per-category points breakdown on the Profile screen (per event).
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | |
| `profile_id` | `uuid` FK → `profiles` | |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `contact_email` | `text` FK → `contacts` | |
| `delta` | `integer` | points added (can be negative for admin adjustments) |
| `category` | `text` | `checkin` \| `connection` \| `feedback` \| `admin` |
| `created_at` | `timestamptz` | |
Index: `points_log_profile_id_idx (profile_id)`.
Index: `points_log_event_id_idx (event_id)`.
## Other indexes
- `profiles_qr_token_idx (qr_token)` — fast lanyard lookups.
- `checkins_session_id_idx (session_id)`.
- `slots_event_id_idx (event_id)`, `registrations_event_id_idx (event_id)`,
`checkins_session_id_idx (session_id)`.
## Storage
A **`materials`** bucket (public read) stores session material. Speakers + admins
can write (see [rls.md](./rls.md#storage--materials-bucket)). A session's
`material_path` points at the object; the public URL is
`/storage/v1/object/public/materials/{material_path}`.
+47 -29
View File
@@ -7,12 +7,16 @@ Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs o
| Data | Count | Notes |
|---|---|---|
| `auth.users` + `auth.identities` | 13 | 12 attendees + 1 admin; **QR token = bcrypt password** |
| `contacts` | 14 | 13 with QR tokens + 1 external keynote speaker (no token) |
| `events` | 1 | **APPE 2026**, 2026-10-23, São Paulo, Brazil, **active** |
| `registrations` | 13 | one per contact (Elena has none); points scoped here |
| `sponsors` | 3 | Nubank (headline, paid), Acme Corp (gold, paid), Globant (community, unpaid) |
| `slots` | 6 | 23 Oct, 09:00–15:45 (see table below) |
| `sessions` | 18 | 3 per slot (Main Stage / Room A / Room B) |
| `auth.users` + `auth.identities` | 13 | 12 attendees + 1 admin; **QR token = bcrypt password** |
| `profiles` | 13 | one per user, with role + starting points |
| `leaderboard` | 13 | mirrored from `profiles` |
| `points_log` | 21 | Ana's coherent breakdown + one `admin` entry per other user |
| `session_speakers` | 22 | M:N session → contact |
| `leaderboard` | 13 | mirrored from `registrations` |
| `points_log` | 16 | Ana's coherent breakdown + one `admin` entry per other user |
| Ana's demo state | — | 6 preferences, 2 check-ins, 4 connections, 1 feedback |
> **GoTrue gotcha:** manually-inserted `auth.users` must have
@@ -21,40 +25,49 @@ Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs o
> grant can't scan a NULL `confirmation_token`. `phone` is left NULL (unique
> constraint).
> **Staff = admin (merged).** Bruno, Rita, and the APPE Admin have
> `is_admin = true` on their `contacts` row. Their registration `type` is
> `staff` (the ticket type shown on the lanyard).
## Slots
| id | Time |
|---|---|
| 1 | 09:00–09:45 |
| 2 | 10:00–10:45 |
| 3 | 11:30–12:15 |
| 4 | 13:15–14:00 |
| 5 | 14:00–14:45 |
| 6 | 15:00–15:45 |
| id | Type | Time |
|---|---|---|
| 1 | keynote | 09:00–09:45 |
| 2 | session | 10:00–10:45 |
| 3 | session | 11:30–12:15 |
| 4 | lunch_break | 13:15–14:00 |
| 5 | session | 14:00–14:45 |
| 6 | close_up | 15:00–15:45 |
## Demo accounts
Login = **QR code** (typed or scanned) + **email**. The QR token is the password.
| Person | Role | QR code | Email | Company | Start pts |
|---|---|---|---|---|---|
| **Ana Silva** | attendee | `CVV-ANA-4821` | ana.silva@nubank.com | Nubank | 40 |
| **Bruno Costa** | staff | `CVV-BRU-1177` | bruno.costa@acme.com | Acme Corp | 140 |
| **Rita Lopes** | staff | `CVV-RIT-9034` | rita.lopes@globant.com | Globant | 95 |
| **Convivo Admin** | admin | `CVV-ADM-0001` | admin@appe.at | Convivo | 0 |
| Tomás Ribeiro | attendee | `CVV-TOM-5566` | tomas.ribeiro@dataprev.com | Dataprev | 88 |
| Sofia Almeida | attendee | `CVV-SOF-2299` | sofia.almeida@loop.com | Loop | 76 |
| Marco Chen | attendee | `CVV-MRC-7712` | marco.chen@deepmind.com | DeepMind | 70 |
| Julia Santos | attendee | `CVV-JUL-3345` | julia.santos@ifood.com | iFood | 64 |
| Pedro Nunes | attendee | `CVV-PED-8801` | pedro.nunes@microsoft.com | Microsoft | 58 |
| Carla Mendes | attendee | `CVV-CAR-6623` | carla.mendes@quintoessencial.com | QuintoEssencial | 52 |
| Diego Ferreira | attendee | `CVV-DIE-4458` | diego.ferreira@stone.com | Stone | 35 |
| Marina Costa | attendee | `CVV-MNA-2210` | marina.costa@olx.com | OLX | 28 |
| Lucas Oliveira | attendee | `CVV-LUC-9987` | lucas.oliveira@usp.br | USP | 15 |
| Person | Type | QR code | Email | Start pts |
|---|---|---|---|---|
| **Ana Silva** | attendee | `CVV-ANA-4821` | ana.silva@nubank.com | 40 |
| **Bruno Costa** | staff (admin) | `CVV-BRU-1177` | bruno.costa@acme.com | 140 |
| **Rita Lopes** | staff (admin) | `CVV-RIT-9034` | rita.lopes@globant.com | 95 |
| **APPE Admin** | staff (admin) | `CVV-ADM-0001` | admin@appe.at | 0 |
| Tomás Ribeiro | attendee | `CVV-TOM-5566` | tomas.ribeiro@dataprev.com | 88 |
| Sofia Almeida | attendee | `CVV-SOF-2299` | sofia.almeida@loop.com | 76 |
| Marco Chen | attendee | `CVV-MRC-7712` | marco.chen@deepmind.com | 70 |
| Julia Santos | attendee | `CVV-JUL-3345` | julia.santos@ifood.com | 64 |
| Pedro Nunes | attendee | `CVV-PED-8801` | pedro.nunes@microsoft.com | 58 |
| Carla Mendes | attendee | `CVV-CAR-6623` | carla.mendes@quintoessencial.com | 52 |
| Diego Ferreira | attendee | `CVV-DIE-4458` | diego.ferreira@stone.com | 35 |
| Marina Costa | attendee | `CVV-MNA-2210` | marina.costa@olx.com | 28 |
| Lucas Oliveira | attendee | `CVV-LUC-9987` | lucas.oliveira@usp.br | 15 |
| Dr. Elena Vasquez | (external speaker) | — | elena.vasquez@keynote.com | — |
> **Dr. Elena Vasquez** is an external keynote speaker: she has a `contacts` row
> (and speaks in `session_speakers`) but **no QR token and no auth user**, so she
> can't log in — she only appears as a speaker on the agenda.
## Ana's demo state (so the app looks alive on first login)
Ana (id `11111111-…`) is seeded with a coherent 40-point history:
Ana (`[email protected]`) is seeded with a coherent 40-point history:
- **Points breakdown** (`points_log`): 2× check-in (+10 each), 2× connection
(+5 each), 1× feedback (+10) = **40**.
@@ -70,7 +83,10 @@ Ana (id `11111111-…`) is seeded with a coherent 40-point history:
- accepted with **Bruno** and **Rita**
- incoming (pending) from **Sofia**
- outgoing (pending) to **Julia**
- **Feedback** — rated Slot 1's *Designing for Trust in AI Products* 5★ with a comment.
- **Feedback** — rated Slot 1's *Designing for Trust in AI Products* 5★ with a
comment.
- **Speaker** — Ana is a speaker of Slot 6's *Open Space: Your Ideas* (so the
Agenda shows a "🎤 you" tag and the material-upload notice).
> Everyone else gets a single `admin` `points_log` entry for their starting points
> (so the Profile breakdown shows "Other"), and no other activity.
@@ -82,3 +98,5 @@ Ana (id `11111111-…`) is seeded with a coherent 40-point history:
3. Log in as **Bruno** (staff) → the Scan tab becomes **Check-in** → pick a
session → scan **Carla** (`CVV-CAR-6623`) → she gets +10.
4. Watch the **Leaderboard** update live (Realtime).
5. Log in as **APPE Admin** (`CVV-ADM-0001` / `[email protected]`) in the admin app
→ Dashboard, Contacts, Registrations, Sponsors, Schedule, Activity, Events.
+8 -5
View File
@@ -14,7 +14,7 @@ the "main docker" of the project.
| `supabase_auth_Convivo` | `supabase/gotrue` | Auth (QR + email login) |
| `supabase_rest_Convivo` | `supabase/postgrest` | REST API over Postgres (tables + RPCs) |
| `supabase_realtime_Convivo` | `supabase/realtime` | WebSocket realtime (leaderboard) |
| `supabase_storage_Convivo` | `supabase/storage-api` | Storage (unused in v1) |
| `supabase_storage_Convivo` | `supabase/storage-api` | Storage — the `materials` bucket (session material) |
| `supabase_kong_Convivo` | `supabase/kong` | **API gateway** — fronts everything on one port |
| `supabase_studio_Convivo` | `supabase/studio` | Web UI (Studio) |
| `supabase_inbucket_Convivo` | `supabase/mailpit` | Captures emails (none sent in this flow) |
@@ -58,10 +58,12 @@ npm run db:stop # = supabase stop
npx supabase status
```
- `db:reset` drops and recreates the database, applies
[`migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql),
then runs [`seed.sql`](../../supabase/seed.sql). Use it any time you want a
clean demo state.
- `db:reset` drops and recreates the database, applies **all** migrations in
order (`20260822000000_init.sql` → `20260823000000_admin_app.sql` →
[`20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql),
the last of which replaces the old schema), then runs
[`seed.sql`](../../supabase/seed.sql). Use it any time you want a clean demo
state.
- Migrations and seed are **idempotent** (`on conflict ... do nothing`), so a
reset is safe to repeat.
@@ -74,6 +76,7 @@ npx supabase status
| `[db] port` | `54322` | Postgres port |
| `[studio] port` | `54323` | Studio port |
| `[auth.email] enable_confirmations` | `false` | **No email is sent** — the QR+email login never emails the user |
| `[auth] jwt_expiry` | `86400` | **24-hour login** — the session JWT lives a full day |
| `[auth] site_url` | `http://127.0.0.1:3000` | The app origin |
| `[db.seed] sql_paths` | `["./seed.sql"]` | Seed runs on reset |