From c783b23bae64f2b4ebab101675c8469fcf341145 Mon Sep 17 00:00:00 2001 From: Jamil Date: Sat, 21 Jun 2025 14:17:33 -0700 Subject: [PATCH] refactor(portal): rename conditional->manual (#9612) These only have one condition - to run manually. `manual migrations` better implies that these migrations _must_ typically be run manually. --- .../domain/lib/domain/config/definitions.ex | 4 +-- elixir/apps/domain/lib/domain/release.ex | 36 +++++++++---------- .../.gitkeep | 0 ...617175017_drop_telemetry_reporter_logs.exs | 0 elixir/config/config.exs | 4 +-- elixir/config/dev.exs | 2 +- elixir/config/runtime.exs | 2 +- elixir/config/test.exs | 2 +- elixir/mix.exs | 2 +- 9 files changed, 26 insertions(+), 26 deletions(-) rename elixir/apps/domain/priv/repo/{conditional_migrations => manual_migrations}/.gitkeep (100%) rename elixir/apps/domain/priv/repo/{conditional_migrations => manual_migrations}/20250617175017_drop_telemetry_reporter_logs.exs (100%) diff --git a/elixir/apps/domain/lib/domain/config/definitions.ex b/elixir/apps/domain/lib/domain/config/definitions.ex index 9f992ea73..2b32b4f15 100644 --- a/elixir/apps/domain/lib/domain/config/definitions.ex +++ b/elixir/apps/domain/lib/domain/config/definitions.ex @@ -263,10 +263,10 @@ defmodule Domain.Config.Definitions do ############################################## @doc """ - Whether to run migrations in the priv/repo/conditional_migrations directory. + Whether to run migrations in the priv/repo/manual_migrations directory. If set to false, these migrations must be manually run from an IEx shell. """ - defconfig(:run_conditional_migrations, :boolean, default: false) + defconfig(:run_manual_migrations, :boolean, default: false) @doc """ PostgreSQL host. diff --git a/elixir/apps/domain/lib/domain/release.ex b/elixir/apps/domain/lib/domain/release.ex index bdc5d6e56..1afc77911 100644 --- a/elixir/apps/domain/lib/domain/release.ex +++ b/elixir/apps/domain/lib/domain/release.ex @@ -8,19 +8,19 @@ defmodule Domain.Release do IO.puts("Starting sentry app..") {:ok, _} = Application.ensure_all_started(:sentry) - conditional = + manual = Keyword.get( opts, - :conditional, + :manual, Application.get_env( :domain, - :run_conditional_migrations, - System.get_env("RUN_CONDITIONAL_MIGRATIONS") == "true" + :run_manual_migrations, + System.get_env("RUN_MANUAL_MIGRATIONS") == "true" ) ) for repo <- @repos do - {:ok, _, _} = do_migration(repo, conditional) + {:ok, _, _} = do_migration(repo, manual) end end @@ -51,15 +51,15 @@ defmodule Domain.Release do end end - defp do_migration(repo, conditional) do + defp do_migration(repo, manual) do default_path = priv_dir(@otp_app, ["repo", "migrations"]) - conditional_path = priv_dir(@otp_app, ["repo", "conditional_migrations"]) + manual_path = priv_dir(@otp_app, ["repo", "manual_migrations"]) paths = - if conditional do + if manual do [ default_path, - conditional_path + manual_path ] else [ @@ -70,18 +70,18 @@ defmodule Domain.Release do Ecto.Migrator.with_repo(repo, fn repo -> Ecto.Migrator.run(repo, paths, :up, all: true) - unless conditional do - check_pending_conditional_migrations(@otp_app, repo) + unless manual do + check_pending_manual_migrations(@otp_app, repo) end end) end - defp check_pending_conditional_migrations(app, repo) do - conditional_path = priv_dir(app, ["repo", "conditional_migrations"]) + defp check_pending_manual_migrations(app, repo) do + manual_path = priv_dir(app, ["repo", "manual_migrations"]) - if File.dir?(conditional_path) do - # Get all migrations from the conditional directory - case Ecto.Migrator.migrations(repo, conditional_path) do + if File.dir?(manual_path) do + # Get all migrations from the manual directory + case Ecto.Migrator.migrations(repo, manual_path) do [] -> :ok @@ -97,10 +97,10 @@ defmodule Domain.Release do defp maybe_log_error(pending) do error = """ - #{pending} pending conditional migration(s) were not run because run_conditional_migrations is false. + #{pending} pending manual migration(s) were not run because run_manual_migrations is false. Run the following command from an IEx shell when you're ready to execute them: - Domain.Release.migrate(conditional: true) + Domain.Release.migrate(manual: true) """ Logger.error(error) diff --git a/elixir/apps/domain/priv/repo/conditional_migrations/.gitkeep b/elixir/apps/domain/priv/repo/manual_migrations/.gitkeep similarity index 100% rename from elixir/apps/domain/priv/repo/conditional_migrations/.gitkeep rename to elixir/apps/domain/priv/repo/manual_migrations/.gitkeep diff --git a/elixir/apps/domain/priv/repo/conditional_migrations/20250617175017_drop_telemetry_reporter_logs.exs b/elixir/apps/domain/priv/repo/manual_migrations/20250617175017_drop_telemetry_reporter_logs.exs similarity index 100% rename from elixir/apps/domain/priv/repo/conditional_migrations/20250617175017_drop_telemetry_reporter_logs.exs rename to elixir/apps/domain/priv/repo/manual_migrations/20250617175017_drop_telemetry_reporter_logs.exs diff --git a/elixir/config/config.exs b/elixir/config/config.exs index a19cb1e6c..366f4fb04 100644 --- a/elixir/config/config.exs +++ b/elixir/config/config.exs @@ -17,8 +17,8 @@ config :domain, generators: [binary_id: true, context_app: :domain] config :domain, sql_sandbox: false -# Don't run conditional migrations by default -config :domain, run_conditional_migrations: false +# Don't run manual migrations by default +config :domain, run_manual_migrations: false config :domain, Domain.Repo, hostname: "localhost", diff --git a/elixir/config/dev.exs b/elixir/config/dev.exs index 4f2ba4d7a..2639f6dc5 100644 --- a/elixir/config/dev.exs +++ b/elixir/config/dev.exs @@ -13,7 +13,7 @@ config :domain, Domain.Repo, config :domain, outbound_email_adapter_configured?: true -config :domain, run_conditional_migrations: true +config :domain, run_manual_migrations: true config :domain, Domain.Billing, enabled: System.get_env("BILLING_ENABLED", "false") == "true", diff --git a/elixir/config/runtime.exs b/elixir/config/runtime.exs index 0633c12ed..96c6a13ac 100644 --- a/elixir/config/runtime.exs +++ b/elixir/config/runtime.exs @@ -42,7 +42,7 @@ if config_env() == :prod do database: env_var_to_config!(:database_name) ] - config :domain, run_conditional_migrations: env_var_to_config!(:run_conditional_migrations) + config :domain, run_manual_migrations: env_var_to_config!(:run_manual_migrations) config :domain, Domain.Tokens, key_base: env_var_to_config!(:tokens_key_base), diff --git a/elixir/config/test.exs b/elixir/config/test.exs index 0877c706c..4b7481cc2 100644 --- a/elixir/config/test.exs +++ b/elixir/config/test.exs @@ -13,7 +13,7 @@ partition_suffix = config :domain, sql_sandbox: true -config :domain, run_conditional_migrations: true +config :domain, run_manual_migrations: true config :domain, Domain.Repo, database: "firezone_test#{partition_suffix}", diff --git a/elixir/mix.exs b/elixir/mix.exs index 48b848ca3..a2edef297 100644 --- a/elixir/mix.exs +++ b/elixir/mix.exs @@ -56,7 +56,7 @@ defmodule Firezone.MixProject do defp aliases do migration_args = - "--migrations-path apps/domain/priv/repo/migrations --migrations-path apps/domain/priv/repo/conditional_migrations" + "--migrations-path apps/domain/priv/repo/migrations --migrations-path apps/domain/priv/repo/manual_migrations" [ "ecto.migrate": ["ecto.migrate #{migration_args}"],