Run seeds only once #475

Merged
simon merged 6 commits from bugfix/rund-seeds-just-once into main 2026-03-16 19:27:33 +01:00
Owner

Description of the implemented changes

The changes were:

  • Bugfixing
  • New Feature
  • Breaking Change
  • 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

  • No new technical depths
  • Linting passed
  • Documentation is added where needed

Accessibility

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

Testing

  • Tests for new code are written (existing seeds and release tests cover behaviour; idempotency test still passes when second run skips)
  • All tests pass
  • 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.
## 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.
simon added 4 commits 2026-03-16 17:56:13 +01:00
feat: improve oidc only mode
Some checks failed
continuous-integration/drone/push Build is failing
a8d9fe6121
feat: improve oidc only mode
Some checks failed
continuous-integration/drone/push Build is failing
9b4f3b140c
style: fix formatting
All checks were successful
continuous-integration/drone/push Build is passing
a049ccb8e3
feat: only run all seeds on first startup
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing
c40f3135a1
simon added this to the Sprint 14: 26.02 - 05.03 project 2026-03-16 17:56:18 +01:00
simon changed target branch from main to feature/improve_oidc_only 2026-03-16 18:02:12 +01:00
simon changed target branch from feature/improve_oidc_only to main 2026-03-16 19:09:11 +01:00
simon added 1 commit 2026-03-16 19:20:43 +01:00
refactor: harden seed only once implementation
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/promote/production Build is passing
77012f10ca
simon added 1 commit 2026-03-16 19:27:00 +01:00
Merge origin/main into bugfix/rund-seeds-just-once
All checks were successful
continuous-integration/drone/push Build is passing
28c40ec2a9
Resolved conflicts:
- CHANGELOG.md: keep FORCE_SEEDS and Seeds entries, keep OIDC/Unauthenticated from main
- auth_controller.ex: use sign_in_path_after_oidc_failure() for OIDC-only redirect
- oidc_only_sign_in_redirect.ex: take main's oidc_failed=1 handling
- gettext default.po: remove obsolete #~ block
- auth_controller_test.exs: keep test for oidc_failed=1 redirect loop

Made-with: Cursor
simon merged commit f8a3cc4c47 into main 2026-03-16 19:27:33 +01:00
simon deleted branch bugfix/rund-seeds-just-once 2026-03-16 19:27:33 +01:00
simon referenced this pull request from a commit 2026-03-16 19:27:34 +01:00
Sign in to join this conversation.
No description provided.