giant massive dep upgrade and dialyxir-found error emporium (#371)
[akkoma] / lib / mix / tasks / pleroma / database.ex
index bcde07774fb71b9365bec0bdc75169ebc4196aa6..272c9e3e536884af38007a0841850b2660b00057 100644 (file)
@@ -18,7 +18,7 @@ defmodule Mix.Tasks.Pleroma.Database do
   use Mix.Task
 
   @shortdoc "A collection of database related tasks"
-  @moduledoc File.read!("docs/administration/CLI_tasks/database.md")
+  @moduledoc File.read!("docs/docs/administration/CLI_tasks/database.md")
 
   def run(["remove_embedded_objects" | args]) do
     {options, [], []} =
@@ -97,10 +97,10 @@ defmodule Mix.Tasks.Pleroma.Database do
     |> Repo.delete_all(timeout: :infinity)
 
     prune_hashtags_query = """
-    delete from hashtags as ht
-    where not exists (
-      select 1 from hashtags_objects hto
-      where ht.id = hto.hashtag_id)
+    DELETE FROM hashtags AS ht
+    WHERE NOT EXISTS (
+      SELECT 1 FROM hashtags_objects hto
+      WHERE ht.id = hto.hashtag_id)
     """
 
     Repo.query(prune_hashtags_query)
@@ -110,6 +110,13 @@ defmodule Mix.Tasks.Pleroma.Database do
     end
   end
 
+  def run(["prune_task"]) do
+    start_pleroma()
+
+    nil
+    |> Pleroma.Workers.Cron.PruneDatabaseWorker.perform()
+  end
+
   def run(["fix_likes_collections"]) do
     start_pleroma()
 
@@ -209,7 +216,9 @@ defmodule Mix.Tasks.Pleroma.Database do
           new.fts_content := to_tsvector(new.data->>'content');
           RETURN new;
           END
-          $$ LANGUAGE plpgsql"
+          $$ LANGUAGE plpgsql",
+          [],
+          timeout: :infinity
         )
 
         shell_info("Refresh RUM index")
@@ -219,7 +228,9 @@ defmodule Mix.Tasks.Pleroma.Database do
 
         Ecto.Adapters.SQL.query!(
           Pleroma.Repo,
-          "CREATE INDEX objects_fts ON objects USING gin(to_tsvector('#{tsconfig}', data->>'content')); "
+          "CREATE INDEX CONCURRENTLY objects_fts ON objects USING gin(to_tsvector('#{tsconfig}', data->>'content')); ",
+          [],
+          timeout: :infinity
         )
       end