defmodule WandererApp.Repo.Migrations.MapSystemsChains 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_system_v1, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
      add :solar_system_id, :bigint, null: false
      add :name, :text, null: false
      add :custom_name, :text
      add :description, :text
      add :tag, :text
      add :labels, :text
      add :status, :bigint, default: 0
      add :visible, :boolean, default: true
      add :locked, :boolean, default: true
      add :position_x, :bigint, default: 0
      add :position_y, :bigint, default: 0
      add :added_at, :utc_datetime

      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_system_v1_map_id_fkey",
            type: :uuid,
            prefix: "public"
          )
    end

    create table(:map_chain_v1, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
      add :solar_system_source, :bigint
      add :solar_system_target, :bigint
      add :mass_status, :bigint, default: 0
      add :time_status, :bigint, default: 0
      add :ship_size_type, :bigint, default: 1
      add :wormhole_type, :text
      add :count_of_passage, :bigint, default: 0

      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_chain_v1_map_id_fkey",
            type: :uuid,
            prefix: "public"
          )
    end
  end

  def down do
    drop constraint(:map_chain_v1, "map_chain_v1_map_id_fkey")

    drop table(:map_chain_v1)

    drop constraint(:map_system_v1, "map_system_v1_map_id_fkey")

    drop table(:map_system_v1)
  end
end
