Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

72 řádky
1.6KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-onl
  4. defmodule Mix.Tasks.Pleroma.Ecto.Rollback do
  5. use Mix.Task
  6. import Mix.Pleroma
  7. require Logger
  8. @shortdoc "Wrapper on `ecto.rollback` task"
  9. @aliases [
  10. n: :step,
  11. v: :to
  12. ]
  13. @switches [
  14. all: :boolean,
  15. step: :integer,
  16. to: :integer,
  17. start: :boolean,
  18. quiet: :boolean,
  19. log_sql: :boolean,
  20. migrations_path: :string
  21. ]
  22. @moduledoc """
  23. Changes `Logger` level to `:info` before start rollback.
  24. Changes level back when rollback ends.
  25. ## Start rollback
  26. mix pleroma.ecto.rollback
  27. Options:
  28. - see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Rollback.html
  29. """
  30. @impl true
  31. def run(args \\ []) do
  32. load_pleroma()
  33. {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
  34. if Application.get_env(:pleroma, Pleroma.Repo)[:ssl] do
  35. Application.ensure_all_started(:ssl)
  36. end
  37. opts =
  38. if opts[:to] || opts[:step] || opts[:all],
  39. do: opts,
  40. else: Keyword.put(opts, :step, 1)
  41. opts =
  42. if opts[:quiet],
  43. do: Keyword.merge(opts, log: false, log_sql: false),
  44. else: opts
  45. path = Mix.Tasks.Pleroma.Ecto.ensure_migrations_path(Pleroma.Repo, opts)
  46. level = Logger.level()
  47. Logger.configure(level: :info)
  48. if Pleroma.Config.get(:env) == :test do
  49. Logger.info("Rollback succesfully")
  50. else
  51. {:ok, _, _} =
  52. Ecto.Migrator.with_repo(Pleroma.Repo, &Ecto.Migrator.run(&1, path, :down, opts))
  53. end
  54. Logger.configure(level: level)
  55. end
  56. end