summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20200328124805_change_following_relationships_state_to_integer.exs
blob: 7729f8a9f4b2b25c16509d67408112a47f0a1139 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Repo.Migrations.ChangeFollowingRelationshipsStateToInteger do
  use Ecto.Migration

  @alter_following_relationship_state "ALTER TABLE following_relationships ALTER COLUMN state"

  def up do
    execute("""
    #{@alter_following_relationship_state} TYPE integer USING
    CASE
      WHEN state = 'pending' THEN 1
      WHEN state = 'accept' THEN 2
      WHEN state = 'reject' THEN 3
      ELSE 0
    END;
    """)
  end

  def down do
    execute("""
    #{@alter_following_relationship_state} TYPE varchar(255) USING
    CASE
      WHEN state = 1 THEN 'pending'
      WHEN state = 2 THEN 'accept'
      WHEN state = 3 THEN 'reject'
      ELSE ''
    END;
    """)
  end
end