defmodule Officetournament.Repo.Migrations.CreateMembership do
  use Ecto.Migration

  def change do
    create table(:memberships) do
      add :user_id, references(:users)
      add :league_id, references(:leagues)

      timestamps
    end

    create unique_index(:memberships, [:user_id, :league_id])

  end
end

defmodule Officetournament.Repo.Migrations.CreateMembership do
  use Ecto.Migration

  def change do
    create table(:memberships) do
      add :user_id, references(:users, on_delete: :delete_all)
      add :league_id, references(:leagues, on_delete: :delete_all)

      timestamps
    end

    create unique_index(:memberships, [:user_id, :league_id])

  end
end

Remove memberships when a user is deleted
Remove memberships when a user is deleted

X0nic/officetournament,X0nic/officetournament