Merge branch 'develop' into feature/tag_feed
This commit is contained in:
commit
293281fcbd
|
@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Store status data inside Flag activity
|
- Store status data inside Flag activity
|
||||||
- Deprecated (reorganized as `UserRelationship` entity) User fields with user AP IDs (`blocks`, `mutes`, `muted_reblogs`, `muted_notifications`, `subscribers`).
|
- Deprecated (reorganized as `UserRelationship` entity) User fields with user AP IDs (`blocks`, `mutes`, `muted_reblogs`, `muted_notifications`, `subscribers`).
|
||||||
- Logger: default log level changed from `warn` to `info`.
|
- Logger: default log level changed from `warn` to `info`.
|
||||||
|
- Config mix task `migrate_to_db` truncates `config` table before migrating the config file.
|
||||||
<details>
|
<details>
|
||||||
<summary>API Changes</summary>
|
<summary>API Changes</summary>
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,9 @@ def migrate_to_db(file_path \\ nil) do
|
||||||
|
|
||||||
defp do_migrate_to_db(config_file) do
|
defp do_migrate_to_db(config_file) do
|
||||||
if File.exists?(config_file) do
|
if File.exists?(config_file) do
|
||||||
|
Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;")
|
||||||
|
Ecto.Adapters.SQL.query!(Repo, "ALTER SEQUENCE config_id_seq RESTART;")
|
||||||
|
|
||||||
custom_config =
|
custom_config =
|
||||||
config_file
|
config_file
|
||||||
|> read_file()
|
|> read_file()
|
||||||
|
|
|
@ -416,7 +416,7 @@ defp do_transform_string(value) do
|
||||||
|
|
||||||
@spec is_module_name?(String.t()) :: boolean()
|
@spec is_module_name?(String.t()) :: boolean()
|
||||||
def is_module_name?(string) do
|
def is_module_name?(string) do
|
||||||
Regex.match?(~r/^(Pleroma|Phoenix|Tesla|Quack|Ueberauth)\./, string) or
|
Regex.match?(~r/^(Pleroma|Phoenix|Tesla|Quack|Ueberauth|Swoosh)\./, string) or
|
||||||
string in ["Oban", "Ueberauth", "ExSyslogger"]
|
string in ["Oban", "Ueberauth", "ExSyslogger"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -307,6 +307,15 @@ test "Quack.Logger module" do
|
||||||
assert ConfigDB.from_binary(binary) == Quack.Logger
|
assert ConfigDB.from_binary(binary) == Quack.Logger
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "Swoosh.Adapters modules" do
|
||||||
|
binary = ConfigDB.transform("Swoosh.Adapters.SMTP")
|
||||||
|
assert binary == :erlang.term_to_binary(Swoosh.Adapters.SMTP)
|
||||||
|
assert ConfigDB.from_binary(binary) == Swoosh.Adapters.SMTP
|
||||||
|
binary = ConfigDB.transform("Swoosh.Adapters.AmazonSES")
|
||||||
|
assert binary == :erlang.term_to_binary(Swoosh.Adapters.AmazonSES)
|
||||||
|
assert ConfigDB.from_binary(binary) == Swoosh.Adapters.AmazonSES
|
||||||
|
end
|
||||||
|
|
||||||
test "sigil" do
|
test "sigil" do
|
||||||
binary = ConfigDB.transform("~r[comp[lL][aA][iI][nN]er]")
|
binary = ConfigDB.transform("~r[comp[lL][aA][iI][nN]er]")
|
||||||
assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/)
|
assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/)
|
||||||
|
|
|
@ -25,30 +25,50 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "error if file with custom settings doesn't exist" do
|
test "error if file with custom settings doesn't exist" do
|
||||||
Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
|
Mix.Tasks.Pleroma.Config.migrate_to_db("config/not_existance_config_file.exs")
|
||||||
|
|
||||||
assert_receive {:mix_shell, :info,
|
assert_receive {:mix_shell, :info,
|
||||||
[
|
[
|
||||||
"To migrate settings, you must define custom settings in config/test.secret.exs."
|
"To migrate settings, you must define custom settings in config/not_existance_config_file.exs."
|
||||||
]},
|
]},
|
||||||
15
|
15
|
||||||
end
|
end
|
||||||
|
|
||||||
test "settings are migrated to db" do
|
describe "migrate_to_db/1" do
|
||||||
initial = Application.get_env(:quack, :level)
|
setup do
|
||||||
on_exit(fn -> Application.put_env(:quack, :level, initial) end)
|
initial = Application.get_env(:quack, :level)
|
||||||
assert Repo.all(ConfigDB) == []
|
on_exit(fn -> Application.put_env(:quack, :level, initial) end)
|
||||||
|
end
|
||||||
|
|
||||||
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
|
test "settings are migrated to db" do
|
||||||
|
assert Repo.all(ConfigDB) == []
|
||||||
|
|
||||||
config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
|
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
|
||||||
config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
|
|
||||||
config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
|
|
||||||
refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
|
|
||||||
|
|
||||||
assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]]
|
config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
|
||||||
assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]]
|
config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
|
||||||
assert ConfigDB.from_binary(config3.value) == :info
|
config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
|
||||||
|
refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
|
||||||
|
|
||||||
|
assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]]
|
||||||
|
assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]]
|
||||||
|
assert ConfigDB.from_binary(config3.value) == :info
|
||||||
|
end
|
||||||
|
|
||||||
|
test "config table is truncated before migration" do
|
||||||
|
ConfigDB.create(%{
|
||||||
|
group: ":pleroma",
|
||||||
|
key: ":first_setting",
|
||||||
|
value: [key: "value", key2: ["Activity"]]
|
||||||
|
})
|
||||||
|
|
||||||
|
assert Repo.aggregate(ConfigDB, :count, :id) == 1
|
||||||
|
|
||||||
|
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
|
||||||
|
|
||||||
|
config = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
|
||||||
|
assert ConfigDB.from_binary(config.value) == [key: "value", key2: [Repo]]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with deletion temp file" do
|
describe "with deletion temp file" do
|
||||||
|
|
Loading…
Reference in a new issue