Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly put :ssl and :ssl_opts for the Ecto Repo #4442

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions config/runtime.exs
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import Config

if config_env() == :dev do
{ssl, ssl_opts} =
if System.get_env("DATABASE_URL") do
{true, [verify: :verify_none]}
else
{false, []}
end

config :sanbase, Sanbase.Repo,
ssl: ssl,
ssl_opts: ssl_opts
end

if config_env() in [:dev, :test] do
# In order to properly work while developing locally,
# load the .env file before doing the configuration
Expand Down
11 changes: 11 additions & 0 deletions lib/sanbase/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ defmodule Sanbase.Repo do
|> Keyword.put(:pool_size, pool_size)
|> Keyword.put(:url, System.get_env("DATABASE_URL"))

test_env? = Application.get_env(:sanbase, :env) == :test

opts =
if is_nil(System.get_env("DATABASE_URL")) or test_env? do
opts
else
opts
|> Keyword.put(:ssl, true)
|> Keyword.put(:ssl_opts, verify: :verify_none)
end

{:ok, opts}
end
end