|
|
|
@ -16,6 +16,19 @@ defmodule Explorer.ReleaseTasks do |
|
|
|
|
|
|
|
|
|
@repos Application.compile_env(:blockscout, :ecto_repos, [Explorer.Repo]) |
|
|
|
|
|
|
|
|
|
def create_and_migrate do |
|
|
|
|
start_services() |
|
|
|
|
|
|
|
|
|
create() |
|
|
|
|
run_migrations() |
|
|
|
|
|
|
|
|
|
stop_services() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def create do |
|
|
|
|
Enum.each(@repos, &create_db_for/1) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def migrate(_argv) do |
|
|
|
|
start_services() |
|
|
|
|
|
|
|
|
@ -51,6 +64,16 @@ defmodule Explorer.ReleaseTasks do |
|
|
|
|
:init.stop() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp create_db_for(repo) do |
|
|
|
|
IO.puts("Create #{inspect(repo)} database if it doesn't exist") |
|
|
|
|
|
|
|
|
|
case repo.__adapter__.storage_up(repo.config) do |
|
|
|
|
:ok -> :ok |
|
|
|
|
{:error, :already_up} -> :ok |
|
|
|
|
{:error, term} -> {:error, term} |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp run_migrations do |
|
|
|
|
Enum.each(@repos, &run_migrations_for/1) |
|
|
|
|
end |
|
|
|
|