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

      add :map_id,
          references(:maps_v1,
            column: :id,
            name: "map_user_settings_v1_map_id_fkey",
            type: :uuid,
            prefix: "public"
          ),
          primary_key: true,
          null: false

      add :user_id,
          references(:user_v1,
            column: :id,
            name: "map_user_settings_v1_user_id_fkey",
            type: :uuid,
            prefix: "public"
          ),
          primary_key: true,
          null: false
    end

    create unique_index(:map_user_settings_v1, [:map_id, :user_id],
             name: "map_user_settings_v1_uniq_map_user_index"
           )
  end

  def down do
    drop_if_exists unique_index(:map_user_settings_v1, [:map_id, :user_id],
                     name: "map_user_settings_v1_uniq_map_user_index"
                   )

    drop constraint(:map_user_settings_v1, "map_user_settings_v1_map_id_fkey")

    drop constraint(:map_user_settings_v1, "map_user_settings_v1_user_id_fkey")

    drop table(:map_user_settings_v1)
  end
end
