aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2020-01-23 17:23:02 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2020-01-23 17:23:02 +0300
commit4344c5d5b99cedcd08e168650af2f641ef8c6f0b (patch)
tree98c4e1a964f0cb45301b50dd96f508f2437d9de7
parentdddebee047efc4ab1dff6565bef32954695846a7 (diff)
downloadpleroma-4344c5d5b99cedcd08e168650af2f641ef8c6f0b.tar.gz
truncate config table on migrate to db task
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/mix/tasks/pleroma/config.ex2
-rw-r--r--test/tasks/config_test.exs44
3 files changed, 35 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f6914638..861312e18 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..8098e9bab 100644
--- a/lib/mix/tasks/pleroma/config.ex
+++ b/lib/mix/tasks/pleroma/config.ex
@@ -52,6 +52,8 @@ 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;")
+
custom_config =
config_file
|> read_file()
diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs
index 2e56e6cfe..f2c294140 100644
--- a/test/tasks/config_test.exs
+++ b/test/tasks/config_test.exs
@@ -34,21 +34,41 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
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