Skip to content

Commit

Permalink
Support migration options in Nerves.Release.Tasks.migrate/1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jjcarstens authored and oestrich committed Aug 14, 2024
1 parent a09e087 commit e61a1f1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/nerves_hub/release/tasks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e61a1f1

Please sign in to comment.