mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
add release conf for performing migrations
This commit is contained in:
parent
7046857cbd
commit
23bd821838
2 changed files with 30 additions and 6 deletions
24
lib/philomena/release.ex
Normal file
24
lib/philomena/release.ex
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
defmodule Philomena.Release do
|
||||||
|
@app :philomena
|
||||||
|
|
||||||
|
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
|
12
post-receive
12
post-receive
|
@ -21,12 +21,6 @@ if git diff --name-only $oldrev $newrev | grep -Ee "^mix.(exs|lock)"; then
|
||||||
mix deps.get || die "mix failed to update"
|
mix deps.get || die "mix failed to update"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run migrations
|
|
||||||
if git diff --name-only $oldrev $newrev | grep "^priv/repo/migrations"; then
|
|
||||||
echo "Running database migrations"
|
|
||||||
mix ecto.migrate || die "ecto.migrate failed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Compile assets
|
# Compile assets
|
||||||
if git diff --name-only $oldrev $newrev | grep "^assets/"; then
|
if git diff --name-only $oldrev $newrev | grep "^assets/"; then
|
||||||
echo "Compiling assets"
|
echo "Compiling assets"
|
||||||
|
@ -38,6 +32,12 @@ fi
|
||||||
echo "Building release"
|
echo "Building release"
|
||||||
mix release --overwrite || die "failed to generate release"
|
mix release --overwrite || die "failed to generate release"
|
||||||
|
|
||||||
|
# Run migrations
|
||||||
|
if git diff --name-only $oldrev $newrev | grep "^priv/repo/migrations"; then
|
||||||
|
echo "Running database migrations"
|
||||||
|
_build/prod/rel/philomena/bin/philomena eval "Philomena.Release.migrate()" || die "ecto.migrate failed"
|
||||||
|
fi
|
||||||
|
|
||||||
# Include a task to restart your running appserver instances here.
|
# Include a task to restart your running appserver instances here.
|
||||||
#
|
#
|
||||||
# In general, you should have many app instances configured on different
|
# In general, you should have many app instances configured on different
|
||||||
|
|
Loading…
Reference in a new issue