Adds a Spring @Scheduled job (daily at 03:00) that deletes all events whose expiry_date is before CURRENT_DATE using a native SQL DELETE. RSVPs are cascade-deleted via the existing FK constraint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1.2 KiB
1.2 KiB
Data Model: Auto-Delete Expired Events
Feature: 013-auto-delete-expired | Date: 2026-03-09
Existing Entities (no changes)
Event
| Field | Type | Notes |
|---|---|---|
| id | BIGSERIAL | PK, internal |
| event_token | UUID | Public identifier |
| organizer_token | UUID | Organizer access |
| title | VARCHAR(200) | Required |
| description | VARCHAR(2000) | Optional |
| date_time | TIMESTAMPTZ | Event date/time |
| location | VARCHAR(500) | Optional |
| expiry_date | DATE | Deletion trigger — indexed (idx_events_expiry_date) |
| created_at | TIMESTAMPTZ | Auto-set |
RSVP
| Field | Type | Notes |
|---|---|---|
| id | BIGSERIAL | PK, internal |
| rsvp_token | UUID | Public identifier |
| event_id | BIGINT | FK → events(id), ON DELETE CASCADE |
| name | VARCHAR(100) | Guest name |
Deletion Behavior
DELETE FROM events WHERE expiry_date < CURRENT_DATEremoves expired events.- RSVPs are automatically cascade-deleted by the FK constraint
fk_rsvps_event_idwithON DELETE CASCADE. - No new tables, columns, or migrations required.
Indexes Used
idx_events_expiry_dateonevents(expiry_date)— ensures the cleanup query is efficient.