Merge branch 'following-relationships-optimizations' into 'develop'
[akkoma] / priv / repo / migrations / 20200328124805_change_following_relationships_state_to_integer.exs
1 defmodule Pleroma.Repo.Migrations.ChangeFollowingRelationshipsStateToInteger do
2 use Ecto.Migration
3
4 @alter_following_relationship_state "ALTER TABLE following_relationships ALTER COLUMN state"
5
6 def up do
7 execute("""
8 #{@alter_following_relationship_state} TYPE integer USING
9 CASE
10 WHEN state = 'pending' THEN 1
11 WHEN state = 'accept' THEN 2
12 WHEN state = 'reject' THEN 3
13 ELSE 0
14 END;
15 """)
16 end
17
18 def down do
19 execute("""
20 #{@alter_following_relationship_state} TYPE varchar(255) USING
21 CASE
22 WHEN state = 1 THEN 'pending'
23 WHEN state = 2 THEN 'accept'
24 WHEN state = 3 THEN 'reject'
25 ELSE ''
26 END;
27 """)
28 end
29 end