total rebase
[anni] / priv / repo / migrations / 20230422154018_drop_unused_indexes.exs
1 defmodule Pleroma.Repo.Migrations.DropUnusedIndexes do
2   use Ecto.Migration
3
4   @disable_ddl_transaction true
5   @disable_migration_lock true
6
7   def up do
8     drop_if_exists(
9       index(:activities, ["(data->>'actor')", "inserted_at desc"], name: :activities_actor_index)
10     )
11
12     drop_if_exists(index(:activities, ["(data->'to')"], name: :activities_to_index))
13
14     drop_if_exists(index(:activities, ["(data->'cc')"], name: :activities_cc_index))
15
16     drop_if_exists(index(:activities, ["(split_part(actor, '/', 3))"], name: :activities_hosts))
17
18     drop_if_exists(
19       index(:activities, ["(data->'object'->>'inReplyTo')"], name: :activities_in_reply_to)
20     )
21
22     drop_if_exists(
23       index(:activities, ["((data #> '{\"object\",\"likes\"}'))"], name: :activities_likes)
24     )
25   end
26
27   def down do
28     create_if_not_exists(
29       index(:activities, ["(data->>'actor')", "inserted_at desc"],
30         name: :activities_actor_index,
31         concurrently: true
32       )
33     )
34
35     create_if_not_exists(
36       index(:activities, ["(data->'to')"],
37         name: :activities_to_index,
38         using: :gin,
39         concurrently: true
40       )
41     )
42
43     create_if_not_exists(
44       index(:activities, ["(data->'cc')"],
45         name: :activities_cc_index,
46         using: :gin,
47         concurrently: true
48       )
49     )
50
51     create_if_not_exists(
52       index(:activities, ["(split_part(actor, '/', 3))"],
53         name: :activities_hosts,
54         concurrently: true
55       )
56     )
57
58     create_if_not_exists(
59       index(:activities, ["(data->'object'->>'inReplyTo')"],
60         name: :activities_in_reply_to,
61         concurrently: true
62       )
63     )
64
65     create_if_not_exists(
66       index(:activities, ["((data #> '{\"object\",\"likes\"}'))"],
67         name: :activities_likes,
68         using: :gin,
69         concurrently: true
70       )
71     )
72   end
73 end