config_db search methods
This commit is contained in:
parent
7fd4f4908b
commit
a02eb88396
@ -62,9 +62,8 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||||||
group = maybe_atomize(group)
|
group = maybe_atomize(group)
|
||||||
key = maybe_atomize(key)
|
key = maybe_atomize(key)
|
||||||
|
|
||||||
%{group: group, key: key}
|
group
|
||||||
|> ConfigDB.get_by_params()
|
|> ConfigDB.get_all_by_group_and_key(key)
|
||||||
|> Repo.all()
|
|
||||||
|> Enum.each(&dump/1)
|
|> Enum.each(&dump/1)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -290,17 +289,15 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp dump_group(group) when is_atom(group) do
|
defp dump_group(group) when is_atom(group) do
|
||||||
%{group: group}
|
group
|
||||||
|> ConfigDB.get_by_params()
|
|> ConfigDB.get_all_by_group()
|
||||||
|> Repo.all()
|
|
||||||
|> Enum.each(&dump/1)
|
|> Enum.each(&dump/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp group_exists?(group) do
|
defp group_exists?(group) do
|
||||||
%{group: group}
|
group
|
||||||
|> ConfigDB.get_by_params()
|
|> ConfigDB.get_all_by_group()
|
||||||
|> Repo.all()
|
|> Enum.empty?()
|
||||||
|> Enum.empty?()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_atomize(arg) when is_atom(arg), do: arg
|
defp maybe_atomize(arg) when is_atom(arg), do: arg
|
||||||
@ -310,7 +307,7 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||||||
String.to_existing_atom("Elixir." <> arg)
|
String.to_existing_atom("Elixir." <> arg)
|
||||||
else
|
else
|
||||||
String.to_atom(arg)
|
String.to_atom(arg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp check_configdb(callback) do
|
defp check_configdb(callback) do
|
||||||
@ -326,8 +323,8 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||||||
|
|
||||||
defp delete_key(group, key) do
|
defp delete_key(group, key) do
|
||||||
check_configdb(fn ->
|
check_configdb(fn ->
|
||||||
ConfigDB.get_by_params(%{group: group, key: key})
|
group
|
||||||
|> Repo.all()
|
|> ConfigDB.get_all_by_group_and_key(key)
|
||||||
|> Enum.each(&delete(&1, true))
|
|> Enum.each(&delete(&1, true))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -338,10 +335,9 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||||||
shell_info("The following settings will be removed from ConfigDB:\n")
|
shell_info("The following settings will be removed from ConfigDB:\n")
|
||||||
dump_group(group)
|
dump_group(group)
|
||||||
|
|
||||||
ConfigDB.get_by_params(%{group: group})
|
group
|
||||||
|> Repo.all()
|
|> ConfigDB.get_all_by_group()
|
||||||
|> Enum.each(&delete(&1, true))
|
|> Enum.each(&delete(&1, true))
|
||||||
|
|
||||||
else
|
else
|
||||||
_ -> shell_error("No settings in ConfigDB for #{inspect(group)}. Aborting.")
|
_ -> shell_error("No settings in ConfigDB for #{inspect(group)}. Aborting.")
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ defmodule Pleroma.ConfigDB do
|
|||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Ecto.Query, only: [select: 3]
|
import Ecto.Query, only: [select: 3, from: 2]
|
||||||
import Pleroma.Web.Gettext
|
import Pleroma.Web.Gettext
|
||||||
|
|
||||||
alias __MODULE__
|
alias __MODULE__
|
||||||
@ -41,6 +41,16 @@ defmodule Pleroma.ConfigDB do
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec get_all_by_group(atom() | String.t()) :: [t()]
|
||||||
|
def get_all_by_group(group) do
|
||||||
|
from(c in ConfigDB, where: c.group == ^group) |> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec get_all_by_group_and_key(atom() | String.t(), atom() | String.t()) :: [t()]
|
||||||
|
def get_all_by_group_and_key(group, key) do
|
||||||
|
from(c in ConfigDB, where: c.group == ^group and c.key == ^key) |> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
@spec get_by_params(map()) :: ConfigDB.t() | nil
|
@spec get_by_params(map()) :: ConfigDB.t() | nil
|
||||||
def get_by_params(params), do: Repo.get_by(ConfigDB, params)
|
def get_by_params(params), do: Repo.get_by(ConfigDB, params)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user