defmodule WandererApp.Repo.Migrations.CreateMapDefaultSettingsOnly 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_default_settings, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
      add :settings, :text, 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 :map_id,
          references(:maps_v1, column: :id, name: "map_default_settings_map_id_fkey", type: :uuid),
          null: false

      add :created_by_id,
          references(:character_v1,
            column: :id,
            name: "map_default_settings_created_by_id_fkey",
            type: :uuid
          )

      add :updated_by_id,
          references(:character_v1,
            column: :id,
            name: "map_default_settings_updated_by_id_fkey",
            type: :uuid
          )
    end

    create unique_index(:map_default_settings, [:map_id],
             name: "map_default_settings_unique_map_settings_index"
           )
  end

  def down do
    drop_if_exists unique_index(:map_default_settings, [:map_id],
                     name: "map_default_settings_unique_map_settings_index"
                   )

    drop constraint(:map_default_settings, "map_default_settings_map_id_fkey")

    drop constraint(:map_default_settings, "map_default_settings_created_by_id_fkey")

    drop constraint(:map_default_settings, "map_default_settings_updated_by_id_fkey")

    drop table(:map_default_settings)
  end
end
