# SPDX-FileCopyrightText: 2022 Alembic Pty Ltd
#
# SPDX-License-Identifier: MIT

defmodule Example.Repo.Migrations.UpdateTimestampDefaults 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
    alter table(:user_with_token_required) do
      modify(:updated_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
      modify(:created_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
      modify(:id, :uuid, default: fragment("gen_random_uuid()"))
    end

    alter table(:user_identities) do
      modify(:id, :uuid, default: fragment("gen_random_uuid()"))
    end

    alter table(:user) do
      modify(:updated_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
      modify(:created_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
      modify(:id, :uuid, default: fragment("gen_random_uuid()"))
    end

    alter table(:tokens) do
      modify(:created_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
      modify(:updated_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
    end
  end

  def down do
    alter table(:tokens) do
      modify(:updated_at, :utc_datetime_usec, default: fragment("now()"))
      modify(:created_at, :utc_datetime_usec, default: fragment("now()"))
    end

    alter table(:user) do
      modify(:id, :uuid, default: fragment("uuid_generate_v4()"))
      modify(:created_at, :utc_datetime_usec, default: fragment("now()"))
      modify(:updated_at, :utc_datetime_usec, default: fragment("now()"))
    end

    alter table(:user_identities) do
      modify(:id, :uuid, default: fragment("uuid_generate_v4()"))
    end

    alter table(:user_with_token_required) do
      modify(:id, :uuid, default: fragment("uuid_generate_v4()"))
      modify(:created_at, :utc_datetime_usec, default: fragment("now()"))
      modify(:updated_at, :utc_datetime_usec, default: fragment("now()"))
    end
  end
end
