defmodule GitGud.Repo.Migrations.CreatePinnedRepositories do
use Ecto.Migration
def change do
create table(:pinned_repositories) do
add :owner_id, references(:users, on_delete: :delete_all)
add :organization_id, references(:organizations, on_delete: :delete_all)
add :repository_id, references(:repositories, on_delete: :delete_all), null: false
add :position, :integer, null: false, default: 0
timestamps(type: :utc_datetime)
end
create constraint(:pinned_repositories, :owner_xor_org,
check: "(owner_id IS NOT NULL) <> (organization_id IS NOT NULL)"
)
create unique_index(:pinned_repositories, [:owner_id, :repository_id],
where: "owner_id IS NOT NULL"
)
create unique_index(:pinned_repositories, [:organization_id, :repository_id],
where: "organization_id IS NOT NULL"
)
create index(:pinned_repositories, [:owner_id, :position],
where: "owner_id IS NOT NULL"
)
create index(:pinned_repositories, [:organization_id, :position],
where: "organization_id IS NOT NULL"
)
end
end
1.1 KiB · text
5af55d9