summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gleason <alex@alexgleason.me>2022-01-22 16:01:15 -0600
committerAlex Gleason <alex@alexgleason.me>2022-01-22 16:09:50 -0600
commit454307112c9e3cb7a365c61526ae529d8eef8fe8 (patch)
tree550dc556b2dc7322d864194ea1138c7e9f10d2de
parentc368078cd0e09f3d1cc95ecba96cf42d460e1469 (diff)
Add clippy
-rw-r--r--priv/repo/migrations/20211218181632_change_object_id_to_flake.exs70
-rw-r--r--priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs64
-rw-r--r--priv/repo/migrations/20211218181647_combine_activities_and_objects.exs68
3 files changed, 201 insertions, 1 deletions
diff --git a/priv/repo/migrations/20211218181632_change_object_id_to_flake.exs b/priv/repo/migrations/20211218181632_change_object_id_to_flake.exs
index bc6f920b0..dd8912b93 100644
--- a/priv/repo/migrations/20211218181632_change_object_id_to_flake.exs
+++ b/priv/repo/migrations/20211218181632_change_object_id_to_flake.exs
@@ -4,6 +4,12 @@ defmodule Pleroma.Repo.Migrations.ChangeObjectIdToFlake do
Fortunately only a few tables have a foreign key to objects. Update them.
"""
use Ecto.Migration
+ require Integer
+
+ alias Pleroma.Clippy
+ alias Pleroma.Repo
+
+ import Ecto.Query
@delete_duplicate_ap_id_objects_query """
DELETE FROM objects
@@ -33,6 +39,8 @@ defmodule Pleroma.Repo.Migrations.ChangeObjectIdToFlake do
"""
def up do
+ clippy = start_clippy_heartbeats()
+
# Lock tables to avoid a running server meddling with our transaction
execute("LOCK TABLE objects")
execute("LOCK TABLE data_migration_failed_ids")
@@ -84,9 +92,69 @@ defmodule Pleroma.Repo.Migrations.ChangeObjectIdToFlake do
alter column object_id set data type uuid using cast( lpad( to_hex(object_id), 32, '0') as uuid),
add constraint hashtags_objects_object_id_fkey foreign key (object_id) references objects(id) on delete cascade
""")
+
+ flush()
+
+ stop_clippy_heartbeats(clippy)
end
def down do
- :ok
+ raise "This migration can't be reversed"
+ end
+
+ defp start_clippy_heartbeats() do
+ count = from(o in "objects", select: count(o.id)) |> Repo.one!()
+
+ if count > 5000 do
+ heartbeat_interval = :timer.minutes(2) + :timer.seconds(30)
+
+ all_tips =
+ Clippy.tips() ++
+ [
+ "The migration is still running, maybe it's time for another “tea”?",
+ "Happy rabbits practice a cute behavior known as a\n“binky:” they jump up in the air\nand twist\nand spin around!",
+ "Nothing and everything.\n\nI still work.",
+ "Pleroma runs on a Raspberry Pi!\n\n … but this migration will take forever if you\nactually run on a raspberry pi",
+ "Status? Stati? Post? Note? Toot?\nRepeat? Reboost? Boost? Retweet? Retoot??\n\nI-I'm confused."
+ ]
+
+ heartbeat = fn heartbeat, runs, all_tips, tips ->
+ tips =
+ if Integer.is_even(runs) do
+ tips = if tips == [], do: all_tips, else: tips
+ [tip | tips] = Enum.shuffle(tips)
+ Clippy.puts(tip)
+ tips
+ else
+ IO.puts(
+ "\n -- #{DateTime.to_string(DateTime.utc_now())} Migration still running, please wait…\n"
+ )
+
+ tips
+ end
+
+ :timer.sleep(heartbeat_interval)
+ heartbeat.(heartbeat, runs + 1, all_tips, tips)
+ end
+
+ Clippy.puts([
+ [:red, :bright, "It looks like you are running an older instance!"],
+ [""],
+ [:bright, "This migration may take a long time", :reset, " -- so you probably should"],
+ ["go drink a cofe, or a tea, or a beer, a whiskey, a vodka,"],
+ ["while it runs to deal with your temporary fediverse pause!"]
+ ])
+
+ :timer.sleep(heartbeat_interval)
+ spawn_link(fn -> heartbeat.(heartbeat, 1, all_tips, []) end)
+ end
+ end
+
+ defp stop_clippy_heartbeats(pid) do
+ if pid do
+ Process.unlink(pid)
+ Process.exit(pid, :kill)
+ Clippy.puts([[:green, :bright, "Hurray!!", "", "", "Migration completed!"]])
+ end
end
end
diff --git a/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs b/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs
index 71bca1cbe..eeec9dbfb 100644
--- a/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs
+++ b/priv/repo/migrations/20211218181640_resolve_activity_object_conflicts.exs
@@ -4,7 +4,9 @@ defmodule Pleroma.Repo.Migrations.ResolveActivityObjectConflicts do
This should only happen on servers that existed before "20181218172826_users_and_activities_flake_id".
"""
use Ecto.Migration
+ require Integer
+ alias Pleroma.Clippy
alias Pleroma.Object
alias Pleroma.MigrationHelper.ObjectId
alias Pleroma.Repo
@@ -12,6 +14,8 @@ defmodule Pleroma.Repo.Migrations.ResolveActivityObjectConflicts do
import Ecto.Query
def up do
+ clippy = start_clippy_heartbeats()
+
# Lock relevant tables
execute("LOCK TABLE objects")
execute("LOCK TABLE chat_message_references")
@@ -30,6 +34,10 @@ defmodule Pleroma.Repo.Migrations.ResolveActivityObjectConflicts do
# Re-enable triggers
Repo.query!("SET session_replication_role = DEFAULT")
+
+ flush()
+
+ stop_clippy_heartbeats(clippy)
end
# Get only objects with a conflicting activity ID.
@@ -46,4 +54,60 @@ defmodule Pleroma.Repo.Migrations.ResolveActivityObjectConflicts do
def down do
:ok
end
+
+ defp start_clippy_heartbeats() do
+ count = from(o in "objects", select: count(o.id)) |> Repo.one!()
+
+ if count > 5000 do
+ heartbeat_interval = :timer.minutes(2) + :timer.seconds(30)
+
+ all_tips =
+ Clippy.tips() ++
+ [
+ "The migration is still running, maybe it's time for another “tea”?",
+ "Happy rabbits practice a cute behavior known as a\n“binky:” they jump up in the air\nand twist\nand spin around!",
+ "Nothing and everything.\n\nI still work.",
+ "Pleroma runs on a Raspberry Pi!\n\n … but this migration will take forever if you\nactually run on a raspberry pi",
+ "Status? Stati? Post? Note? Toot?\nRepeat? Reboost? Boost? Retweet? Retoot??\n\nI-I'm confused."
+ ]
+
+ heartbeat = fn heartbeat, runs, all_tips, tips ->
+ tips =
+ if Integer.is_even(runs) do
+ tips = if tips == [], do: all_tips, else: tips
+ [tip | tips] = Enum.shuffle(tips)
+ Clippy.puts(tip)
+ tips
+ else
+ IO.puts(
+ "\n -- #{DateTime.to_string(DateTime.utc_now())} Migration still running, please wait…\n"
+ )
+
+ tips
+ end
+
+ :timer.sleep(heartbeat_interval)
+ heartbeat.(heartbeat, runs + 1, all_tips, tips)
+ end
+
+ Clippy.puts([
+ [:red, :bright, "It looks like you are running an older instance!"],
+ [""],
+ [:bright, "This migration may take a long time", :reset, " -- so you probably should"],
+ ["go drink a cofe, or a tea, or a beer, a whiskey, a vodka,"],
+ ["while it runs to deal with your temporary fediverse pause!"]
+ ])
+
+ :timer.sleep(heartbeat_interval)
+ spawn_link(fn -> heartbeat.(heartbeat, 1, all_tips, []) end)
+ end
+ end
+
+ defp stop_clippy_heartbeats(pid) do
+ if pid do
+ Process.unlink(pid)
+ Process.exit(pid, :kill)
+ Clippy.puts([[:green, :bright, "Hurray!!", "", "", "Migration completed!"]])
+ end
+ end
end
diff --git a/priv/repo/migrations/20211218181647_combine_activities_and_objects.exs b/priv/repo/migrations/20211218181647_combine_activities_and_objects.exs
index 7fabf72f3..5de82c790 100644
--- a/priv/repo/migrations/20211218181647_combine_activities_and_objects.exs
+++ b/priv/repo/migrations/20211218181647_combine_activities_and_objects.exs
@@ -1,10 +1,18 @@
defmodule Pleroma.Repo.Migrations.CombineActivitiesAndObjects do
use Ecto.Migration
+ require Integer
+
+ alias Pleroma.Clippy
+ alias Pleroma.Repo
+
+ import Ecto.Query
@function_name "update_status_visibility_counter_cache"
@trigger_name "status_visibility_counter_cache_trigger"
def up do
+ clippy = start_clippy_heartbeats()
+
# Lock both tables to avoid a running server meddling with our transaction
execute("LOCK TABLE activities")
execute("LOCK TABLE objects")
@@ -86,6 +94,10 @@ defmodule Pleroma.Repo.Migrations.CombineActivitiesAndObjects do
execute("drop function if exists thread_visibility(actor varchar, activity_id varchar)")
execute(update_thread_visibility())
+
+ flush()
+
+ stop_clippy_heartbeats(clippy)
end
def down do
@@ -156,4 +168,60 @@ defmodule Pleroma.Repo.Migrations.CombineActivitiesAndObjects do
$$ LANGUAGE plpgsql IMMUTABLE;
"""
end
+
+ defp start_clippy_heartbeats() do
+ count = from(a in "activities", select: count(a.id)) |> Repo.one!()
+
+ if count > 5000 do
+ heartbeat_interval = :timer.minutes(2) + :timer.seconds(30)
+
+ all_tips =
+ Clippy.tips() ++
+ [
+ "The migration is still running, maybe it's time for another “tea”?",
+ "Happy rabbits practice a cute behavior known as a\n“binky:” they jump up in the air\nand twist\nand spin around!",
+ "Nothing and everything.\n\nI still work.",
+ "Pleroma runs on a Raspberry Pi!\n\n … but this migration will take forever if you\nactually run on a raspberry pi",
+ "Status? Stati? Post? Note? Toot?\nRepeat? Reboost? Boost? Retweet? Retoot??\n\nI-I'm confused."
+ ]
+
+ heartbeat = fn heartbeat, runs, all_tips, tips ->
+ tips =
+ if Integer.is_even(runs) do
+ tips = if tips == [], do: all_tips, else: tips
+ [tip | tips] = Enum.shuffle(tips)
+ Clippy.puts(tip)
+ tips
+ else
+ IO.puts(
+ "\n -- #{DateTime.to_string(DateTime.utc_now())} Migration still running, please wait…\n"
+ )
+
+ tips
+ end
+
+ :timer.sleep(heartbeat_interval)
+ heartbeat.(heartbeat, runs + 1, all_tips, tips)
+ end
+
+ Clippy.puts([
+ [:red, :bright, "It looks like you are running an older instance!"],
+ [""],
+ [:bright, "This migration may take a long time", :reset, " -- so you probably should"],
+ ["go drink a cofe, or a tea, or a beer, a whiskey, a vodka,"],
+ ["while it runs to deal with your temporary fediverse pause!"]
+ ])
+
+ :timer.sleep(heartbeat_interval)
+ spawn_link(fn -> heartbeat.(heartbeat, 1, all_tips, []) end)
+ end
+ end
+
+ defp stop_clippy_heartbeats(pid) do
+ if pid do
+ Process.unlink(pid)
+ Process.exit(pid, :kill)
+ Clippy.puts([[:green, :bright, "Hurray!!", "", "", "Migration completed!"]])
+ end
+ end
end