From ee3b95008e42043785e587b8adea8f06920dc663 Mon Sep 17 00:00:00 2001 From: Bertram Harendt Date: Mon, 1 Jun 2015 19:21:16 +0200 Subject: [PATCH] Use rpc to execute migrations. --- lib/edeliver.ex | 3 +-- strategies/erlang-node-execute | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/edeliver.ex b/lib/edeliver.ex index 0efa463b..16f330fa 100644 --- a/lib/edeliver.ex +++ b/lib/edeliver.ex @@ -33,8 +33,7 @@ defmodule Edeliver do end) end - def migrate(application_name, application_version, direction, migration_version \\ :all) do - direction = String.to_atom direction + def migrate(application_name, application_version, direction, migration_version \\ :all) when is_atom(direction) do options = if migration_version == :all, do: [all: true], else: [to: to_string(migration_version)] Ecto.Migrator.run(ecto_repository!, migrations_dir(application_name, application_version), direction, options) end diff --git a/strategies/erlang-node-execute b/strategies/erlang-node-execute index 890cc5d7..ff856ab6 100644 --- a/strategies/erlang-node-execute +++ b/strategies/erlang-node-execute @@ -17,6 +17,13 @@ run() { NODE_ACTION="rpc Elixir.Edeliver run_command '[[list_pending_migrations, \"$APP\"]].'" elif [[ "$NODE_ACTION" = migrations ]] && [[ "$RELEASE_CMD" != "mix" ]]; then error "Showing migrations is only supported when using mix as release command." + elif [[ "$NODE_ACTION" = migrate ]] && [[ "$RELEASE_CMD" = "mix" ]]; then + local __up_or_down="up" + for args in $ARGS; do [[ "$arg" = "down" ]] && local __up_or_down="down"; done + [[ -n "$VERSION" ]] && local __to_version=", \"$VERSION\"" || local __to_version="" + NODE_ACTION="rpc Elixir.Edeliver run_command '[[migrate, \"$APP\", ${__up_or_down}${__to_version}]].'" + elif [[ "$NODE_ACTION" = migrate ]] && [[ "$RELEASE_CMD" != "mix" ]]; then + error "Executing migrations is only supported when using mix as release command." fi __exec_if_defined execute_custom_node_command "$NODE_ACTION" || execute_node_command "$NODE_ACTION" }