Skip to content

Commit

Permalink
Use Ecto.gen_migration/3 to add oban migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sorentwo committed Dec 26, 2024
1 parent a086e8a commit 08f4525
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/mix/tasks/oban.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,33 @@ if Code.ensure_loaded?(Igniter) do
test_code = [testing: :manual]
tree_code = "Application.fetch_env!(#{app_name}, Oban)"

migration = """
use Ecto.Migration
def up, do: Oban.Migration.up(version: 12)
def down, do: Oban.Migration.down(version: 1)
"""

igniter
|> ensure_repo_exists(repo)
|> Igniter.Project.Deps.add_dep({:oban, "~> 2.18"})

Check warning on line 79 in lib/mix/tasks/oban.install.ex

View workflow job for this annotation

GitHub Actions / ci (1.18, 27.2, 9.1, 17.2-alpine, gossip, lint)

Nested modules could be aliased at the top of the invoking module.
|> Igniter.Project.Config.configure("config.exs", app_name, [Oban], {:code, conf_code})

Check warning on line 80 in lib/mix/tasks/oban.install.ex

View workflow job for this annotation

GitHub Actions / ci (1.18, 27.2, 9.1, 17.2-alpine, gossip, lint)

Nested modules could be aliased at the top of the invoking module.
|> Igniter.Project.Config.configure("test.exs", app_name, [Oban], {:code, test_code})

Check warning on line 81 in lib/mix/tasks/oban.install.ex

View workflow job for this annotation

GitHub Actions / ci (1.18, 27.2, 9.1, 17.2-alpine, gossip, lint)

Nested modules could be aliased at the top of the invoking module.
|> Igniter.Project.Application.add_new_child({Oban, {:code, tree_code}}, after: repo)
|> Igniter.Project.Formatter.import_dep(:oban)

Check warning on line 83 in lib/mix/tasks/oban.install.ex

View workflow job for this annotation

GitHub Actions / ci (1.18, 27.2, 9.1, 17.2-alpine, gossip, lint)

Nested modules could be aliased at the top of the invoking module.
|> Igniter.Libs.Ecto.gen_migration(repo, "add_oban", body: migration)

Check warning on line 84 in lib/mix/tasks/oban.install.ex

View workflow job for this annotation

GitHub Actions / ci (1.18, 27.2, 9.1, 17.2-alpine, gossip, lint)

Nested modules could be aliased at the top of the invoking module.
end

defp ensure_repo_exists(igniter, repo) do
case Igniter.Project.Module.module_exists(repo) do
case Igniter.Project.Module.module_exists(igniter, repo) do
{true, igniter} ->
igniter

{_boo, igniter} ->
Igniter.add_issue(igniter, "The provided repo (#{inspect(repo)}) doesn't exist")
end
end

defp repo_priv(app_name, repo) do
path =
repo.config()
|> Keyword.get(:priv, repo |> Module.split() |> List.last() |> Macro.underscore())
|> String.trim_leading("priv/")

app_name
|> :code.priv_dir()
|> Path.join(path)
end
end
else
defmodule Mix.Tasks.Oban.Install do
Expand Down

0 comments on commit 08f4525

Please sign in to comment.