aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2020-01-24 08:58:07 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2020-01-24 08:58:07 +0300
commit293281fcbdba793604316f16f42d0de5ed816941 (patch)
treedd5484d4517d56edfdb697be2f31099a97073828
parent2cfe1b93854c117fda19e54ea17c99f72413a569 (diff)
parenta182d400d7d5aa414240b156965533c0e9b222d0 (diff)
downloadpleroma-293281fcbdba793604316f16f42d0de5ed816941.tar.gz
Merge branch 'develop' into feature/tag_feed
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/mix/tasks/pleroma/config.ex3
-rw-r--r--lib/pleroma/config/config_db.ex2
-rw-r--r--test/config/config_db_test.exs9
-rw-r--r--test/tasks/config_test.exs48
5 files changed, 48 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 14952ffc4..506ce811e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
- 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`.
+- Config mix task `migrate_to_db` truncates `config` table before migrating the config file.
<details>
<summary>API Changes</summary>
diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex
index 861832451..3e76d2c97 100644
--- a/lib/mix/tasks/pleroma/config.ex
+++ b/lib/mix/tasks/pleroma/config.ex
@@ -52,6 +52,9 @@ defmodule Mix.Tasks.Pleroma.Config do
defp do_migrate_to_db(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 =
config_file
|> read_file()
diff --git a/lib/pleroma/config/config_db.ex b/lib/pleroma/config/config_db.ex
index 91a1aa0cc..be6688095 100644
--- a/lib/pleroma/config/config_db.ex
+++ b/lib/pleroma/config/config_db.ex
@@ -416,7 +416,7 @@ defmodule Pleroma.ConfigDB do
@spec is_module_name?(String.t()) :: boolean()
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"]
end
end
diff --git a/test/config/config_db_test.exs b/test/config/config_db_test.exs
index 61a0b1d5d..812709fd8 100644
--- a/test/config/config_db_test.exs
+++ b/test/config/config_db_test.exs
@@ -307,6 +307,15 @@ defmodule Pleroma.ConfigDBTest do
assert ConfigDB.from_binary(binary) == Quack.Logger
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
binary = ConfigDB.transform("~r[comp[lL][aA][iI][nN]er]")
assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/)
diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs
index 2e56e6cfe..d79d34276 100644
--- a/test/tasks/config_test.exs
+++ b/test/tasks/config_test.exs
@@ -25,30 +25,50 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end
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,
[
- "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
end
- test "settings are migrated to db" do
- initial = Application.get_env(:quack, :level)
- on_exit(fn -> Application.put_env(:quack, :level, initial) end)
- assert Repo.all(ConfigDB) == []
+ describe "migrate_to_db/1" do
+ setup do
+ initial = Application.get_env(:quack, :level)
+ on_exit(fn -> Application.put_env(:quack, :level, initial) end)
+ end
+
+ test "settings are migrated to db" do
+ assert Repo.all(ConfigDB) == []
+
+ Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
+
+ config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
+ 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]]
+ assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]]
+ assert ConfigDB.from_binary(config3.value) == :info
+ end
- Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
+ 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
- config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
- 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"})
+ Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
- 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
+ config = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
+ assert ConfigDB.from_binary(config.value) == [key: "value", key2: [Repo]]
+ end
end
describe "with deletion temp file" do