1
0
Fork 1
mirror of https://akkoma.dev/AkkomaGang/akkoma.git synced 2024-12-25 04:53:06 +00:00

Make the --force flag for reset command consistent with the others and deduplicate db truncation

This commit is contained in:
Mark Felder 2020-12-02 16:34:23 -06:00
parent e379ab8277
commit 16bdc2bcd0

View file

@ -95,7 +95,15 @@ def run(["groups"]) do
end) end)
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 -> check_configdb(fn ->
start_pleroma() start_pleroma()
@ -108,13 +116,8 @@ def run(["reset" | options]) do
shell_error("\nTHIS CANNOT BE UNDONE!") shell_error("\nTHIS CANNOT BE UNDONE!")
proceed? = if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
"--force" in options or truncatedb()
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;")
shell_info("The ConfigDB settings have been removed from the database.") shell_info("The ConfigDB settings have been removed from the database.")
else else
@ -189,8 +192,7 @@ def migrate_to_db(file_path \\ nil) do
defp do_migrate_to_db(config_file) do defp do_migrate_to_db(config_file) do
if File.exists?(config_file) do if File.exists?(config_file) do
shell_info("Migrating settings from file: #{Path.expand(config_file)}") shell_info("Migrating settings from file: #{Path.expand(config_file)}")
Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;") truncatedb()
Ecto.Adapters.SQL.query!(Repo, "ALTER SEQUENCE config_id_seq RESTART;")
custom_config = custom_config =
config_file config_file
@ -376,4 +378,9 @@ defp delete_group(group) do
end end
end) 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 end