2019-06-19 04:33:33 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2019-06-19 04:33:33 -06:00
|
|
|
|
|
|
|
defmodule Mix.Tasks.Pleroma.Ecto.Rollback do
|
|
|
|
use Mix.Task
|
2019-06-21 19:17:04 -06:00
|
|
|
import Mix.Pleroma
|
2019-06-19 04:33:33 -06:00
|
|
|
require Logger
|
|
|
|
@shortdoc "Wrapper on `ecto.rollback` task"
|
|
|
|
|
|
|
|
@aliases [
|
|
|
|
n: :step,
|
|
|
|
v: :to
|
|
|
|
]
|
|
|
|
|
|
|
|
@switches [
|
|
|
|
all: :boolean,
|
|
|
|
step: :integer,
|
|
|
|
to: :integer,
|
|
|
|
start: :boolean,
|
|
|
|
quiet: :boolean,
|
|
|
|
log_sql: :boolean,
|
2020-12-22 07:55:30 -07:00
|
|
|
migrations_path: :string,
|
|
|
|
env: :string
|
2019-06-19 04:33:33 -06:00
|
|
|
]
|
|
|
|
|
|
|
|
@moduledoc """
|
|
|
|
Changes `Logger` level to `:info` before start rollback.
|
|
|
|
Changes level back when rollback ends.
|
|
|
|
|
|
|
|
## Start rollback
|
|
|
|
|
|
|
|
mix pleroma.ecto.rollback
|
|
|
|
|
|
|
|
Options:
|
|
|
|
- see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Rollback.html
|
|
|
|
"""
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def run(args \\ []) do
|
2019-06-21 19:17:04 -06:00
|
|
|
load_pleroma()
|
2019-06-19 04:33:33 -06:00
|
|
|
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
|
|
|
|
|
2020-08-15 22:02:33 -06:00
|
|
|
if Application.get_env(:pleroma, Pleroma.Repo)[:ssl] do
|
|
|
|
Application.ensure_all_started(:ssl)
|
|
|
|
end
|
|
|
|
|
2019-06-19 04:33:33 -06:00
|
|
|
opts =
|
|
|
|
if opts[:to] || opts[:step] || opts[:all],
|
|
|
|
do: opts,
|
|
|
|
else: Keyword.put(opts, :step, 1)
|
|
|
|
|
|
|
|
opts =
|
|
|
|
if opts[:quiet],
|
|
|
|
do: Keyword.merge(opts, log: false, log_sql: false),
|
|
|
|
else: opts
|
|
|
|
|
|
|
|
path = Mix.Tasks.Pleroma.Ecto.ensure_migrations_path(Pleroma.Repo, opts)
|
|
|
|
|
|
|
|
level = Logger.level()
|
|
|
|
Logger.configure(level: :info)
|
|
|
|
|
2020-12-22 07:55:30 -07:00
|
|
|
if opts[:env] == "test" do
|
2019-06-19 04:33:33 -06:00
|
|
|
Logger.info("Rollback succesfully")
|
|
|
|
else
|
|
|
|
{:ok, _, _} =
|
|
|
|
Ecto.Migrator.with_repo(Pleroma.Repo, &Ecto.Migrator.run(&1, path, :down, opts))
|
|
|
|
end
|
|
|
|
|
|
|
|
Logger.configure(level: level)
|
|
|
|
end
|
|
|
|
end
|