diff --git a/elixir/apps/domain/lib/domain/release.ex b/elixir/apps/domain/lib/domain/release.ex index 3ad06babe..bdc5d6e56 100644 --- a/elixir/apps/domain/lib/domain/release.ex +++ b/elixir/apps/domain/lib/domain/release.ex @@ -5,11 +5,18 @@ defmodule Domain.Release do @repos Application.compile_env!(@otp_app, :ecto_repos) def migrate(opts \\ []) do + IO.puts("Starting sentry app..") + {:ok, _} = Application.ensure_all_started(:sentry) + conditional = Keyword.get( opts, :conditional, - Application.get_env(:domain, :run_conditional_migrations, false) + Application.get_env( + :domain, + :run_conditional_migrations, + System.get_env("RUN_CONDITIONAL_MIGRATIONS") == "true" + ) ) for repo <- @repos do @@ -63,7 +70,7 @@ defmodule Domain.Release do Ecto.Migrator.with_repo(repo, fn repo -> Ecto.Migrator.run(repo, paths, :up, all: true) - if conditional do + unless conditional do check_pending_conditional_migrations(@otp_app, repo) end end) @@ -80,17 +87,30 @@ defmodule Domain.Release do migrations -> # Count pending migrations (status = :down) - pending = Enum.count(migrations, fn {status, _, _} -> status == :down end) - - if pending > 0 do - Logger.warning(""" - #{pending} pending conditional migration(s) were not run because run_conditional_migrations is false. - Run the following command from an IEx shell when you're ready to execute them: - - Domain.Release.migrate(conditional: true) - """) - end + Enum.count(migrations, fn {status, _, _} -> status == :down end) + |> maybe_log_error() end end end + + defp maybe_log_error(0), do: nil + + defp maybe_log_error(pending) do + error = """ + #{pending} pending conditional migration(s) were not run because run_conditional_migrations is false. + Run the following command from an IEx shell when you're ready to execute them: + + Domain.Release.migrate(conditional: true) + """ + + Logger.error(error) + + # Sentry logger handler may not be fully initialized, so manually send + # a message and wait for it to send. + Task.start(fn -> + Sentry.capture_message(error) + end) + + Process.sleep(1_000) + end end