feat: add event-scoped schedule deletion and import date guard
This commit is contained in:
1 parent
ef0121a3e4
commit
5c93d4a0cb
12 files changed
+2034
-14
No files matched your search
@@ -210,6 +210,25 @@ existing uploaded `materials` object under `sessions/<this session UUID>/<filena
|
||||
There is no active-event, date, check-in or points condition. Shared by Agenda and
|
||||
the [speaker portal](../frontend/screens.md#speaker-portal).
|
||||
|
||||
### `delete_event_schedule(p_event_id)` → `jsonb`
|
||||
**Admin-only.** Deletes the slots and sessions for exactly one event in a single
|
||||
transaction. It locks the event plus that event's schedule rows, validates that
|
||||
sessions and dependent `preferences` / `checkins` / `feedback` rows do not cross
|
||||
event boundaries, then deletes `sessions` and `slots` for `p_event_id`.
|
||||
|
||||
FK cascades remove `session_speakers`, `preferences`, `checkins` and
|
||||
`feedback`. The event row, contacts, registrations, sponsors, connections,
|
||||
points, leaderboard rows and other events are preserved. Session
|
||||
`material_path` values disappear with the deleted session rows, but Storage
|
||||
objects in the `materials` bucket are not physically purged.
|
||||
|
||||
The function is `security definer` with an empty `search_path`, requires both
|
||||
`auth.uid()` and `public.is_admin()`, revokes execution from `PUBLIC` / `anon` /
|
||||
`authenticated`, then grants execution back only to `authenticated`. It returns
|
||||
counts for deleted slots, sessions and dependent rows plus the number of
|
||||
material paths left unpurged. It does not coordinate with Sessionize/Pretix
|
||||
sync; a concurrent or later import can repopulate the event schedule.
|
||||
|
||||
## Speaker Portal RPCs
|
||||
|
||||
Source: [20261006175631_speaker_portal.sql](../../supabase/migrations/20261006175631_speaker_portal.sql),
|
||||
|
||||
@@ -50,6 +50,20 @@ contacts + registrations.
|
||||
Linking a speaker to a session fires the `session_speakers_speaker_promote`
|
||||
trigger, which promotes an existing registration to `speaker`.
|
||||
|
||||
Both import paths are guarded by the event's configured `start_date` /
|
||||
`end_date`: any Sessionize session dated outside that inclusive range aborts the
|
||||
RPC before speakers, sessions, slots, links, registrations, audit rows, or event
|
||||
sync timestamps are changed. The exception includes the bad date, the configured
|
||||
range, and the actionable check to verify the Sessionize endpoint, Excel export,
|
||||
or event dates. Existing historical rows outside the range are retained by later
|
||||
successful imports; deleting or reconciling them is a separate, explicitly
|
||||
approved data-repair task.
|
||||
|
||||
The date guard lives in
|
||||
[`20261009225632_guard_sessionize_dates.sql`](../../supabase/migrations/20261009225632_guard_sessionize_dates.sql).
|
||||
It is not automatically deployed by being present in the repository; apply it
|
||||
through the normal reviewed migration path for each environment.
|
||||
|
||||
## How it reaches things
|
||||
|
||||
```mermaid
|
||||
|
||||
@@ -88,6 +88,49 @@ authorization separately. See [screen contract](../frontend/screens.md#speaker-p
|
||||
[API client](../frontend/api-client.md#speaker-portal), [RLS](./rls.md#speaker-portal-authorization)
|
||||
and [RPCs](./rpcs.md#speaker-portal-rpcs).
|
||||
|
||||
## Sessionize Date Guard
|
||||
|
||||
[sessionize_date_guard_tests.sql](../../supabase/tests/sessionize_date_guard_tests.sql)
|
||||
is an independent fail-fast rollback-only suite for the Sessionize API and Excel
|
||||
RPC date guard. It creates generated event/contact/auth fixtures, precreates
|
||||
explicit negative slot IDs so successful imports do not allocate sequence values,
|
||||
and ends with `ROLLBACK`.
|
||||
|
||||
To verify the migration and suite together on the local database without
|
||||
persisting either change:
|
||||
|
||||
```bash
|
||||
{ printf 'BEGIN;\n'; cat supabase/migrations/20261009225632_guard_sessionize_dates.sql supabase/tests/sessionize_date_guard_tests.sql; printf '\nROLLBACK;\n'; } | docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1
|
||||
```
|
||||
|
||||
The nested `BEGIN` warning from the suite is harmless in this rollback-only
|
||||
check. This command is local validation only; it does not write CLI migration
|
||||
history and is not a production deployment. Historical rows outside the newly
|
||||
configured event range are retained by successful imports and need a separately
|
||||
approved reconciliation if they should be removed or changed.
|
||||
|
||||
## Delete Event Schedule
|
||||
|
||||
[delete_event_schedule_tests.sql](../../supabase/tests/delete_event_schedule_tests.sql)
|
||||
is an independent fail-fast rollback-only suite for the admin schedule-clear RPC.
|
||||
It creates generated contacts/events/auth fixtures, uses explicit negative slot
|
||||
IDs so fixture setup does not advance `slots_id_seq`, and ends with `ROLLBACK`.
|
||||
|
||||
To verify the migration and suite together on the local database without
|
||||
persisting either change:
|
||||
|
||||
```bash
|
||||
{ printf 'BEGIN;\n'; cat supabase/migrations/20261009231817_delete_event_schedule.sql supabase/tests/delete_event_schedule_tests.sql; printf '\nROLLBACK;\n'; } | docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1
|
||||
```
|
||||
|
||||
The suite checks authenticated admin execution, non-admin rejection, anon
|
||||
execute denial, missing-event rejection, exact delete counts, unchanged event
|
||||
selection, registrations, contacts, auth users, sponsors, connections, points,
|
||||
event feedback, leaderboard and other-event schedule rows. It also proves
|
||||
cross-event slot/dependent mismatches fail atomically instead of cascading
|
||||
foreign-event rows. This is local validation only; it does not write migration
|
||||
history or deploy anything.
|
||||
|
||||
## Files
|
||||
|
||||
- [`supabase/tests/rpc_tests.sql`](../../supabase/tests/rpc_tests.sql) — the test
|
||||
|
||||
@@ -18,7 +18,7 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
|
||||
| **Contacts** | Table of all contacts (email, name, LinkedIn, visibility toggles, `is_admin`). Edit, toggle `is_admin`, set visibility, adjust points. (No QR token here — it lives on the registration.) |
|
||||
| **Registrations** | Per active event: list (contact, type, **QR token**, checked_in, points). Change type (enforces the sponsor rule — a failed sponsor change opens an **in-place sponsor lookup** popup), mark checked-in, **view the QR token** (final — no reset). |
|
||||
| **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, **contact search-and-pick**). |
|
||||
| **Schedule** | Slots (with a **type optionset** — `Session` / `Service Session`) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
|
||||
| **Schedule** | Slots (with a **type optionset** — `Session` / `Service Session`) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button), plus an admin-only **Delete current schedule** action for the active event. |
|
||||
| **Activity** | Tables of check-ins, connections, and feedback (per active event). |
|
||||
| **Events** | Create event, toggle active/inactive (a switch; only one can be active at a time — activating one deactivates the rest), edit dates/location + the **Sessionize endpoint** + the **Real-time clock** toggle (on = the attendee app uses the real system clock for Live/Next/Done; off = the simulated mid-event clock, the default). Each row has a **Sync** button that runs a (blocking) Sessionize sync and shows a result modal. |
|
||||
| **Interfaces** | Manages the Sessionize sync **sidecar**: status (online / running / last run), a **Run sync** control (event picker + blocking run + result modal), an **Import Excel** control (upload the Sessionize "Sessions and speakers (advanced)" `.xlsx` + a "How to get this file" tooltip), and a **Recent runs** table from `sync_runs`. See [../backend/sidecar.md](../backend/sidecar.md). |
|
||||
@@ -128,7 +128,8 @@ key. Everything it can do is allowed by RLS:
|
||||
(admin-only policies).
|
||||
- **RPCs** — `adjust_points` (manual, audited as `admin`), `upsert_contact`,
|
||||
`create_registration`, `set_registration_type`, `evaluate_session_feedback`
|
||||
(AI stub), and `set_session_material` (attach uploaded material). The
|
||||
(AI stub), `set_session_material` (attach uploaded material), and
|
||||
`delete_event_schedule` (clear the active event's slots/sessions). The
|
||||
`reset_registration_qr_token` RPC still exists but the admin UI no longer
|
||||
exposes a token reset. See
|
||||
[../backend/rpcs.md](../backend/rpcs.md).
|
||||
@@ -164,6 +165,23 @@ The Schedule view uploads a session's material to the `materials` bucket and set
|
||||
`sessions.material_path` (admins can write `sessions` directly). The **Evaluate**
|
||||
button calls `evaluate_session_feedback` (the AI stub) to set
|
||||
`ai_generated_feedback`.
|
||||
|
||||
### Delete current schedule
|
||||
|
||||
The Schedule view keeps the existing active-event selection pattern: it loads
|
||||
`getActiveEvent()`, then reads slots/sessions for that event. **Delete current
|
||||
schedule** captures the active event ID/name when the confirmation modal opens
|
||||
and calls `delete_event_schedule(p_event_id)`. Success refreshes only that same
|
||||
event view and reports deleted slot/session counts; if the admin navigates away
|
||||
or changes the active event while the RPC is pending, the stale completion does
|
||||
not clear the newly selected event's UI.
|
||||
|
||||
The confirmation spells out the irreversible data loss: slots, sessions,
|
||||
speaker links, preferences, check-ins and feedback are deleted; registrations
|
||||
are preserved; material paths are removed with session rows, but Storage objects
|
||||
are not physically purged. The UI disables schedule mutation controls while the
|
||||
delete is pending. A later or concurrent Sessionize/Pretix sync can recreate
|
||||
schedule rows because the admin delete does not lock the import sidecar.
|
||||
### Reports (post-event summary + export)
|
||||
|
||||
The **Reports** view is the post-event reporting surface. It works for **any**
|
||||
|
||||
Reference in new issue
Block a user