888 B · text History 6ccfeee
defmodule OhMyExOhIrcd.Repo.Migrations.CreateScrobbleTokens do
  use Ecto.Migration

  def change do
    create table(:scrobble_tokens) do
      add :channel_id, references(:channels, on_delete: :delete_all), null: false
      # The account this token is bound to; the announced identity is
      # derived from the token, never from the request body.
      add :user_id, references(:users, on_delete: :delete_all), null: false
      add :token_hash, :binary, null: false
      # Display name shown in announcements, fixed at mint time.
      add :who, :string, null: false
      add :label, :string
      add :last_used_at, :utc_datetime
      add :revoked_at, :utc_datetime

      timestamps(type: :utc_datetime)
    end

    create unique_index(:scrobble_tokens, [:token_hash])
    create index(:scrobble_tokens, [:channel_id])
    create index(:scrobble_tokens, [:user_id])
  end
end