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

This commit is contained in:
Simon 2026-03-16 17:52:59 +01:00
parent a049ccb8e3
commit c40f3135a1
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
5 changed files with 70 additions and 36 deletions

View file

@ -3,7 +3,8 @@
# mix run priv/repo/seeds.exs
#
# Bootstrap runs in all environments. Dev seeds (members, groups, sample data)
# run only in dev and test.
# run only in dev and test. Skips entirely if bootstrap was already applied
# (Admin role exists), so safe to run on every start.
#
# In production (release): seeds are run via Mv.Release.run_seeds/0 from the
# container entrypoint. Set RUN_DEV_SEEDS=true to also run dev seeds there.
@ -12,19 +13,25 @@
# so that eval_file of bootstrap/dev does not emit "redefining module" warnings;
# it is always restored in `after` to avoid hiding real conflicts elsewhere.
prev = Code.compiler_options()
Code.compiler_options(ignore_module_conflict: true)
_ = Application.ensure_all_started(:mv)
try do
# Always run bootstrap (fee types, custom fields, roles, admin, system user, settings)
Code.eval_file("priv/repo/seeds_bootstrap.exs")
if Mv.Release.bootstrap_seeds_applied?() do
IO.puts("Seeds already applied (admin user exists). Skipping.")
else
prev = Code.compiler_options()
Code.compiler_options(ignore_module_conflict: true)
# In dev and test only: run dev seeds (20 members, groups, custom field values)
if Mix.env() in [:dev, :test] do
Code.eval_file("priv/repo/seeds_dev.exs")
try do
# Always run bootstrap (fee types, custom fields, roles, admin, system user, settings)
Code.eval_file("priv/repo/seeds_bootstrap.exs")
# In dev and test only: run dev seeds (20 members, groups, custom field values)
if Mix.env() in [:dev, :test] do
Code.eval_file("priv/repo/seeds_dev.exs")
end
IO.puts("✅ All seeds completed.")
after
Code.compiler_options(prev)
end
IO.puts("✅ All seeds completed.")
after
Code.compiler_options(prev)
end