~ihabunek/triglav

4993a877f2b4e6d7614775d11a31af49163292e4 — Ivan Habunek 1 year, 24 days ago 56b08b1
Release preparation
3 files changed, 27 insertions(+), 7 deletions(-)

M config/prod.exs
R config/{prod.secret.exs => releases.exs}
A lib/triglav/release.ex
M config/prod.exs => config/prod.exs +1 -5
@@ 10,7 10,7 @@ use Mix.Config
# which you should run after static files are built and
# before starting your production server.
config :triglav, TriglavWeb.Endpoint,
  url: [host: "example.com", port: 80],
  url: [host: "triglav.bezdomni.net", port: 80],
  cache_static_manifest: "priv/static/cache_manifest.json"

# Do not print debug messages in production


@@ 49,7 49,3 @@ config :logger, level: :info
#       force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.

# Finally import the config/prod.secret.exs which loads secrets
# and configuration from environment variables.
import_config "prod.secret.exs"

R config/prod.secret.exs => config/releases.exs +2 -2
@@ 2,7 2,7 @@
# from environment variables. You can also hardcode secrets,
# although such is generally not recommended and you have to
# remember to add this file to your .gitignore.
use Mix.Config
import Config

database_url =
  System.get_env("DATABASE_URL") ||


@@ 35,7 35,7 @@ config :triglav, TriglavWeb.Endpoint,
# If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint:
#
#     config :triglav, TriglavWeb.Endpoint, server: true
config :triglav, TriglavWeb.Endpoint, server: true
#
# Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information.

A lib/triglav/release.ex => lib/triglav/release.ex +24 -0
@@ 0,0 1,24 @@
defmodule Triglav.Release do
  @app :triglav

  def migrate do
    load_app()

    for repo <- repos() do
      {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
    end
  end

  def rollback(repo, version) do
    load_app()
    {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
  end

  defp repos do
    Application.fetch_env!(@app, :ecto_repos)
  end

  defp load_app do
    Application.load(@app)
  end
end