Phase 0 + 1: Dockerized Supabase core + attendee PWA

Phase 0 — Supabase core (Docker via CLI):
- Schema: profiles, slots, sessions, preferences, connections, checkins,
  feedback, leaderboard (Realtime mirror), points_log
- RLS on every table; transactional security-definer points RPCs
- Seed: 6 slots, 18 sessions, 13 demo users (QR token as auth password)

Phase 1 — Attendee web PWA (React + Vite + TS):
- Login via QR token + email (GoTrue, no email sent)
- Home, Agenda, Scan/Connect, staff Check-in, Feedback, live Leaderboard, Profile
- Same-origin proxy to Supabase (Vite dev / nginx in Docker)
- Docker: multi-stage build -> nginx sidecar on the Supabase network
This commit is contained in:
Lago committed 2026-08-22 16:10:59 +02:00
commit 37684ba116
45 files changed
+6922

No files matched your search

+414
View File
@@ -0,0 +1,414 @@
# For detailed configuration reference documentation, visit:
# https://supabase.com/docs/guides/local-development/cli/config
# A string used to distinguish different Supabase projects on the same host. Defaults to the
# working directory name when running `supabase init`.
project_id = "Convivo"
[api]
enabled = true
# Port to use for the API URL.
port = 54321
# Schemas to expose in your API. Tables, views and stored procedures in this schema will get API
# endpoints. `public` and `graphql_public` schemas are included by default.
schemas = ["public", "graphql_public"]
# Extra schemas to add to the search_path of every request.
extra_search_path = ["public", "extensions"]
# The maximum number of rows returns from a view, table, or stored procedure. Limits payload size
# for accidental or malicious requests.
max_rows = 1000
# Controls whether new tables, views, sequences and functions created in the `public` schema by
# `postgres` are reachable through the Data API roles (`anon`, `authenticated`, `service_role`)
# without explicit GRANTs. When unset, new entities are NOT auto-exposed, matching the new cloud
# default. Set to `true` to keep the legacy behaviour of auto-exposing new entities; this is
# deprecated and the field is removed on 2026-10-30 once the always-revoked behaviour is permanent.
# auto_expose_new_tables = true
[api.tls]
# Enable HTTPS endpoints locally using a self-signed certificate.
enabled = false
# Paths to self-signed certificate pair.
# cert_path = "../certs/my-cert.pem"
# key_path = "../certs/my-key.pem"
[db]
# Port to use for the local database URL.
port = 54322
# Port used by db diff command to initialize the shadow database.
shadow_port = 54320
# Maximum amount of time to wait for health check when starting the local database.
health_timeout = "2m"
# The database major version to use. This has to be the same as your remote database's. Run `SHOW
# server_version;` on the remote database to check.
major_version = 17
[db.pooler]
enabled = false
# Port to use for the local connection pooler.
port = 54329
# Specifies when a server connection can be reused by other clients.
# Configure one of the supported pooler modes: `transaction`, `session`.
pool_mode = "transaction"
# How many server connections to allow per user/database pair.
default_pool_size = 20
# Maximum number of client connections allowed.
max_client_conn = 100
# [db.vault]
# secret_key = "env(SECRET_VALUE)"
[db.migrations]
# If disabled, migrations will be skipped during a db push or reset.
enabled = true
# Specifies an ordered list of schema files, directories, or glob patterns that describe your database.
# Supports paths relative to supabase directory: "./schemas/*.sql", "./database".
schema_paths = []
[db.seed]
# If enabled, seeds the database after migrations during a db reset.
enabled = true
# Specifies an ordered list of seed files to load during db reset.
# Supports glob patterns relative to supabase directory: "./seeds/*.sql"
sql_paths = ["./seed.sql"]
[db.network_restrictions]
# Enable management of network restrictions.
enabled = false
# List of IPv4 CIDR blocks allowed to connect to the database.
# Defaults to allow all IPv4 connections. Set empty array to block all IPs.
allowed_cidrs = ["0.0.0.0/0"]
# List of IPv6 CIDR blocks allowed to connect to the database.
# Defaults to allow all IPv6 connections. Set empty array to block all IPs.
allowed_cidrs_v6 = ["::/0"]
# Uncomment to reject non-secure connections to the database.
# [db.ssl_enforcement]
# enabled = true
[realtime]
enabled = true
# Bind realtime via either IPv4 or IPv6. (default: IPv4)
# ip_version = "IPv6"
# The maximum length in bytes of HTTP request headers. (default: 4096)
# max_header_length = 4096
[studio]
enabled = true
# Port to use for Supabase Studio.
port = 54323
# External URL of the API server that frontend connects to.
api_url = "http://127.0.0.1"
# OpenAI API Key to use for Supabase AI in the Supabase Studio.
openai_api_key = "env(OPENAI_API_KEY)"
# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they
# are monitored, and you can view the emails that would have been sent from the web interface.
[local_smtp]
enabled = true
# Port to use for the email testing server web interface.
port = 54324
# Uncomment to expose additional ports for testing user applications that send emails.
# smtp_port = 54325
# pop3_port = 54326
# admin_email = "[email protected]"
# sender_name = "Admin"
[storage]
enabled = true
# The maximum file size allowed (e.g. "5MB", "500KB").
file_size_limit = "50MiB"
# Uncomment to configure local storage buckets
# [storage.buckets.images]
# public = false
# file_size_limit = "50MiB"
# allowed_mime_types = ["image/png", "image/jpeg"]
# objects_path = "./images"
# Allow connections via S3 compatible clients
[storage.s3_protocol]
enabled = true
# Image transformation API is available to Supabase Pro plan.
# [storage.image_transformation]
# enabled = true
# Store analytical data in S3 for running ETL jobs over Iceberg Catalog
# This feature is only available on the hosted platform.
[storage.analytics]
enabled = false
max_namespaces = 5
max_tables = 10
max_catalogs = 2
# Analytics Buckets is available to Supabase Pro plan.
# [storage.analytics.buckets.my-warehouse]
# Store vector embeddings in S3 for large and durable datasets
[storage.vector]
enabled = true
max_buckets = 10
max_indexes = 5
# Vector Buckets is available to Supabase Pro plan.
# [storage.vector.buckets.documents-openai]
[auth]
enabled = true
# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used
# in emails.
site_url = "http://127.0.0.1:3000"
# The public URL that Auth serves on. Defaults to the API external URL with `/auth/v1` appended.
# external_url = ""
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
additional_redirect_urls = ["https://127.0.0.1:3000"]
# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week).
jwt_expiry = 3600
# JWT issuer URL. If not set, defaults to auth.external_url.
# jwt_issuer = ""
# Path to JWT signing key. DO NOT commit your signing keys file to git.
# signing_keys_path = "./signing_keys.json"
# If disabled, the refresh token will never expire.
enable_refresh_token_rotation = true
# Allows refresh tokens to be reused after expiry, up to the specified interval in seconds.
# Requires enable_refresh_token_rotation = true.
refresh_token_reuse_interval = 10
# Allow/disallow new user signups to your project.
enable_signup = true
# Allow/disallow anonymous sign-ins to your project.
enable_anonymous_sign_ins = false
# Allow/disallow testing manual linking of accounts
enable_manual_linking = false
# Passwords shorter than this value will be rejected as weak. Minimum 6, recommended 8 or more.
minimum_password_length = 6
# Passwords that do not meet the following requirements will be rejected as weak. Supported values
# are: `letters_digits`, `lower_upper_letters_digits`, `lower_upper_letters_digits_symbols`
password_requirements = ""
# Configure passkey sign-ins.
# [auth.passkey]
# enabled = false
# Configure WebAuthn relying party settings (required when passkey is enabled).
# [auth.webauthn]
# rp_display_name = "Supabase"
# rp_id = "localhost"
# rp_origins = ["http://127.0.0.1:3000"]
[auth.rate_limit]
# Number of emails that can be sent per hour. Requires auth.email.smtp to be enabled.
email_sent = 2
# Number of SMS messages that can be sent per hour. Requires auth.sms to be enabled.
sms_sent = 30
# Number of anonymous sign-ins that can be made per hour per IP address. Requires enable_anonymous_sign_ins = true.
anonymous_users = 30
# Number of sessions that can be refreshed in a 5 minute interval per IP address.
token_refresh = 150
# Number of sign up and sign-in requests that can be made in a 5 minute interval per IP address (excludes anonymous users).
sign_in_sign_ups = 30
# Number of OTP / Magic link verifications that can be made in a 5 minute interval per IP address.
token_verifications = 30
# Number of Web3 logins that can be made in a 5 minute interval per IP address.
web3 = 30
# Configure one of the supported captcha providers: `hcaptcha`, `turnstile`.
# [auth.captcha]
# enabled = true
# provider = "hcaptcha"
# secret = ""
[auth.email]
# Allow/disallow new user signups via email to your project.
enable_signup = true
# If enabled, a user will be required to confirm any email change on both the old, and new email
# addresses. If disabled, only the new email is required to confirm.
double_confirm_changes = true
# If enabled, users need to confirm their email address before signing in.
enable_confirmations = false
# If enabled, users will need to reauthenticate or have logged in recently to change their password.
secure_password_change = false
# Controls the minimum amount of time that must pass before sending another signup confirmation or password reset email.
max_frequency = "1s"
# Number of characters used in the email OTP.
otp_length = 6
# Number of seconds before the email OTP expires (defaults to 1 hour).
otp_expiry = 3600
# Use a production-ready SMTP server
# [auth.email.smtp]
# enabled = true
# host = "smtp.sendgrid.net"
# port = 587
# user = "apikey"
# pass = "env(SENDGRID_API_KEY)"
# admin_email = "[email protected]"
# sender_name = "Admin"
# Uncomment to customize email template
# [auth.email.template.invite]
# subject = "You have been invited"
# content_path = "./supabase/templates/invite.html"
# Uncomment to customize notification email template
# [auth.email.notification.password_changed]
# enabled = true
# subject = "Your password has been changed"
# content_path = "./supabase/templates/password_changed_notification.html"
[auth.sms]
# Allow/disallow new user signups via SMS to your project.
enable_signup = false
# If enabled, users need to confirm their phone number before signing in.
enable_confirmations = false
# Template for sending OTP to users
template = "Your code is {{ .Code }}"
# Controls the minimum amount of time that must pass before sending another sms otp.
max_frequency = "5s"
# Use pre-defined map of phone number to OTP for testing.
# [auth.sms.test_otp]
# 4152127777 = "123456"
# Configure logged in session timeouts.
# [auth.sessions]
# Force log out after the specified duration.
# timebox = "24h"
# Force log out if the user has been inactive longer than the specified duration.
# inactivity_timeout = "8h"
# This hook runs before a new user is created and allows developers to reject the request based on the incoming user object.
# [auth.hook.before_user_created]
# enabled = true
# uri = "pg-functions://postgres/auth/before-user-created-hook"
# This hook runs before a token is issued and allows you to add additional claims based on the authentication method used.
# [auth.hook.custom_access_token]
# enabled = true
# uri = "pg-functions://<database>/<schema>/<hook_name>"
# Configure one of the supported SMS providers: `twilio`, `twilio_verify`, `messagebird`, `textlocal`, `vonage`.
[auth.sms.twilio]
enabled = false
account_sid = ""
message_service_sid = ""
# DO NOT commit your Twilio auth token to git. Use environment variable substitution instead:
auth_token = "env(SUPABASE_AUTH_SMS_TWILIO_AUTH_TOKEN)"
# Multi-factor-authentication is available to Supabase Pro plan.
[auth.mfa]
# Control how many MFA factors can be enrolled at once per user.
max_enrolled_factors = 10
# Control MFA via App Authenticator (TOTP)
[auth.mfa.totp]
enroll_enabled = false
verify_enabled = false
# Configure MFA via Phone Messaging
[auth.mfa.phone]
enroll_enabled = false
verify_enabled = false
otp_length = 6
template = "Your code is {{ .Code }}"
max_frequency = "5s"
# Configure MFA via WebAuthn
# [auth.mfa.web_authn]
# enroll_enabled = true
# verify_enabled = true
# Use an external OAuth provider. The full list of providers are: `apple`, `azure`, `bitbucket`,
# `discord`, `facebook`, `github`, `gitlab`, `google`, `keycloak`, `linkedin_oidc`, `notion`, `twitch`,
# `twitter`, `x`, `slack`, `spotify`, `workos`, `zoom`.
[auth.external.apple]
enabled = false
client_id = ""
# DO NOT commit your OAuth provider secret to git. Use environment variable substitution instead:
secret = "env(SUPABASE_AUTH_EXTERNAL_APPLE_SECRET)"
# Overrides the default auth callback URL derived from auth.external_url.
redirect_uri = ""
# Overrides the default auth provider URL. Used to support self-hosted gitlab, single-tenant Azure,
# or any other third-party OIDC providers.
url = ""
# If enabled, the nonce check will be skipped. Required for local sign in with Google auth.
skip_nonce_check = false
# If enabled, it will allow the user to successfully authenticate when the provider does not return an email address.
email_optional = false
# Allow Solana wallet holders to sign in to your project via the Sign in with Solana (SIWS, EIP-4361) standard.
# You can configure "web3" rate limit in the [auth.rate_limit] section and set up [auth.captcha] if self-hosting.
[auth.web3.solana]
enabled = false
# Use Firebase Auth as a third-party provider alongside Supabase Auth.
[auth.third_party.firebase]
enabled = false
# project_id = "my-firebase-project"
# Use Auth0 as a third-party provider alongside Supabase Auth.
[auth.third_party.auth0]
enabled = false
# tenant = "my-auth0-tenant"
# tenant_region = "us"
# Use AWS Cognito (Amplify) as a third-party provider alongside Supabase Auth.
[auth.third_party.aws_cognito]
enabled = false
# user_pool_id = "my-user-pool-id"
# user_pool_region = "us-east-1"
# Use Clerk as a third-party provider alongside Supabase Auth.
[auth.third_party.clerk]
enabled = false
# Obtain from https://clerk.com/setup/supabase
# domain = "example.clerk.accounts.dev"
# OAuth server configuration
[auth.oauth_server]
# Enable OAuth server functionality
enabled = false
# Path for OAuth consent flow UI
authorization_url_path = "/oauth/consent"
# Allow dynamic client registration
allow_dynamic_registration = false
[edge_runtime]
enabled = true
# Supported request policies: `oneshot`, `per_worker`.
# `per_worker` (default) — enables hot reload during local development.
# `oneshot` — fallback mode if hot reload causes issues (e.g. in large repos or with symlinks).
policy = "per_worker"
# Port to attach the Chrome inspector for debugging edge functions.
inspector_port = 8083
# The Deno major version to use.
deno_version = 2
# [edge_runtime.secrets]
# secret_key = "env(SECRET_VALUE)"
[analytics]
enabled = true
port = 54327
# Configure one of the supported backends: `postgres`, `bigquery`.
backend = "postgres"
# Experimental features may be deprecated any time
[experimental]
# Configures Postgres storage engine to use OrioleDB (S3)
orioledb_version = ""
# Configures S3 bucket URL, eg. <bucket_name>.s3-<region>.amazonaws.com
s3_host = "env(S3_HOST)"
# Configures S3 bucket region, eg. us-east-1
s3_region = "env(S3_REGION)"
# Configures AWS_ACCESS_KEY_ID for S3 bucket
s3_access_key = "env(S3_ACCESS_KEY)"
# Configures AWS_SECRET_ACCESS_KEY for S3 bucket
s3_secret_key = "env(S3_SECRET_KEY)"
# pg-delta is the schema diff engine for db diff / db pull / db remote commit.
# Set enabled = false to fall back to the legacy migra engine.
[experimental.pgdelta]
enabled = true
# Directory under `supabase/` where declarative files are written.
# declarative_schema_path = "./schemas"
# JSON string passed through to pg-delta SQL formatting.
# format_options = "{\"keywordCase\":\"upper\",\"indent\":2,\"maxWidth\":80,\"commaStyle\":\"trailing\"}"
+451
View File
@@ -0,0 +1,451 @@
-- =============================================================================
-- Convivo — Phase 0: initial schema, RLS, and transactional points RPCs
-- =============================================================================
create extension if not exists "pgcrypto";
-- -----------------------------------------------------------------------------
-- TABLES
-- -----------------------------------------------------------------------------
-- Source of truth for people. `id` is the Supabase Auth user id.
-- `qr_token` is the lanyard token; it doubles as the Auth password for the
-- QR + email login flow (no email is ever sent).
create table public.profiles (
id uuid primary key references auth.users (id) on delete cascade,
email text not null unique,
full_name text not null,
company text,
role text not null default 'attendee' check (role in ('attendee', 'staff', 'admin')),
qr_token text unique,
points integer not null default 0 check (points >= 0),
created_at timestamptz not null default now()
);
create table public.slots (
id integer primary key,
name text not null,
slot_date date not null,
start_time time not null,
end_time time not null
);
create table public.sessions (
id uuid primary key default gen_random_uuid(),
title text not null,
description text,
slot_id integer not null references public.slots (id) on delete cascade,
room text,
capacity integer,
speakers text,
created_at timestamptz not null default now()
);
-- One preferred session per slot per attendee.
create table public.preferences (
id uuid primary key default gen_random_uuid(),
profile_id uuid not null references public.profiles (id) on delete cascade,
session_id uuid not null references public.sessions (id) on delete cascade,
slot_id integer not null,
created_at timestamptz not null default now(),
unique (profile_id, slot_id)
);
-- The custom M:N networking relationship. Unique per unordered pair.
create table public.connections (
id uuid primary key default gen_random_uuid(),
from_id uuid not null references public.profiles (id) on delete cascade,
to_id uuid not null references public.profiles (id) on delete cascade,
status text not null default 'pending' check (status in ('pending', 'accepted', 'rejected')),
created_at timestamptz not null default now(),
resolved_at timestamptz
);
create unique index connections_pair_uniq
on public.connections (least(from_id, to_id), greatest(from_id, to_id));
-- Staff check-in of an attendee into a session. Unique per (attendee, session).
create table public.checkins (
id uuid primary key default gen_random_uuid(),
profile_id uuid not null references public.profiles (id) on delete cascade,
session_id uuid not null references public.sessions (id) on delete cascade,
staff_id uuid not null references public.profiles (id) on delete cascade,
created_at timestamptz not null default now(),
unique (profile_id, session_id)
);
-- Post-session feedback. Unique per (attendee, session).
create table public.feedback (
id uuid primary key default gen_random_uuid(),
profile_id uuid not null references public.profiles (id) on delete cascade,
session_id uuid not null references public.sessions (id) on delete cascade,
rating integer not null check (rating between 1 and 5),
comment text,
created_at timestamptz not null default now(),
unique (profile_id, session_id)
);
-- Public, Realtime-friendly mirror of points for the live leaderboard.
-- Kept in sync transactionally by the points RPCs (see _sync_leaderboard).
create table public.leaderboard (
profile_id uuid primary key references public.profiles (id) on delete cascade,
full_name text not null,
company text,
points integer not null default 0,
updated_at timestamptz not null default now()
);
-- Audit trail powering the per-category points breakdown.
create table public.points_log (
id uuid primary key default gen_random_uuid(),
profile_id uuid not null references public.profiles (id) on delete cascade,
delta integer not null,
category text not null check (category in ('checkin', 'connection', 'feedback', 'admin')),
created_at timestamptz not null default now()
);
create index sessions_slot_id_idx on public.sessions (slot_id);
create index checkins_session_id_idx on public.checkins (session_id);
create index points_log_profile_id_idx on public.points_log (profile_id);
create index profiles_qr_token_idx on public.profiles (qr_token);
-- -----------------------------------------------------------------------------
-- ROLE HELPER FUNCTIONS (security definer so they can read profiles in RLS)
-- -----------------------------------------------------------------------------
create or replace function public.is_admin() returns boolean
language sql stable security definer set search_path = public as $$
select exists (select 1 from public.profiles where id = auth.uid() and role = 'admin');
$$;
create or replace function public.is_staff_or_admin() returns boolean
language sql stable security definer set search_path = public as $$
select exists (select 1 from public.profiles where id = auth.uid() and role in ('staff', 'admin'));
$$;
-- -----------------------------------------------------------------------------
-- INTERNAL POINTS HELPERS (security definer: bypass RLS, run as owner)
-- -----------------------------------------------------------------------------
create or replace function public._sync_leaderboard(p_profile_id uuid) returns void
language plpgsql security definer set search_path = public as $$
begin
insert into public.leaderboard (profile_id, full_name, company, points)
select id, full_name, company, points from public.profiles where id = p_profile_id
on conflict (profile_id) do update
set full_name = excluded.full_name,
company = excluded.company,
points = excluded.points,
updated_at = now();
end;
$$;
create or replace function public._award_points(p_profile_id uuid, p_delta integer, p_category text) returns void
language plpgsql security definer set search_path = public as $$
begin
update public.profiles set points = greatest(0, points + p_delta) where id = p_profile_id;
insert into public.points_log (profile_id, delta, category) values (p_profile_id, p_delta, p_category);
perform public._sync_leaderboard(p_profile_id);
end;
$$;
-- -----------------------------------------------------------------------------
-- PUBLIC READ FUNCTIONS (security definer: expose only public columns)
-- -----------------------------------------------------------------------------
-- Powers the leaderboard initial load and id -> name/company/role lookups.
create or replace function public.get_public_profiles()
returns table (id uuid, full_name text, company text, role text, points integer)
language sql stable security definer set search_path = public as $$
select id, full_name, company, role, points
from public.profiles
order by points desc, full_name asc;
$$;
-- Resolves a scanned lanyard QR token to a public profile (pre-login + connect).
create or replace function public.lanyard_lookup(p_qr_token text)
returns table (id uuid, full_name text, company text, role text)
language sql stable security definer set search_path = public as $$
select id, full_name, company, role
from public.profiles
where qr_token = p_qr_token;
$$;
-- -----------------------------------------------------------------------------
-- RPCs
-- -----------------------------------------------------------------------------
-- Set (or change) the preferred session for the slot that p_session_id belongs to.
create or replace function public.set_preference(p_session_id uuid)
returns public.preferences
language plpgsql security definer set search_path = public as $$
declare
v_uid uuid := auth.uid();
v_slot_id integer;
v_pref public.preferences;
begin
if v_uid is null then raise exception 'not authenticated'; end if;
select slot_id into v_slot_id from public.sessions where id = p_session_id;
if v_slot_id is null then raise exception 'session not found'; end if;
delete from public.preferences where profile_id = v_uid and slot_id = v_slot_id;
insert into public.preferences (profile_id, session_id, slot_id)
values (v_uid, p_session_id, v_slot_id)
returning * into v_pref;
return v_pref;
end;
$$;
create or replace function public.clear_preference(p_slot_id integer)
returns void
language plpgsql security definer set search_path = public as $$
declare
v_uid uuid := auth.uid();
begin
if v_uid is null then raise exception 'not authenticated'; end if;
delete from public.preferences where profile_id = v_uid and slot_id = p_slot_id;
end;
$$;
-- Create a pending connection to the attendee whose lanyard QR was scanned.
-- Idempotent: returns the existing connection if the pair already has one.
create or replace function public.create_connection_request(p_target_qr text)
returns public.connections
language plpgsql security definer set search_path = public as $$
declare
v_uid uuid := auth.uid();
v_target uuid;
v_conn public.connections;
begin
if v_uid is null then raise exception 'not authenticated'; end if;
select id into v_target from public.profiles where qr_token = p_target_qr;
if v_target is null then raise exception 'no attendee found for that QR code'; end if;
if v_target = v_uid then raise exception 'you cannot connect with yourself'; end if;
select * into v_conn from public.connections
where (from_id = v_uid and to_id = v_target) or (from_id = v_target and to_id = v_uid)
limit 1;
if found then
return v_conn;
end if;
insert into public.connections (from_id, to_id, status)
values (v_uid, v_target, 'pending')
returning * into v_conn;
return v_conn;
end;
$$;
-- Accept an incoming connection request. Awards +5 to both parties.
create or replace function public.accept_connection(p_connection_id uuid)
returns public.connections
language plpgsql security definer set search_path = public as $$
declare
v_uid uuid := auth.uid();
v_conn public.connections;
begin
if v_uid is null then raise exception 'not authenticated'; end if;
select * into v_conn from public.connections where id = p_connection_id for update;
if not found then raise exception 'connection not found'; end if;
if v_conn.to_id <> v_uid then raise exception 'you can only accept incoming requests'; end if;
if v_conn.status <> 'pending' then raise exception 'request already resolved'; end if;
update public.connections set status = 'accepted', resolved_at = now() where id = p_connection_id;
perform public._award_points(v_conn.from_id, 5, 'connection');
perform public._award_points(v_conn.to_id, 5, 'connection');
select * into v_conn from public.connections where id = p_connection_id;
return v_conn;
end;
$$;
create or replace function public.reject_connection(p_connection_id uuid)
returns public.connections
language plpgsql security definer set search_path = public as $$
declare
v_uid uuid := auth.uid();
v_conn public.connections;
begin
if v_uid is null then raise exception 'not authenticated'; end if;
select * into v_conn from public.connections where id = p_connection_id for update;
if not found then raise exception 'connection not found'; end if;
if v_conn.to_id <> v_uid then raise exception 'you can only reject incoming requests'; end if;
if v_conn.status <> 'pending' then raise exception 'request already resolved'; end if;
update public.connections set status = 'rejected', resolved_at = now() where id = p_connection_id;
select * into v_conn from public.connections where id = p_connection_id;
return v_conn;
end;
$$;
-- Staff checks an attendee into a session. Awards +10 to the attendee.
-- Returns already=true if the attendee was already checked in (no double points).
create or replace function public.checkin_attendee(p_session_id uuid, p_attendee_qr text)
returns table (checkin_id uuid, attendee_id uuid, attendee_name text, points integer, already boolean)
language plpgsql security definer set search_path = public as $$
declare
v_uid uuid := auth.uid();
v_attendee uuid;
v_name text;
v_new_id uuid;
v_points integer;
v_already boolean := false;
begin
if v_uid is null then raise exception 'not authenticated'; end if;
if not public.is_staff_or_admin() then raise exception 'staff or admin only'; end if;
select id, full_name into v_attendee, v_name from public.profiles where qr_token = p_attendee_qr;
if v_attendee is null then raise exception 'no attendee found for that QR code'; end if;
insert into public.checkins (profile_id, session_id, staff_id)
values (v_attendee, p_session_id, v_uid)
on conflict (profile_id, session_id) do nothing
returning id into v_new_id;
if v_new_id is null then
-- Already checked in: no double points; report the existing check-in.
v_already := true;
select id into v_new_id from public.checkins where profile_id = v_attendee and session_id = p_session_id;
else
perform public._award_points(v_attendee, 10, 'checkin');
end if;
select p.points into v_points from public.profiles p where p.id = v_attendee;
return query select v_new_id, v_attendee, v_name, v_points, v_already;
end;
$$;
-- Post-session feedback. Requires the attendee to be checked in.
-- Awards +5 (rating only) or +10 (rating + comment). Idempotent per session.
create or replace function public.submit_feedback(p_session_id uuid, p_rating integer, p_comment text)
returns table (feedback_id uuid, points integer, earned integer)
language plpgsql security definer set search_path = public as $$
declare
v_uid uuid := auth.uid();
v_earned integer;
v_fb_id uuid;
v_points integer;
v_clean text;
v_exists boolean;
begin
if v_uid is null then raise exception 'not authenticated'; end if;
if p_rating is null or p_rating < 1 or p_rating > 5 then raise exception 'rating must be between 1 and 5'; end if;
if not exists (select 1 from public.checkins where profile_id = v_uid and session_id = p_session_id) then
raise exception 'you must be checked in to this session to give feedback';
end if;
v_clean := nullif(btrim(coalesce(p_comment, '')), '');
v_earned := case when v_clean is not null then 10 else 5 end;
select exists (select 1 from public.feedback where profile_id = v_uid and session_id = p_session_id) into v_exists;
if v_exists then
update public.feedback set rating = p_rating, comment = v_clean
where profile_id = v_uid and session_id = p_session_id;
select id into v_fb_id from public.feedback where profile_id = v_uid and session_id = p_session_id;
v_earned := 0; -- already rewarded on first submission
else
insert into public.feedback (profile_id, session_id, rating, comment)
values (v_uid, p_session_id, p_rating, v_clean)
returning id into v_fb_id;
perform public._award_points(v_uid, v_earned, 'feedback');
end if;
select p.points into v_points from public.profiles p where p.id = v_uid;
return query select v_fb_id, v_points, v_earned;
end;
$$;
-- Admin-only manual points adjustment.
create or replace function public.adjust_points(p_profile_id uuid, p_delta integer, p_reason text)
returns void
language plpgsql security definer set search_path = public as $$
declare
v_uid uuid := auth.uid();
begin
if v_uid is null then raise exception 'not authenticated'; end if;
if not public.is_admin() then raise exception 'admin only'; end if;
perform public._award_points(p_profile_id, p_delta, 'admin');
end;
$$;
-- Full agenda: slots (ordered) each with their sessions.
create or replace function public.get_agenda()
returns table (
slot_id integer, slot_name text, slot_date date, start_time time, end_time time,
session_id uuid, title text, description text, room text, capacity integer, speakers text
)
language sql stable security definer set search_path = public as $$
select s.id, s.name, s.slot_date, s.start_time, s.end_time,
se.id, se.title, se.description, se.room, se.capacity, se.speakers
from public.slots s
left join public.sessions se on se.slot_id = s.id
order by s.id, se.title;
$$;
-- -----------------------------------------------------------------------------
-- ROW LEVEL SECURITY
-- -----------------------------------------------------------------------------
alter table public.profiles enable row level security;
alter table public.slots enable row level security;
alter table public.sessions enable row level security;
alter table public.preferences enable row level security;
alter table public.connections enable row level security;
alter table public.checkins enable row level security;
alter table public.feedback enable row level security;
alter table public.leaderboard enable row level security;
alter table public.points_log enable row level security;
-- profiles: full row only for self or admin (protects email + qr_token).
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
using (public.is_admin()) with check (public.is_admin());
create policy "profiles_delete_admin" on public.profiles for delete to authenticated
using (public.is_admin());
-- slots: readable by all authenticated; writable by admin.
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: readable by all authenticated; writable by admin.
create policy "sessions_select_all" on public.sessions for select to authenticated using (true);
create policy "sessions_admin_insert" on public.sessions for insert to authenticated with check (public.is_admin());
create policy "sessions_admin_update" on public.sessions for update to authenticated using (public.is_admin()) with check (public.is_admin());
create policy "sessions_admin_delete" on public.sessions for delete to authenticated using (public.is_admin());
-- preferences: read own; writes happen via RPC (security definer).
create policy "prefs_select_own" on public.preferences for select to authenticated
using (profile_id = auth.uid());
-- connections: read any row you're part of; writes happen via RPC.
create policy "conn_select_involved" on public.connections for select to authenticated
using (from_id = auth.uid() or to_id = auth.uid());
-- checkins: read own, or all if staff/admin; writes happen via RPC.
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());
-- feedback: read own; writes happen via RPC.
create policy "feedback_select_own" on public.feedback for select to authenticated
using (profile_id = auth.uid());
-- 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());
-- -----------------------------------------------------------------------------
-- GRANTS
-- The new Supabase CLI does NOT auto-expose new tables to the Data API roles,
-- so grant explicitly. RLS still governs what each role can actually see.
-- -----------------------------------------------------------------------------
grant usage on schema public to anon, authenticated, service_role;
grant select on public.profiles, public.slots, public.sessions, public.preferences,
public.connections, public.checkins, public.feedback,
public.leaderboard, public.points_log
to anon, authenticated, service_role;
grant insert, update, delete on public.profiles, public.slots, public.sessions,
public.preferences, public.connections, public.checkins,
public.feedback, public.leaderboard, public.points_log
to authenticated, service_role;
grant execute on function public.is_admin() to authenticated;
grant execute on function public.is_staff_or_admin() to authenticated;
grant execute on function public.get_public_profiles() to authenticated;
grant execute on function public.lanyard_lookup(text) to authenticated;
grant execute on function public.set_preference(uuid) to authenticated;
grant execute on function public.clear_preference(integer) to authenticated;
grant execute on function public.create_connection_request(text) to authenticated;
grant execute on function public.accept_connection(uuid) to authenticated;
grant execute on function public.reject_connection(uuid) to authenticated;
grant execute on function public.checkin_attendee(uuid, text) to authenticated;
grant execute on function public.submit_feedback(uuid, integer, text) to authenticated;
grant execute on function public.adjust_points(uuid, integer, text) to authenticated;
grant execute on function public.get_agenda() to authenticated;
+160
View File
@@ -0,0 +1,160 @@
-- =============================================================================
-- Convivo — Phase 0: seed data
-- Ports the mockup's slots/sessions/people into real Supabase Auth users + rows.
-- The QR token is the Auth password (QR + email login, no email sent).
-- =============================================================================
-- -----------------------------------------------------------------------------
-- SLOTS (23 Oct)
-- -----------------------------------------------------------------------------
insert into public.slots (id, name, slot_date, start_time, end_time) values
(1, 'Slot 1', '2026-10-23', '09:00:00', '09:45:00'),
(2, 'Slot 2', '2026-10-23', '10:00:00', '10:45:00'),
(3, 'Slot 3', '2026-10-23', '11:30:00', '12:15:00'),
(4, 'Slot 4', '2026-10-23', '13:15:00', '14:00:00'),
(5, 'Slot 5', '2026-10-23', '14:00:00', '14:45:00'),
(6, 'Slot 6', '2026-10-23', '15:00:00', '15:45:00')
on conflict (id) do nothing;
-- -----------------------------------------------------------------------------
-- SESSIONS (18 — 3 per slot)
-- -----------------------------------------------------------------------------
insert into public.sessions (id, title, description, slot_id, room, capacity, speakers) values
('10000000-0000-0000-0000-000000000001', 'Opening Keynote: The Next Decade of AI', 'A wide-angle look at where AI is heading over the next ten years — and what it means for product teams.', 1, 'Main Stage', 300, 'Dr. Elena Vasquez'),
('10000000-0000-0000-0000-000000000002', 'Designing for Trust in AI Products', 'Practical patterns for making AI features transparent, explainable, and safe for your users.', 1, 'Room A', 80, 'Marco Chen'),
('10000000-0000-0000-0000-000000000003', 'From Hackathon to Product', 'How a weekend prototype became a product with 40k users — the messy middle included.', 1, 'Room B', 60, 'Sofia Almeida'),
('10000000-0000-0000-0000-000000000004', 'AI in Practice: Lessons from Production', 'Lessons learned shipping LLM features to production: latency, cost, evals, and the surprises.', 2, 'Main Stage', 300, 'Bruno Costa'),
('10000000-0000-0000-0000-000000000005', 'The Introvert''s Guide to Networking', 'Small, low-energy ways to have big conversations at any event. (Yes, this one is for you.)', 2, 'Room A', 80, 'Rita Lopes'),
('10000000-0000-0000-0000-000000000006', 'Building with Dataverse: Beyond the Basics', 'Go beyond the basics: relationships, security roles, and automations that actually scale.', 2, 'Room B', 60, 'Tomás Ribeiro'),
('10000000-0000-0000-0000-000000000007', 'Scaling Teams at 10x', 'What breaks when you grow 10x in two years, and the rituals that kept us sane.', 3, 'Main Stage', 300, 'Julia Santos'),
('10000000-0000-0000-0000-000000000008', 'Security by Design', 'Baking security into the product from day one instead of bolting it on at the end.', 3, 'Room A', 80, 'Pedro Nunes'),
('10000000-0000-0000-0000-000000000009', 'Data Storytelling', 'Turn dashboards into narratives your stakeholders actually remember.', 3, 'Room B', 60, 'Carla Mendes'),
('10000000-0000-0000-0000-000000000010', 'The Future of Work', 'Hybrid, async, and AI-augmented: where work is going and how to prepare for it.', 4, 'Main Stage', 300, 'Dr. Elena Vasquez'),
('10000000-0000-0000-0000-000000000011', 'Prototyping with AI', 'From idea to clickable prototype in an afternoon — tools and workflows that work.', 4, 'Room A', 80, 'Diego Ferreira'),
('10000000-0000-0000-0000-000000000012', 'Pricing SaaS in 2026', 'Usage-based, seat-based, or hybrid? What is actually working right now.', 4, 'Room B', 60, 'Marina Costa'),
('10000000-0000-0000-0000-000000000013', 'Community-Led Growth', 'Building a community that sells for you — case studies and playbooks.', 5, 'Main Stage', 300, 'Lucas Oliveira'),
('10000000-0000-0000-0000-000000000014', 'Accessibility First', 'Why accessible products are better products, and how to start this sprint.', 5, 'Room A', 80, 'Carla Mendes'),
('10000000-0000-0000-0000-000000000015', 'The Art of the Demo', 'Structure, pacing, and the moments that make a demo land.', 5, 'Room B', 60, 'Pedro Nunes'),
('10000000-0000-0000-0000-000000000016', 'Closing Panel: What''s Next', 'Founders, researchers, and builders on what comes next — with audience Q&A.', 6, 'Main Stage', 300, 'Elena · Bruno · Rita'),
('10000000-0000-0000-0000-000000000017', 'Open Space: Your Ideas', 'You bring the topic, we bring the room. 45 minutes of your ideas.', 6, 'Room A', 80, 'Facilitated by Ana Silva'),
('10000000-0000-0000-0000-000000000018', 'Lightning Talks', 'Eight speakers, five minutes each. Fast, fun, and unpredictable.', 6, 'Room B', 60, '8 speakers')
on conflict (id) do nothing;
-- -----------------------------------------------------------------------------
-- AUTH USERS (QR token = password). 12 attendees + 1 admin.
-- -----------------------------------------------------------------------------
-- NOTE: confirmation_token is set to '' (not NULL) because GoTrue's password
-- grant cannot scan a NULL confirmation_token on manually-inserted users.
insert into auth.users (instance_id, id, aud, role, email, encrypted_password, email_confirmed_at, confirmation_token, recovery_token, email_change_token_new, email_change, raw_app_meta_data, raw_user_meta_data, created_at, updated_at, confirmation_sent_at, last_sign_in_at) values
('00000000-0000-0000-0000-000000000000', '11111111-1111-1111-1111-111111111111', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-ANA-4821', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Ana Silva"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', '22222222-2222-2222-2222-222222222222', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-BRU-1177', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Bruno Costa"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', '33333333-3333-3333-3333-333333333333', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-RIT-9034', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Rita Lopes"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', '44444444-4444-4444-4444-444444444444', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-TOM-5566', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Tomás Ribeiro"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', '55555555-5555-5555-5555-555555555555', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-SOF-2299', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Sofia Almeida"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', '66666666-6666-6666-6666-666666666666', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-MRC-7712', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Marco Chen"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', '77777777-7777-7777-7777-777777777777', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-JUL-3345', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Julia Santos"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', '88888888-8888-8888-8888-888888888888', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-PED-8801', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Pedro Nunes"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', '99999999-9999-9999-9999-999999999999', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-CAR-6623', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Carla Mendes"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-DIE-4458', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Diego Ferreira"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-MNA-2210', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Marina Costa"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', 'cccccccc-cccc-cccc-cccc-cccccccccccc', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-LUC-9987', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Lucas Oliveira"}', now(), now(), now(), now()),
('00000000-0000-0000-0000-000000000000', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'authenticated', 'authenticated', '[email protected]', crypt('CVV-ADM-0001', gen_salt('bf')), now(), '', '', '', '', '{"provider":"email","providers":["email"]}', '{"full_name":"Convivo Admin"}', now(), now(), now(), now())
on conflict (id) do nothing;
insert into auth.identities (id, provider_id, identity_data, provider, user_id, created_at, updated_at, last_sign_in_at) values
('11111111-1111-1111-1111-111111111111', '11111111-1111-1111-1111-111111111111', '{"sub":"11111111-1111-1111-1111-111111111111","email":"[email protected]"}', 'email', '11111111-1111-1111-1111-111111111111', now(), now(), now()),
('22222222-2222-2222-2222-222222222222', '22222222-2222-2222-2222-222222222222', '{"sub":"22222222-2222-2222-2222-222222222222","email":"[email protected]"}', 'email', '22222222-2222-2222-2222-222222222222', now(), now(), now()),
('33333333-3333-3333-3333-333333333333', '33333333-3333-3333-3333-333333333333', '{"sub":"33333333-3333-3333-3333-333333333333","email":"[email protected]"}', 'email', '33333333-3333-3333-3333-333333333333', now(), now(), now()),
('44444444-4444-4444-4444-444444444444', '44444444-4444-4444-4444-444444444444', '{"sub":"44444444-4444-4444-4444-444444444444","email":"[email protected]"}', 'email', '44444444-4444-4444-4444-444444444444', now(), now(), now()),
('55555555-5555-5555-5555-555555555555', '55555555-5555-5555-5555-555555555555', '{"sub":"55555555-5555-5555-5555-555555555555","email":"[email protected]"}', 'email', '55555555-5555-5555-5555-555555555555', now(), now(), now()),
('66666666-6666-6666-6666-666666666666', '66666666-6666-6666-6666-666666666666', '{"sub":"66666666-6666-6666-6666-666666666666","email":"[email protected]"}', 'email', '66666666-6666-6666-6666-666666666666', now(), now(), now()),
('77777777-7777-7777-7777-777777777777', '77777777-7777-7777-7777-777777777777', '{"sub":"77777777-7777-7777-7777-777777777777","email":"[email protected]"}', 'email', '77777777-7777-7777-7777-777777777777', now(), now(), now()),
('88888888-8888-8888-8888-888888888888', '88888888-8888-8888-8888-888888888888', '{"sub":"88888888-8888-8888-8888-888888888888","email":"[email protected]"}', 'email', '88888888-8888-8888-8888-888888888888', now(), now(), now()),
('99999999-9999-9999-9999-999999999999', '99999999-9999-9999-9999-999999999999', '{"sub":"99999999-9999-9999-9999-999999999999","email":"[email protected]"}', 'email', '99999999-9999-9999-9999-999999999999', now(), now(), now()),
('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '{"sub":"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa","email":"[email protected]"}', 'email', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', now(), now(), now()),
('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', '{"sub":"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb","email":"[email protected]"}', 'email', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', now(), now(), now()),
('cccccccc-cccc-cccc-cccc-cccccccccccc', 'cccccccc-cccc-cccc-cccc-cccccccccccc', '{"sub":"cccccccc-cccc-cccc-cccc-cccccccccccc","email":"[email protected]"}', 'email', 'cccccccc-cccc-cccc-cccc-cccccccccccc', now(), now(), now()),
('dddddddd-dddd-dddd-dddd-dddddddddddd', 'dddddddd-dddd-dddd-dddd-dddddddddddd', '{"sub":"dddddddd-dddd-dddd-dddd-dddddddddddd","email":"[email protected]"}', 'email', 'dddddddd-dddd-dddd-dddd-dddddddddddd', now(), now(), now())
on conflict (id) do nothing;
-- -----------------------------------------------------------------------------
-- PROFILES
-- -----------------------------------------------------------------------------
insert into public.profiles (id, email, full_name, company, role, qr_token, points) values
('11111111-1111-1111-1111-111111111111', '[email protected]', 'Ana Silva', 'Nubank', 'attendee', 'CVV-ANA-4821', 40),
('22222222-2222-2222-2222-222222222222', '[email protected]', 'Bruno Costa', 'Acme Corp', 'staff', 'CVV-BRU-1177', 140),
('33333333-3333-3333-3333-333333333333', '[email protected]', 'Rita Lopes', 'Globant', 'staff', 'CVV-RIT-9034', 95),
('44444444-4444-4444-4444-444444444444', '[email protected]', 'Tomás Ribeiro', 'Dataprev', 'attendee', 'CVV-TOM-5566', 88),
('55555555-5555-5555-5555-555555555555', '[email protected]', 'Sofia Almeida', 'Loop', 'attendee', 'CVV-SOF-2299', 76),
('66666666-6666-6666-6666-666666666666', '[email protected]', 'Marco Chen', 'DeepMind', 'attendee', 'CVV-MRC-7712', 70),
('77777777-7777-7777-7777-777777777777', '[email protected]', 'Julia Santos', 'iFood', 'attendee', 'CVV-JUL-3345', 64),
('88888888-8888-8888-8888-888888888888', '[email protected]', 'Pedro Nunes', 'Microsoft', 'attendee', 'CVV-PED-8801', 58),
('99999999-9999-9999-9999-999999999999', '[email protected]', 'Carla Mendes', 'QuintoEssencial', 'attendee', 'CVV-CAR-6623', 52),
('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '[email protected]', 'Diego Ferreira', 'Stone', 'attendee', 'CVV-DIE-4458', 35),
('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', '[email protected]', 'Marina Costa', 'OLX', 'attendee', 'CVV-MNA-2210', 28),
('cccccccc-cccc-cccc-cccc-cccccccccccc', '[email protected]', 'Lucas Oliveira', 'USP', 'attendee', 'CVV-LUC-9987', 15),
('dddddddd-dddd-dddd-dddd-dddddddddddd', '[email protected]', 'Convivo Admin', 'Convivo', 'admin', 'CVV-ADM-0001', 0)
on conflict (id) do nothing;
-- -----------------------------------------------------------------------------
-- LEADERBOARD (mirror of points)
-- -----------------------------------------------------------------------------
insert into public.leaderboard (profile_id, full_name, company, points)
select id, full_name, company, points from public.profiles
on conflict (profile_id) do update
set full_name = excluded.full_name, company = excluded.company, points = excluded.points, updated_at = now();
-- -----------------------------------------------------------------------------
-- POINTS LOG
-- Ana: a coherent breakdown (2 checkins, 2 connections, 1 feedback = 40).
-- Everyone else: a single 'admin' seed entry for their starting points.
-- -----------------------------------------------------------------------------
insert into public.points_log (profile_id, delta, category) values
('11111111-1111-1111-1111-111111111111', 10, 'checkin'),
('11111111-1111-1111-1111-111111111111', 10, 'checkin'),
('11111111-1111-1111-1111-111111111111', 5, 'connection'),
('11111111-1111-1111-1111-111111111111', 5, 'connection'),
('11111111-1111-1111-1111-111111111111', 10, 'feedback'),
('22222222-2222-2222-2222-222222222222', 140, 'admin'),
('33333333-3333-3333-3333-333333333333', 95, 'admin'),
('44444444-4444-4444-4444-444444444444', 88, 'admin'),
('55555555-5555-5555-5555-555555555555', 76, 'admin'),
('66666666-6666-6666-6666-666666666666', 70, 'admin'),
('77777777-7777-7777-7777-777777777777', 64, 'admin'),
('88888888-8888-8888-8888-888888888888', 58, 'admin'),
('99999999-9999-9999-9999-999999999999', 52, 'admin'),
('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 35, 'admin'),
('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 28, 'admin'),
('cccccccc-cccc-cccc-cccc-cccccccccccc', 15, 'admin');
-- -----------------------------------------------------------------------------
-- ANA'S DEMO STATE (so the app looks alive on first login)
-- -----------------------------------------------------------------------------
-- Preferences: one pick per slot (matches the mockup).
insert into public.preferences (profile_id, session_id, slot_id) values
('11111111-1111-1111-1111-111111111111', '10000000-0000-0000-0000-000000000002', 1),
('11111111-1111-1111-1111-111111111111', '10000000-0000-0000-0000-000000000004', 2),
('11111111-1111-1111-1111-111111111111', '10000000-0000-0000-0000-000000000009', 3),
('11111111-1111-1111-1111-111111111111', '10000000-0000-0000-0000-000000000011', 4),
('11111111-1111-1111-1111-111111111111', '10000000-0000-0000-0000-000000000013', 5),
('11111111-1111-1111-1111-111111111111', '10000000-0000-0000-0000-000000000016', 6)
on conflict (profile_id, slot_id) do nothing;
-- Check-ins: Ana is checked into Slot 1 (s2) and Slot 2 (s4), by staff Bruno.
insert into public.checkins (profile_id, session_id, staff_id) values
('11111111-1111-1111-1111-111111111111', '10000000-0000-0000-0000-000000000002', '22222222-2222-2222-2222-222222222222'),
('11111111-1111-1111-1111-111111111111', '10000000-0000-0000-0000-000000000004', '22222222-2222-2222-2222-222222222222')
on conflict (profile_id, session_id) do nothing;
-- Connections: accepted with Bruno & Rita; incoming from Sofia; outgoing to Julia.
insert into public.connections (id, from_id, to_id, status, created_at, resolved_at) values
('e0000000-0000-0000-0000-000000000001', '11111111-1111-1111-1111-111111111111', '22222222-2222-2222-2222-222222222222', 'accepted', now() - interval '2 hours', now() - interval '2 hours'),
('e0000000-0000-0000-0000-000000000002', '33333333-3333-3333-3333-333333333333', '11111111-1111-1111-1111-111111111111', 'accepted', now() - interval '90 minutes', now() - interval '90 minutes'),
('e0000000-0000-0000-0000-000000000003', '55555555-5555-5555-5555-555555555555', '11111111-1111-1111-1111-111111111111', 'pending', now() - interval '15 minutes', null),
('e0000000-0000-0000-0000-000000000004', '11111111-1111-1111-1111-111111111111', '77777777-7777-7777-7777-777777777777', 'pending', now() - interval '5 minutes', null)
on conflict (id) do nothing;
-- Feedback: Ana rated Slot 1 (s2).
insert into public.feedback (profile_id, session_id, rating, comment) values
('11111111-1111-1111-1111-111111111111', '10000000-0000-0000-0000-000000000002', 5, 'Great patterns, very practical. Wish it were longer!')
on conflict (profile_id, session_id) do nothing;