-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
413 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Mix.Tasks.Ecto.Rollback do | ||
use Mix.Task | ||
import Mix.Tasks.Ecto | ||
|
||
@shortdoc "Reverts migrations down on a repo" | ||
|
||
@moduledoc """ | ||
Reverts applied migrations in the given repository. | ||
Migrations are expected to be found inside the migrations | ||
directory returned by the priv function defined in the | ||
repository. | ||
Runs the latest applied migration by default. To roll back to | ||
to a version number, supply `--to version_number`. | ||
To roll back a specific number of times, use `--step n`. | ||
To undo all applied migrations, provide `--all`. | ||
## Examples | ||
mix ecto.rollback MyApp.Repo | ||
mix ecto.rollback MyApp.Repo -n 3 | ||
mix ecto.rollback MyApp.Repo --step 3 | ||
mix ecto.rollback MyApp.Repo -v 20080906120000 | ||
mix ecto.rollback MyApp.Repo --to 20080906120000 | ||
""" | ||
def run(args, migrator // &Ecto.Migrator.run/3) do | ||
{ opts, args, _ } = OptionParser.parse args, | ||
switches: [all: :boolean, step: :integer, version: :integer], | ||
aliases: [n: :step, v: :to] | ||
{ repo, _ } = parse_repo(args) | ||
ensure_repo(repo) | ||
ensure_started(repo) | ||
migrator.(repo, migrations_path(repo), Keyword.merge(opts, direction: :down)) | ||
end | ||
end |
Oops, something went wrong.