|
| 1 | +--- |
| 2 | +name: generate-dev-db-events |
| 3 | +description: >- |
| 4 | + Seeds or refreshes Campus Life Events PostgreSQL demo data via Docker Compose |
| 5 | + Postgres. Generates bilingual (DE/EN) events with realistic timestamps, about |
| 6 | + three to four events per calendar week, using existing organizers. Use when |
| 7 | + the user asks for dev/demo events, seed data, filling the local database, |
| 8 | + refreshing outdated demo events, or bulk INSERTs for events in backend/docker-compose. |
| 9 | +--- |
| 10 | + |
| 11 | +# Generate dev database events |
| 12 | + |
| 13 | +## Preconditions |
| 14 | + |
| 15 | +- Postgres container from `backend/docker-compose.yml` is running (`cle-postgres`). |
| 16 | +- Inserts target the **`events`** table; **`organizer_id`** must reference an existing `organizers.id`. |
| 17 | + |
| 18 | +## Connection (local Compose) |
| 19 | + |
| 20 | +From `backend/docker-compose.yml`: |
| 21 | + |
| 22 | +| Setting | Value | |
| 23 | +|--------|--------| |
| 24 | +| Host (from machine) | `localhost` | |
| 25 | +| Port | **5422** | |
| 26 | +| User | `cle` | |
| 27 | +| Password | `cle_password` | |
| 28 | +| Database | `cle_db` | |
| 29 | +| Container name | `cle-postgres` | |
| 30 | + |
| 31 | +Shell: |
| 32 | + |
| 33 | +```bash |
| 34 | +docker exec -i cle-postgres psql -U cle -d cle_db -v ON_ERROR_STOP=1 |
| 35 | +``` |
| 36 | + |
| 37 | +**Important:** use `docker exec **-i**` when piping SQL or a heredoc into `psql`. Without `-i`, stdin is ignored and nothing runs. |
| 38 | + |
| 39 | +Host `psql` (if installed): |
| 40 | + |
| 41 | +```bash |
| 42 | +psql "postgres://cle:cle_password@localhost:5422/cle_db" |
| 43 | +``` |
| 44 | + |
| 45 | +## `events` row shape |
| 46 | + |
| 47 | +Required / typical columns: |
| 48 | + |
| 49 | +- `organizer_id` (BIGINT, FK to `organizers`) |
| 50 | +- `title_de`, `title_en` (NOT NULL) |
| 51 | +- `description_de`, `description_en` (optional) |
| 52 | +- `start_date_time`, `end_date_time` (**both NOT NULL**; `end_date_time` must be after start) |
| 53 | +- `event_url`, `location` (optional) |
| 54 | +- `publish_app`, `publish_newsletter`, `publish_in_ical`, `publish_web` (BOOLEAN; default demo pattern: all `TRUE`) |
| 55 | + |
| 56 | +Use `TIMESTAMPTZ` strings with explicit offset, e.g. `2026-05-14T17:00:00+02` for Europe/Berlin summer time. |
| 57 | + |
| 58 | +## Cadence |
| 59 | + |
| 60 | +- Aim for **3–4 events per week** over the requested date range (e.g. one semester window). |
| 61 | +- Spread weekdays (e.g. Tue, Wed, Thu, Sat) to avoid unrealistic stacking unless the user asks otherwise. |
| 62 | +- Rotate **`organizer_id`** across existing organizers (query `SELECT id, name FROM organizers ORDER BY id` first). |
| 63 | + |
| 64 | +## Workflow |
| 65 | + |
| 66 | +1. List organizers: `SELECT id, name FROM organizers ORDER BY id;` |
| 67 | +2. Optionally clear old demo rows in the target window: `DELETE FROM events WHERE ...` (check `audit_log` for `event_id` if constraints exist). |
| 68 | +3. Generate `INSERT INTO events (...) VALUES (...), (...);` in batches. |
| 69 | +4. Apply with `docker exec -i cle-postgres psql -U cle -d cle_db -v ON_ERROR_STOP=1 <<'SQL' ... SQL` |
| 70 | +5. Verify density: |
| 71 | + |
| 72 | +```sql |
| 73 | +SELECT date_trunc('week', start_date_time)::date AS week_start, COUNT(*) AS n |
| 74 | +FROM events |
| 75 | +WHERE start_date_time >= 'YYYY-MM-DD' AND start_date_time < 'YYYY-MM-DD' |
| 76 | +GROUP BY 1 ORDER BY 1; |
| 77 | +``` |
| 78 | + |
| 79 | +## Generation pattern (recommended) |
| 80 | + |
| 81 | +Use a short script (e.g. Python) to emit SQL: cycle organizer ids and event templates, fix `end` after `start`, escape single quotes in text as `''`, and print one multi-row `INSERT`. |
| 82 | + |
| 83 | +## Content guidelines |
| 84 | + |
| 85 | +- Bilingual **German / English** titles and descriptions matching campus-life tone. |
| 86 | +- Varied categories: sports, culture, tech workshops, sustainability, music, debate, international office, etc. |
| 87 | +- Prefer **plausible** locations and optional `https://example.edu/...` URLs for demos. |
| 88 | + |
| 89 | +## Optional cleanup |
| 90 | + |
| 91 | +If the user wants only the new cohort in a window, delete superseded rows by id or by `start_date_time` range after confirming no important FKs (e.g. `audit_log.event_id`). |
0 commit comments