db973ea1c060e2f227545dbc69d34b250af6edc5
[anni] / priv / repo / migrations / 20190516112144_add_ap_id_to_lists.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.AddApIdToLists do
6   use Ecto.Migration
7
8   def up do
9     alter table(:lists) do
10       add(:ap_id, :string)
11     end
12
13     execute("""
14     UPDATE lists
15     SET ap_id = u.ap_id || '/lists/' || lists.id
16     FROM users AS u
17     WHERE lists.user_id = u.id
18     """)
19
20     create(unique_index(:lists, :ap_id))
21   end
22
23   def down do
24     drop(index(:lists, [:ap_id]))
25
26     alter table(:lists) do
27       remove(:ap_id)
28     end
29   end
30 end