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, delete?]) do
42 delete? = if delete? == "true", do: true, else: false
44 if Pleroma.Config.get([:instance, :dynamic_configuration]) do
45 config_path = "config/#{env}.exported_from_db.secret.exs"
47 {:ok, file} = File.open(config_path, [:write])
48 IO.write(file, "use Mix.Config\r\n")
51 |> Enum.each(fn config ->
53 if String.starts_with?(config.key, "Pleroma.") or
54 String.starts_with?(config.key, "Ueberauth"),
60 "config :#{config.group}, #{config.key}#{mark} #{
61 inspect(Config.from_binary(config.value))
66 {:ok, _} = Repo.delete(config)
67 Mix.shell().info("#{config.key} deleted from DB.")
72 System.cmd("mix", ["format", config_path])
75 "Migration is not allowed by config. You can change this behavior in instance settings."