projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'develop' into feature/1893-remote-emoji-packs-pagination
[akkoma]
/
lib
/
mix
/
tasks
/
pleroma
/
config.ex
diff --git
a/lib/mix/tasks/pleroma/config.ex
b/lib/mix/tasks/pleroma/config.ex
index 861832451bb272e43c63385f895fff85af54b681..18f99318db09d1ad5a53fe777fc25d22bd39f33f 100644
(file)
--- a/
lib/mix/tasks/pleroma/config.ex
+++ b/
lib/mix/tasks/pleroma/config.ex
@@
-1,5
+1,5
@@
# Pleroma: A lightweight social networking server
# Pleroma: A lightweight social networking server
-# Copyright © 2017-20
19
Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-20
20
Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.Config do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.Config do
@@
-32,7
+32,8
@@
defmodule Mix.Tasks.Pleroma.Config do
@spec migrate_to_db(Path.t() | nil) :: any()
def migrate_to_db(file_path \\ nil) do
@spec migrate_to_db(Path.t() | nil) :: any()
def migrate_to_db(file_path \\ nil) do
- if Pleroma.Config.get([:configurable_from_database]) do
+ with true <- Pleroma.Config.get([:configurable_from_database]),
+ :ok <- Pleroma.Config.DeprecationWarnings.warn() do
config_file =
if file_path do
file_path
config_file =
if file_path do
file_path
@@
-46,12
+47,17
@@
defmodule Mix.Tasks.Pleroma.Config do
do_migrate_to_db(config_file)
else
do_migrate_to_db(config_file)
else
- migration_error()
+ :error -> deprecation_error()
+ _ -> migration_error()
end
end
defp do_migrate_to_db(config_file) do
if File.exists?(config_file) do
end
end
defp do_migrate_to_db(config_file) do
if File.exists?(config_file) do
+ shell_info("Migrating settings from file: #{Path.expand(config_file)}")
+ Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;")
+ Ecto.Adapters.SQL.query!(Repo, "ALTER SEQUENCE config_id_seq RESTART;")
+
custom_config =
config_file
|> read_file()
custom_config =
config_file
|> read_file()
@@
-69,8
+75,7
@@
defmodule Mix.Tasks.Pleroma.Config do
group
|> Pleroma.Config.Loader.filter_group(settings)
|> Enum.each(fn {key, value} ->
group
|> Pleroma.Config.Loader.filter_group(settings)
|> Enum.each(fn {key, value} ->
- key = inspect(key)
- {:ok, _} = ConfigDB.update_or_create(%{group: inspect(group), key: key, value: value})
+ {:ok, _} = ConfigDB.update_or_create(%{group: group, key: key, value: value})
shell_info("Settings for key #{key} migrated.")
end)
shell_info("Settings for key #{key} migrated.")
end)
@@
-80,7
+85,7
@@
defmodule Mix.Tasks.Pleroma.Config do
defp migrate_from_db(opts) do
if Pleroma.Config.get([:configurable_from_database]) do
defp migrate_from_db(opts) do
if Pleroma.Config.get([:configurable_from_database]) do
- env = opts[:env] ||
"prod"
+ env = opts[:env] ||
Pleroma.Config.get(:env)
config_path =
if Pleroma.Config.get(:release) do
config_path =
if Pleroma.Config.get(:release) do
@@
-102,6
+107,10
@@
defmodule Mix.Tasks.Pleroma.Config do
:ok = File.close(file)
System.cmd("mix", ["format", config_path])
:ok = File.close(file)
System.cmd("mix", ["format", config_path])
+
+ shell_info(
+ "Database configuration settings have been exported to config/#{env}.exported_from_db.secret.exs"
+ )
else
migration_error()
end
else
migration_error()
end
@@
-109,10
+118,14
@@
defmodule Mix.Tasks.Pleroma.Config do
defp migration_error do
shell_error(
defp migration_error do
shell_error(
- "Migration is not allowed in config. You can change this behavior by setting `config
urable_from_database` to true.
"
+ "Migration is not allowed in config. You can change this behavior by setting `config
:pleroma, configurable_from_database: true`
"
)
end
)
end
+ defp deprecation_error do
+ shell_error("Migration is not allowed until all deprecation warnings have been resolved.")
+ end
+
if Code.ensure_loaded?(Config.Reader) do
defp config_header, do: "import Config\r\n\r\n"
defp read_file(config_file), do: Config.Reader.read_imports!(config_file)
if Code.ensure_loaded?(Config.Reader) do
defp config_header, do: "import Config\r\n\r\n"
defp read_file(config_file), do: Config.Reader.read_imports!(config_file)
@@
-128,12
+141,9
@@
defmodule Mix.Tasks.Pleroma.Config do
end
defp write(config, file) do
end
defp write(config, file) do
- value =
- config.value
- |> ConfigDB.from_binary()
- |> inspect(limit: :infinity)
+ value = inspect(config.value, limit: :infinity)
- IO.write(file, "config #{
config.group}, #{config.key
}, #{value}\r\n\r\n")
+ IO.write(file, "config #{
inspect(config.group)}, #{inspect(config.key)
}, #{value}\r\n\r\n")
config
end
config
end