defmodule Orcasite.Repo.Migrations.AddUserAndToken do
  @moduledoc """
  Updates resources based on their most recent snapshots.

  This file was autogenerated with `mix ash_postgres.generate_migrations`
  """

  use Ecto.Migration

  def up do
    drop_if_exists table(:users)

    create table(:users, primary_key: false) do
      add :id, :uuid, null: false, primary_key: true, default: fragment("uuid_generate_v4()")
      add :email, :citext, null: false
      add :hashed_password, :text, null: false
      add :first_name, :text
      add :last_name, :text
      add :admin, :boolean
      add :inserted_at, :utc_datetime_usec, null: false, default: fragment("now()")
      add :updated_at, :utc_datetime_usec, null: false, default: fragment("now()")
    end

    create unique_index(:users, [:email], name: "users_unique_email_index")

    create table(:subscriber_tokens, primary_key: false) do
      add :updated_at, :utc_datetime_usec, null: false, default: fragment("now()")
      add :created_at, :utc_datetime_usec, null: false, default: fragment("now()")
      add :extra_data, :map
      add :purpose, :text, null: false
      add :expires_at, :utc_datetime, null: false
      add :subject, :text, null: false
      add :jti, :text, null: false, primary_key: true
    end
  end

  def down do
    drop table(:account_tokens)

    drop table(:subscriber_tokens)

    drop_if_exists unique_index(:users, [:email], name: "users_unique_email_index")

    drop table(:users)
  end
end
