From e61a1f1ef467eb1ac766bf17bb1814f45917817b Mon Sep 17 00:00:00 2001 From: Jon Carstens Date: Tue, 6 Aug 2024 17:00:03 -0600 Subject: [PATCH] Support migration options in `Nerves.Release.Tasks.migrate/1` This allows others using NervesHub to step through migrations more manually if needed, such as situations where a column is removed and one might need to apply the migrations manually in 2 steps or at a later date without blocking the ability to deploy other non-related changes --- lib/nerves_hub/release/tasks.ex | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/nerves_hub/release/tasks.ex b/lib/nerves_hub/release/tasks.ex index ca4832335..932be851f 100644 --- a/lib/nerves_hub/release/tasks.ex +++ b/lib/nerves_hub/release/tasks.ex @@ -7,14 +7,25 @@ defmodule NervesHub.Release.Tasks do start_apps_before_migration: [:logger, :ssl, :postgrex, :ecto_sql] ] - def migrate() do + @doc """ + Run the Ecto.Migrator for each defined repo + + You can optionally pass options supported Ecto.Migrator.run/3 for each + repo in order to control the migration a bit more, like for specifying + a migration to stop at: + + migrate([{NervesHub.Repo, [to: 20240806112233]}]) + """ + @spec migrate([{Ecto.Repo.t(), keyword()}]) :: [{:ok, [integer()], [atom()]} | {:error, term()}] + def migrate(opts \\ []) do for repo <- Application.fetch_env!(@app, :ecto_repos) do - {:ok, _, _} = Migrator.with_repo(repo, &Migrator.run(&1, :up, all: true), @migrate_opts) + run_opts = opts[repo] || [all: true] + {:ok, _, _} = Migrator.with_repo(repo, &Migrator.run(&1, :up, run_opts), @migrate_opts) end end - def migrate_and_seed() do - _ = migrate() + def migrate_and_seed(opts \\ []) do + _ = migrate(opts) seed() end