# SPDX-FileCopyrightText: 2020 Zach Daniel
#
# SPDX-License-Identifier: MIT

defmodule AshPostgres.TestRepo.Migrations.AddComplexCalculationsChannels 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(:complex_calculations_channels, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true
      add :created_at, :utc_datetime_usec, null: false, default: fragment("now()")
      add :updated_at, :utc_datetime_usec, null: false, default: fragment("now()")
    end

    create table(:complex_calculations_certifications_channel_members, primary_key: false) do
      add :id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true
      add :created_at, :utc_datetime_usec, null: false, default: fragment("now()")
      add :updated_at, :utc_datetime_usec, null: false, default: fragment("now()")

      add :user_id,
          references(:users,
            column: :id,
            name: "complex_calculations_certifications_channel_members_user_id_fkey",
            type: :uuid,
            prefix: "public"
          )

      add :channel_id,
          references(:complex_calculations_channels,
            column: :id,
            name: "complex_calculations_certifications_channel_members_channel_id_fkey",
            type: :uuid,
            prefix: "public"
          )
    end
  end

  def down do
    drop constraint(
           :complex_calculations_certifications_channel_members,
           "complex_calculations_certifications_channel_members_user_id_fkey"
         )

    drop constraint(
           :complex_calculations_certifications_channel_members,
           "complex_calculations_certifications_channel_members_channel_id_fkey"
         )

    drop table(:complex_calculations_certifications_channel_members)

    drop table(:complex_calculations_channels)
  end
end