Files
Convivo/docs/backend/schema.md
T
74c41c8c1d Phase 7+8: Pretix + Sessionize interfaces
- Migration 20260825000000_interfaces.sql: external_id on contacts/
  registrations/sessions (+ partial unique indexes), slots_id_seq, sync_runs
  audit table, and service-role-only sync_pretix_attendees /
  sync_sessionize_sessions RPCs (idempotent upserts).
- sync-trigger Edge Function: admin-JWT or CRON_SECRET auth, pulls from
  Pretix/Sessionize base URLs, normalizes, calls the service-role RPCs.
- interfaces/mock-api: dependency-free Node server (:54330) + fixtures so the
  full pipeline is testable without real tokens.
- APPE Admin 'Interfaces' view: per-source + 'Sync all' triggers, result
  counts, recent sync runs, and QR CSV export; /functions proxy added.
- Docs: new docs/backend/interfaces.md; updated README, roadmap, next-steps,
  schema, rls, rpcs, architecture, admin-app, and docs index.

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
2026-08-23 03:34:30 +02:00

11 KiB
Raw Blame History

Database Schema

All tables live in the public schema. Source of truth: supabase/migrations/20260824000000_redesign.sql (the Redesign migration, which replaces the old profiles-based schema).

There are 14 tables: people (contacts), the event (events), participation (registrations, sponsors), the schedule (slots, sessions, session_speakers), the event's activity (preferences, connections, checkins, feedback, leaderboard, points_log), and the interface audit (sync_runs).

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.

erDiagram
    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"

contacts — people (source of truth)

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
email text PK The ticket-purchase email (login identifier)
full_name text
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
external_id text nullable — the Pretix order code (set by the sync)
created_at timestamptz

Index: contacts_qr_token_idx (qr_token) — fast lanyard lookups. Partial unique index: contacts_external_id_uniq (external_id) WHERE external_id IS NOT NULL.

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
external_id text nullable — the Pretix order code (set by the sync)
created_at timestamptz

Constraint: unique (event_id, contact_email) — one registration per contact per event. Partial unique index: registrations_external_id_uniq (external_id) WHERE external_id IS NOT NULL.

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 / 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
room text "Main Stage" / "Room A" / "Room B"
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
external_id text nullable — the Sessionize session id (set by the sync)
created_at timestamptz

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). Partial unique index: sessions_external_id_uniq (external_id) WHERE external_id IS NOT NULL.

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
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 (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
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 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 a contact

Column Type Notes
id uuid PK
event_id uuid FK → events on delete cascade
contact_email text FK → contacts the attendee being checked in
session_id uuid FK → sessions
staff_email text FK → contacts the staff member who scanned
created_at timestamptz

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
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 (event_id, contact_email, session_id) — one feedback per contact per session.

leaderboard — Realtime mirror

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).

Column Type Notes
event_id uuid PK FK → events
contact_email text PK FK → contacts
full_name text denormalized for display
points integer
updated_at timestamptz

PK: (event_id, contact_email). The app subscribes to postgres_changes on this table to update the leaderboard live. See ../frontend/screens.md#leaderboard.

points_log — audit trail

Powers the per-category points breakdown on the Profile screen (per event).

Column Type Notes
id uuid PK
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_event_id_idx (event_id).

sync_runs — interface sync audit

One row per Pretix/Sessionize sync run, written by the service-role-only sync RPCs (see interfaces.md).

Column Type Notes
id uuid PK gen_random_uuid()
source text pretix | sessionize
started_at timestamptz
finished_at timestamptz nullable
created integer rows created
updated integer rows updated
skipped integer rows skipped
error text nullable — top-level error, if any
triggered_by text default service_role

Index: sync_runs_source_idx (source). RLS: admin-only select.

Other indexes

  • 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). A session's material_path points at the object; the public URL is /storage/v1/object/public/materials/{material_path}.