summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20190516112144_add_ap_id_to_lists.exs
blob: 3c32bc355d82c41b585c44ccd68dd6634af9aba1 (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
defmodule Pleroma.Repo.Migrations.AddApIdToLists do
  use Ecto.Migration

  def up do
    alter table(:lists) do
      add(:ap_id, :string)
    end

    execute("""
    UPDATE lists
    SET ap_id = u.ap_id || '/lists/' || lists.id
    FROM users AS u
    WHERE lists.user_id = u.id
    """)

    create(unique_index(:lists, :ap_id))
  end

  def down do
    drop(index(:lists, [:ap_id]))

    alter table(:lists) do
      remove(:ap_id)
    end
  end
end