From c8702193572a77bfe7a301d6df7e1593c8a33020 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 27 Jun 2024 09:21:45 +0200 Subject: [PATCH] wip --- config/dev.exs | 2 +- config/runtime.exs | 19 ------------------- lib/asciinema/application.ex | 5 ++++- lib/asciinema/repo.ex | 20 ++++++++++++++++++++ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/config/dev.exs b/config/dev.exs index 7a1c56d9c..4bd349c58 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -8,7 +8,7 @@ config :asciinema, Asciinema.Repo, database: "asciinema_development", stacktrace: true, show_sensitive_data_on_connection_error: true, - pool_size: 10 + pool_size: 11 secret_key_base = "60BnXnzGGwwiZj91YA9XYKF9BCiM7lQ/1um8VXcWWLSdUp9OcPZV6YnQv7eFTYSY" diff --git a/config/runtime.exs b/config/runtime.exs index ce857abf6..0a342289f 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -8,17 +8,6 @@ import Config env = &System.get_env/1 -if config_env() == :prod do - database_url = - System.get_env("DATABASE_URL") || - raise """ - environment variable DATABASE_URL is missing. - For example: ecto://USER:PASS@HOST/DATABASE - """ - - config :asciinema, Asciinema.Repo, url: database_url -end - if config_env() in [:prod, :dev] do if secret_key_base = env.("SECRET_KEY_BASE") do config :asciinema, Asciinema.Accounts, secret: secret_key_base @@ -74,14 +63,6 @@ if config_env() in [:prod, :dev] do end end - if db_pool_size = env.("DB_POOL_SIZE") do - config :asciinema, Asciinema.Repo, pool_size: String.to_integer(db_pool_size) - end - - if env.("ECTO_IPV6") in ~w(true 1) do - config :asciinema, Asciinema.Repo, socket_options: [:inet6] - end - if smtp_host = env.("SMTP_HOST") do config :asciinema, Asciinema.Emails.Mailer, adapter: Swoosh.Adapters.SMTP, diff --git a/lib/asciinema/application.ex b/lib/asciinema/application.ex index 37a6004de..4dd93d1ec 100644 --- a/lib/asciinema/application.ex +++ b/lib/asciinema/application.ex @@ -9,6 +9,9 @@ defmodule Asciinema.Application do def start(_type, _args) do :ok = Oban.Telemetry.attach_default_logger() :ok = Asciinema.ObanErrorReporter.configure() + # rr = take_app_env(Asciinema.Repo) + rr = Application.fetch_env!(:asciinema, Asciinema.Repo) + IO.inspect(rr, label: "rr") # List all child processes to be supervised children = [ @@ -23,7 +26,7 @@ defmodule Asciinema.Application do # Start telemetry reporters Asciinema.Telemetry, # Start the Ecto repository - Asciinema.Repo, + {Asciinema.Repo, rr}, # Start PNG generator poolboy pool :poolboy.child_spec(:worker, Asciinema.PngGenerator.Rsvg.poolboy_config(), []), # Start Oban diff --git a/lib/asciinema/repo.ex b/lib/asciinema/repo.ex index c1bc9b35d..594778969 100644 --- a/lib/asciinema/repo.ex +++ b/lib/asciinema/repo.ex @@ -5,6 +5,26 @@ defmodule Asciinema.Repo do use Scrivener, page_size: 10 + def init(_type, config) do + config = Keyword.put(config, :url, System.get_env("DATABASE_URL")) + + config = + if pool_size = System.get_env("DB_POOL_SIZE") do + Keyword.put(config, :pool_size, String.to_integer(pool_size)) + else + config + end + + config = + if System.get_env("ECTO_IPV6") in ~w(true 1) do + Keyword.put(config, :socket_options, [:inet6]) + else + config + end + + {:ok, config} + end + def transact(fun, opts \\ []) do transaction( fn ->