1 defmodule Mix.Tasks.Pleroma.Config do
5 alias Pleroma.Web.AdminAPI.Config
6 @shortdoc "Manages the location of the config"
8 Manages the location of the config.
10 ## Transfers config from file to DB.
12 mix pleroma.config migrate_to_db
14 ## Transfers config from DB to file.
16 mix pleroma.config migrate_from_db ENV
19 def run(["migrate_to_db"]) do
22 if Pleroma.Config.get([:instance, :dynamic_configuration]) do
23 Application.get_all_env(:pleroma)
24 |> Enum.reject(fn {k, _v} -> k in [Pleroma.Repo, :env] end)
25 |> Enum.each(fn {k, v} ->
26 key = to_string(k) |> String.replace("Elixir.", "")
27 {:ok, _} = Config.update_or_create(%{group: "pleroma", key: key, value: v})
28 Mix.shell().info("#{key} is migrated.")
31 Mix.shell().info("Settings migrated.")
34 "Migration is not allowed by config. You can change this behavior in instance settings."
39 def run(["migrate_from_db", env]) do
42 if Pleroma.Config.get([:instance, :dynamic_configuration]) do
43 config_path = "config/#{env}.exported_from_db.secret.exs"
45 {:ok, file} = File.open(config_path, [:write])
46 IO.write(file, "use Mix.Config\r\n")
49 |> Enum.each(fn config ->
50 mark = if String.starts_with?(config.key, "Pleroma."), do: ",", else: ":"
54 "config :#{config.group}, #{config.key}#{mark} #{
55 inspect(Config.from_binary(config.value))
59 {:ok, _} = Repo.delete(config)
60 Mix.shell().info("#{config.key} deleted from DB.")
64 System.cmd("mix", ["format", config_path])
67 "Migration is not allowed by config. You can change this behavior in instance settings."