Run seeds only once #475
No reviewers
Labels
No labels
bug
duplicate
enhancement
help wanted
high priority
invalid
L
low priority
M
medium priority
needs refinement
optional
question
S
UX research
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: local-it/mitgliederverwaltung#475
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "bugfix/rund-seeds-just-once"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description of the implemented changes
The changes were:
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.exbootstrap_seeds_applied?/0: returns whether the admin user (fromADMIN_EMAILor defaultadmin@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: ifbootstrap_seeds_applied?()is true, prints “Seeds already applied (admin user exists). Skipping.” and returns without running bootstrap or dev seeds; otherwise unchanged behaviour.priv/repo/seeds.exsApplication.ensure_all_started(:mv)).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).Documentation
CODE_GUIDELINES.md§1.2.1: seeds run on every start but exit early when already applied; mentionsbootstrap_seeds_applied?/0.docs/admin-bootstrap-and-oidc-role-sync.md: run_seeds skips when admin user exists; description ofrun_seeds/0updated.CHANGELOG.md[Unreleased]: new “Seeds run only when needed” entry under Changed.Definition of Done
Code Quality
Accessibility
Testing
Additional Notes
Mv.Releaseandpriv/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?/0returnsfalse, so seeds run (safe for first deploy).mix test test/seeds_test.exs test/mv/release_test.exsto confirm seeds and release behaviour.