defmodule WandererApp.Repo.Migrations.AddAccessLists 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(:access_lists_v1, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
      add :name, :text, null: false
      add :description, :text

      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 :owner_id,
          references(:character_v1,
            column: :id,
            name: "access_lists_v1_owner_id_fkey",
            type: :uuid,
            prefix: "public"
          )
    end

    create table(:access_list_members_v1, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
      add :name, :text, null: false
      add :eve_character_id, :text
      add :eve_corporation_id, :text
      add :eve_alliance_id, :text
      add :role, :text, null: false, default: "member"

      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 :access_list_id,
          references(:access_lists_v1,
            column: :id,
            name: "access_list_members_v1_access_list_id_fkey",
            type: :uuid,
            prefix: "public"
          )
    end
  end

  def down do
    drop constraint(:access_list_members_v1, "access_list_members_v1_access_list_id_fkey")

    drop table(:access_list_members_v1)

    drop constraint(:access_lists_v1, "access_lists_v1_owner_id_fkey")

    drop table(:access_lists_v1)
  end
end
