mitgliederverwaltung/lib/mv
Simon f8a3cc4c47
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing
continuous-integration/drone/tag Build is passing
Run seeds only once (#475)
## Description of the implemented changes
The changes were:
- [ ] Bugfixing
- [x] New Feature
- [ ] Breaking Change
- [x] Refactoring

**Seeds run only on first startup.** On every application start (e.g. `just run`, Docker entrypoint), seed scripts are still invoked, but they exit immediately when the admin user already exists. This avoids duplicate seed data (e.g. join requests), keeps startup fast after the first run, and works the same in dev and production.

## What has been changed?

- **`lib/mv/release.ex`**
  - Added `bootstrap_seeds_applied?/0`: returns whether the admin user (from `ADMIN_EMAIL` or default `admin@localhost`) exists. We check the admin *user*, not the Admin *role*, so we do not skip when only migrations have run (migrations can create the Admin role for the system actor).
  - `run_seeds/0`: if `bootstrap_seeds_applied?()` is true, prints “Seeds already applied (admin user exists). Skipping.” and returns without running bootstrap or dev seeds; otherwise unchanged behaviour.
  - Module docs updated for the new function and the skip behaviour.

- **`priv/repo/seeds.exs`**
  - Ensures the app is started (`Application.ensure_all_started(:mv)`).
  - If `Mv.Release.bootstrap_seeds_applied?()` is true, prints the same skip message and does not run bootstrap or dev seeds; otherwise runs as before (bootstrap + dev seeds in dev/test).
  - Comment at the top updated to describe the skip behaviour.

- **Documentation**
  - `CODE_GUIDELINES.md` §1.2.1: seeds run on every start but exit early when already applied; mentions `bootstrap_seeds_applied?/0`.
  - `docs/admin-bootstrap-and-oidc-role-sync.md`: run_seeds skips when admin user exists; description of `run_seeds/0` updated.
  - `CHANGELOG.md` [Unreleased]: new “Seeds run only when needed” entry under Changed.

## Definition of Done
### Code Quality
- [x] No new technical depths
- [x] Linting passed
- [x] Documentation is added where needed

### Accessibility
- [x] New elements are properly defined with html-tags *(no new UI)*
- [x] Colour contrast follows WCAG criteria *(no new UI)*
- [x] Aria labels are added when needed *(no new UI)*
- [x] Everything is accessible by keyboard *(no new UI)*
- [x] Tab-Order is comprehensible *(no new UI)*
- [x] All interactive elements have a visible focus *(no new UI)*

### Testing
- [x] Tests for new code are written *(existing seeds and release tests cover behaviour; idempotency test still passes when second run skips)*
- [x] All tests pass
- [x] axe-core dev tools show no critical or major issues *(no UI changes)*

## Additional Notes

- **Review focus:** Logic in `Mv.Release` and `priv/repo/seeds.exs`; the “already applied” check is a single DB read for the admin user. On failure (e.g. DB down), `bootstrap_seeds_applied?/0` returns `false`, so seeds run (safe for first deploy).
- **Suggested check:** Run `mix test test/seeds_test.exs test/mv/release_test.exs` to confirm seeds and release behaviour.

Reviewed-on: #475
Co-authored-by: Simon <s.thiessen@local-it.org>
Co-committed-by: Simon <s.thiessen@local-it.org>
2026-03-16 19:27:31 +01:00
..
accounts/user feat: add smtp settings 2026-03-12 13:39:48 +01:00
authorization Improve oidc only mode (#474) 2026-03-16 19:09:07 +01:00
email_sync refactor: reduce nesting in SyncUserEmailToMember.sync_email 2026-02-04 13:03:36 +01:00
helpers feat(system_actor): add system_user?/1 and normalize email 2026-01-27 17:39:04 +01:00
membership CSV export: robust apply_export_filters, single custom_field_ids_union, string boolean_filters, more tests 2026-03-04 21:15:54 +01:00
membership_fees Member/CycleGenerator: better delete_cycles errors; UUID-based advisory lock 2026-03-04 17:11:56 +01:00
smtp refactor: unify smtp config logic 2026-03-16 14:23:46 +01:00
vereinfacht fix: resolve Mix.env at compile time in Vereinfacht client 2026-03-10 20:17:26 +01:00
application.ex refactor: review remarks 2026-03-13 17:55:17 +01:00
config.ex refactor: adress review 2026-03-12 15:29:54 +01:00
constants.ex Add filter prefix constants and shared FilterParams module 2026-03-09 14:33:58 +01:00
helpers.ex Member/Setting/validations: domain, actor, and seeds 2026-02-03 23:52:16 +01:00
mailer.ex refactor: unify smtp config logic 2026-03-16 14:23:46 +01:00
oidc_role_sync.ex Fix Credo Readability (strict) 2026-03-04 16:21:14 +01:00
oidc_role_sync_config.ex feat: OIDC configuration in global Settings (ENV or DB) 2026-02-24 13:58:24 +01:00
release.ex Run seeds only once (#475) 2026-03-16 19:27:31 +01:00
repo.ex chore: enable trigram extension 2025-10-30 16:48:45 +01:00
secrets.ex Secrets: return MissingSecret when OIDC values nil to avoid crashes 2026-02-24 15:12:58 +01:00
statistics.ex Statistics: log Ash errors instead of returning 0/nil silently 2026-02-12 19:35:48 +01:00