Rename users_ap_id_COALESCE_follower_address_index for faster db restoration
[akkoma] / priv / repo / migrations / 20230127143303_rename_index_users_ap_id_coalesce_follower_address_index.exs
1 defmodule Pleroma.Repo.Migrations.RenameIndexUsersApId_COALESCEFollowerAddressIndex do
2 alias Pleroma.Repo
3
4 use Ecto.Migration
5
6 def up do
7 # By default Postgresql first restores the data and then the indexes when dumping and restoring the database.
8 # Restoring index activities_visibility_index took a very long time.
9 # users_ap_id_COALESCE_follower_address_index was later added because having this could speed up the restoration tremendously.
10 # The problem now is that restoration apparently happens in alphabetical order, so this new index wasn't created yet
11 # by the time activities_visibility_index needed it.
12 # There were several work-arounds which included more complex steps during backup/restore.
13 # By renaming this index, it should be restored first and thus activities_visibility_index can make use of it.
14 # This speeds up restoration significantly without requiring more complex or unexpected steps from people.
15 Repo.query!("ALTER INDEX public.\"users_ap_id_COALESCE_follower_address_index\"
16 RENAME TO \"aa_users_ap_id_COALESCE_follower_address_index\";")
17 end
18
19 def down do
20 Repo.query!("ALTER INDEX public.\"aa_users_ap_id_COALESCE_follower_address_index\"
21 RENAME TO \"users_ap_id_COALESCE_follower_address_index\";")
22 end
23 end