move to 2.5.5
[anni] / priv / repo / migrations / 20200328124805_change_following_relationships_state_to_integer.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.ChangeFollowingRelationshipsStateToInteger do
6   use Ecto.Migration
7
8   @alter_following_relationship_state "ALTER TABLE following_relationships ALTER COLUMN state"
9
10   def up do
11     execute("""
12     #{@alter_following_relationship_state} TYPE integer USING
13     CASE
14       WHEN state = 'pending' THEN 1
15       WHEN state = 'accept' THEN 2
16       WHEN state = 'reject' THEN 3
17       ELSE 0
18     END;
19     """)
20   end
21
22   def down do
23     execute("""
24     #{@alter_following_relationship_state} TYPE varchar(255) USING
25     CASE
26       WHEN state = 1 THEN 'pending'
27       WHEN state = 2 THEN 'accept'
28       WHEN state = 3 THEN 'reject'
29       ELSE ''
30     END;
31     """)
32   end
33 end