defmodule Helpcenter.Repo.Migrations.AddAshParental 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
    create table(:invitations, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
      add :email, :text, null: false
      add :status, :text, null: false, default: "pending"
      add :token, :text, null: false
      add :team, :text, null: false
      add :expires_at, :utc_datetime, null: false

      add :inserted_at, :utc_datetime_usec,
        null: false,
        default: fragment("(now() AT TIME ZONE 'utc')")

      add :updated_at, :utc_datetime_usec,
        null: false,
        default: fragment("(now() AT TIME ZONE 'utc')")

      add :group_id, :uuid, null: false

      add :inviter_user_id,
          references(:users,
            column: :id,
            name: "invitations_inviter_user_id_fkey",
            type: :uuid,
            prefix: "public"
          ),
          null: false

      add :invitee_user_id,
          references(:users,
            column: :id,
            name: "invitations_invitee_user_id_fkey",
            type: :uuid,
            prefix: "public"
          )
    end
  end

  def down do
    drop constraint(:invitations, "invitations_group_id_fkey")

    drop constraint(:invitations, "invitations_inviter_user_id_fkey")

    drop constraint(:invitations, "invitations_invitee_user_id_fkey")

    drop table(:invitations)
  end
end
