Split CreateFollowingRelationships to multiple migrations
[akkoma] / priv / repo / migrations / 20191007073319_create_following_relationships.exs
1 defmodule Pleroma.Repo.Migrations.CreateFollowingRelationships do
2 use Ecto.Migration
3
4 # had to disable these to be able to restore `following` index concurrently
5 # https://hexdocs.pm/ecto_sql/Ecto.Migration.html#index/3-adding-dropping-indexes-concurrently
6
7 def change do
8 create_if_not_exists table(:following_relationships) do
9 add(:follower_id, references(:users, type: :uuid, on_delete: :delete_all), null: false)
10 add(:following_id, references(:users, type: :uuid, on_delete: :delete_all), null: false)
11 add(:state, :string, null: false)
12
13 timestamps()
14 end
15
16 create_if_not_exists(index(:following_relationships, :follower_id))
17 create_if_not_exists(unique_index(:following_relationships, [:follower_id, :following_id]))
18 end
19 end