Packages
significa_utils
0.3.2
0.3.2
0.3.1
0.3.0
0.3.0-1
0.2.0
0.1.0
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
0.0.1-main-d418c86c2c8e6d2638e4a225893f6e068bf36270
0.0.1-main-a68c9941c5d644aa896c6919c6ccfc2aa420ea48
0.0.1-main-9b7a22dadf92316ec0551664b2afd2687c6d5815
0.0.1-main-72a387d58ff1307364683940dbea968462c39c1d-1
0.0.1-main-604c9394407686ac217f507d69140a39c1198e3b-1
Collection of elixir utils
Current section
Files
Jump to
Current section
Files
lib/ecto_release_tasks.ex
defmodule SignificaUtils.EctoReleaseTasks do
@moduledoc """
Utility function to create release common tasks used in Ecto projects.
## Usage
```
defmodule SampleProject.ReleaseTasks do
use SignificaUtils.EctoReleaseTasks,
otp_app: :sample_app
end
Creates two public functions:
- `migrate/0`: migrates all the repos to the latest version.
- `rollback/2`: rolls back the repo to the specified version - `rollback(repo, version)`.
```
"""
defmacro __using__(opts) do
otp_app = Keyword.fetch!(opts, :otp_app)
quote do
def migrate do
load_app()
for repo <- get_repos() do
run_migrations(repo, :up, all: true)
end
end
def rollback(repo, version) do
load_app()
run_migrations(repo, :down, to: version)
end
defp get_repos do
Application.fetch_env!(unquote(otp_app), :ecto_repos)
end
defp load_app do
Application.load(unquote(otp_app))
end
defp run_migrations(repo, direction, opts \\ []) do
{:ok, _, _} =
Ecto.Migrator.with_repo(
repo,
&Ecto.Migrator.run(&1, direction, opts)
)
end
end
end
end