Skip to content

Commit a7af29a

Browse files
fix: avoid duplicate org error in seeds and default PHX_HOST to localhost
Check if the default org exists before inserting to prevent noisy Postgres constraint violation errors on restarts. Change PHX_HOST fallback from "example.com" to "localhost" for Docker Compose.
1 parent 5592651 commit a7af29a

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

config/runtime.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ if config_env() == :prod do
8686
You can generate one by calling: mix phx.gen.secret
8787
"""
8888

89-
host = System.get_env("PHX_HOST") || "example.com"
89+
host = System.get_env("PHX_HOST") || "localhost"
9090

9191
config :zentinel_cp, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
9292

priv/repo/seeds.exs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ end
3030
admin = ZentinelCp.Accounts.get_user_by_email("admin@localhost")
3131

3232
if admin do
33-
case ZentinelCp.Orgs.create_org_with_owner(%{name: "Default"}, admin) do
34-
{:ok, org} ->
35-
IO.puts("Created org: #{org.name} (slug: #{org.slug})")
36-
37-
{:error, %{errors: [slug: {"has already been taken", _}]}} ->
33+
case ZentinelCp.Orgs.get_org_by_slug("default") do
34+
%{} ->
3835
IO.puts("Default org already exists")
3936

40-
{:error, reason} ->
41-
IO.inspect(reason, label: "Failed to create org")
37+
nil ->
38+
case ZentinelCp.Orgs.create_org_with_owner(%{name: "Default"}, admin) do
39+
{:ok, org} ->
40+
IO.puts("Created org: #{org.name} (slug: #{org.slug})")
41+
42+
{:error, reason} ->
43+
IO.inspect(reason, label: "Failed to create org")
44+
end
4245
end
4346
end

0 commit comments

Comments
 (0)