summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Felder <feld@FreeBSD.org>2020-12-02 16:34:23 -0600
committerMark Felder <feld@FreeBSD.org>2020-12-02 16:34:23 -0600
commit16bdc2bcd0600ae4c1fcb55eaa84824af01ee61e (patch)
tree0b52d848e30cbe093de23edac1735efa52b9bd76
parente379ab8277f552d66737963a9c908ae3fc01c1ff (diff)
Make the --force flag for reset command consistent with the others and deduplicate db truncation
-rw-r--r--lib/mix/tasks/pleroma/config.ex27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex
index 014782c35..ebaf2c623 100644
--- a/lib/mix/tasks/pleroma/config.ex
+++ b/lib/mix/tasks/pleroma/config.ex
@@ -95,7 +95,15 @@ defmodule Mix.Tasks.Pleroma.Config do
end)
end
- def run(["reset" | options]) do
+ def run(["reset", "--force"]) do
+ check_configdb(fn ->
+ start_pleroma()
+ truncatedb()
+ shell_info("The ConfigDB settings have been removed from the database.")
+ end)
+ end
+
+ def run(["reset"]) do
check_configdb(fn ->
start_pleroma()
@@ -108,13 +116,8 @@ defmodule Mix.Tasks.Pleroma.Config do
shell_error("\nTHIS CANNOT BE UNDONE!")
- proceed? =
- "--force" in options or
- shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y)
-
- if proceed? do
- Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;")
- Ecto.Adapters.SQL.query!(Repo, "ALTER SEQUENCE config_id_seq RESTART;")
+ if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
+ truncatedb()
shell_info("The ConfigDB settings have been removed from the database.")
else
@@ -189,8 +192,7 @@ defmodule Mix.Tasks.Pleroma.Config do
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;")
+ truncatedb()
custom_config =
config_file
@@ -376,4 +378,9 @@ defmodule Mix.Tasks.Pleroma.Config do
end
end)
end
+
+ defp truncatedb() do
+ Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;")
+ Ecto.Adapters.SQL.query!(Repo, "ALTER SEQUENCE config_id_seq RESTART;")
+ end
end