=== "OTP"
```sh
- ./bin/pleroma_ctl config delete tesla
+ ./bin/pleroma_ctl config delete [--force] tesla
```
=== "From Source"
```sh
- mix pleroma.config delete tesla
+ mix pleroma.config delete [--force] tesla
```
To delete values under a specific key:
=== "OTP"
```sh
- ./bin/pleroma_ctl config delete phoenix stacktrace_depth
+ ./bin/pleroma_ctl config delete [--force] phoenix stacktrace_depth
```
=== "From Source"
```sh
- mix pleroma.config delete phoenix stacktrace_depth
+ mix pleroma.config delete [--force] phoenix stacktrace_depth
```
## Remove all settings from the database
=== "OTP"
```sh
- ./bin/pleroma_ctl config reset
+ ./bin/pleroma_ctl config [--force] reset
```
=== "From Source"
```sh
- mix pleroma.config reset
+ mix pleroma.config [--force] reset
```
end)
end
- def run(["reset"]) do
+ def run(["reset" | options]) do
check_configdb(fn ->
start_pleroma()
shell_error("\nTHIS CANNOT BE UNDONE!")
- if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
+ 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;")
end)
end
- def run(["delete", group]) do
- check_configdb(fn ->
- start_pleroma()
+ def run(["delete", "--force", group, key]) do
+ start_pleroma()
- group = maybe_atomize(group)
+ group = maybe_atomize(group)
+ key = maybe_atomize(key)
- if group_exists?(group) do
- shell_info("The following settings will be removed from ConfigDB:\n")
+ delete_key(group, key)
+ end
- dump_group(group)
+ def run(["delete", "--force", group]) do
+ start_pleroma()
- if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
- ConfigDB
- |> Repo.all()
- |> Enum.filter(fn x ->
- if x.group == group do
- x |> delete(true)
- end
- end)
- else
- shell_error("No changes made.")
- end
- else
- shell_error("No settings in ConfigDB for #{inspect(group)}. Aborting.")
- end
- end)
+ group = maybe_atomize(group)
+
+ delete_group(group)
end
def run(["delete", group, key]) do
- check_configdb(fn ->
- start_pleroma()
+ start_pleroma()
- group = maybe_atomize(group)
- key = maybe_atomize(key)
+ group = maybe_atomize(group)
+ key = maybe_atomize(key)
- if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
- ConfigDB
- |> Repo.all()
- |> Enum.filter(fn x ->
- if x.group == group and x.key == key do
- x |> delete(true)
- end
- end)
- else
- shell_error("No changes made.")
- end
- end)
+ if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
+ delete_key(group, key)
+ else
+ shell_error("No changes made.")
+ end
+ end
+
+ def run(["delete", group]) do
+ start_pleroma()
+
+ group = maybe_atomize(group)
+
+ if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
+ delete_group(group)
+ else
+ shell_error("No changes made.")
+ end
end
@spec migrate_to_db(Path.t() | nil) :: any()
{:ok, _} = Repo.delete(config)
shell_info(
- "config #{inspect(config.group)}, #{inspect(config.key)} deleted from the ConfigDB."
+ "config #{inspect(config.group)}, #{inspect(config.key)} was deleted from the ConfigDB."
)
end
)
end
end
+
+ defp delete_key(group, key) do
+ check_configdb(fn ->
+ ConfigDB
+ |> Repo.all()
+ |> Enum.filter(fn x ->
+ if x.group == group and x.key == key do
+ x |> delete(true)
+ end
+ end)
+ end)
+ end
+
+ defp delete_group(group) do
+ check_configdb(fn ->
+ with true <- group_exists?(group) do
+ shell_info("The following settings will be removed from ConfigDB:\n")
+ dump_group(group)
+
+ ConfigDB
+ |> Repo.all()
+ |> Enum.filter(fn x ->
+ if x.group == group do
+ x |> delete(true)
+ end
+ end)
+ else
+ _ -> shell_error("No settings in ConfigDB for #{inspect(group)}. Aborting.")
+ end
+ end)
+ end
end
]}
end
end
+
+ describe "destructive operations" do
+ setup do: clear_config(:configurable_from_database, true)
+
+ test "deletes group of settings" do
+ insert(:config,
+ group: :pleroma,
+ key: :instance,
+ value: [
+ name: "Pleroma Test"
+ ]
+ )
+
+ _config_before = Repo.all(ConfigDB)
+
+ assert config_before = [
+ %Pleroma.ConfigDB{
+ group: :pleroma,
+ key: :instance,
+ value: [name: "Pleroma Test"]
+ }
+ ]
+
+ Mix.Tasks.Pleroma.Config.run(["delete", "--force", "pleroma"])
+
+ config_after = Repo.all(ConfigDB)
+
+ refute config_after == config_before
+ end
+
+ test "deletes specified key" do
+ insert(:config,
+ group: :pleroma,
+ key: :instance,
+ value: [
+ name: "Pleroma Test"
+ ]
+ )
+
+ insert(:config,
+ group: :pleroma,
+ key: Pleroma.Captcha,
+ value: [
+ enabled: false
+ ]
+ )
+
+ _config_before = Repo.all(ConfigDB)
+
+ assert config_before = [
+ %Pleroma.ConfigDB{
+ group: :pleroma,
+ key: :instance,
+ value: [name: "Pleroma Test"]
+ },
+ %Pleroma.ConfigDB{
+ group: :pleroma,
+ key: Pleroma.Captcha,
+ value: [enabled: false]
+ }
+ ]
+
+ Mix.Tasks.Pleroma.Config.run(["delete", "--force", "pleroma", "Pleroma.Captcha"])
+
+ config_after = Repo.all(ConfigDB)
+
+ refute config_after == config_before
+ end
+
+ test "resets entire config" do
+ insert(:config,
+ group: :pleroma,
+ key: :instance,
+ value: [
+ name: "Pleroma Test"
+ ]
+ )
+
+ _config_before = Repo.all(ConfigDB)
+
+ assert config_before = [
+ %Pleroma.ConfigDB{
+ group: :pleroma,
+ key: :instance,
+ value: [name: "Pleroma Test"]
+ }
+ ]
+
+ Mix.Tasks.Pleroma.Config.run(["reset", "--force"])
+
+ config_after = Repo.all(ConfigDB)
+
+ assert config_after == []
+ end
+ end
end