Permit easy access to vaccum full and analyze via a mix task
authorMark Felder <feld@FreeBSD.org>
Wed, 27 May 2020 21:27:07 +0000 (16:27 -0500)
committerMark Felder <feld@FreeBSD.org>
Wed, 27 May 2020 21:27:07 +0000 (16:27 -0500)
lib/mix/tasks/pleroma/database.ex

index 778de162f1687b7eadfbc1126bfa1c8f96e07b45..c4f343f04fa74978fbc764adfcffec6e97ac7dc7 100644 (file)
@@ -135,4 +135,30 @@ defmodule Mix.Tasks.Pleroma.Database do
     end)
     |> Stream.run()
   end
+
+  def run(["vacuum", args]) do
+    start_pleroma()
+
+    case args do
+      "analyze" ->
+        Logger.info("Runnning VACUUM ANALYZE.")
+        Repo.query!(
+          "vacuum analyze;",
+          [],
+          timeout: :infinity
+        )
+
+      "full" ->
+        Logger.info("Runnning VACUUM FULL. This could take a while.")
+
+        Repo.query!(
+          "vacuum full;",
+          [],
+          timeout: :infinity
+        )
+
+      _ ->
+        Logger.error("Error: invalid vacuum argument.")
+    end
+  end
 end