defmodule Chklst.Repo.Migrations.CreateUsersOrgs do
  use Ecto.Migration

  def change do
    create table(:users_orgs, primary_key: false) do
      add :user_id, references(:users, on_delete: :nothing, type: :binary_id)
      add :org_id, references(:orgs, on_delete: :nothing, type: :binary_id)

      timestamps(type: :utc_datetime)
    end

    create index(:users_orgs, [:user_id])
    create index(:users_orgs, [:org_id])
    create unique_index(:users_orgs, [:org_id, :user_id])
  end
end