defmodule Animina.Repo.Migrations.MigrateResources15 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(:users) do
      modify :is_private, :boolean, default: nil
      modify :last_registration_page_visited, :text, default: nil
      modify :preapproved_communication_only, :boolean, default: nil
      modify :legal_terms_accepted, :boolean, default: nil
      modify :mobile_phone, :text, null: true
      modify :height, :bigint, null: true
      modify :gender, :text, null: true
      modify :country, :text, null: true
      modify :birthday, :date, null: true
      modify :name, :text, null: true
      modify :username, :citext, null: true
      modify :email, :citext, null: true
      add :roles, {:array, :map}
      add :city, :map
      add :profile_photo, :map
      add :credit_points, :bigserial
    end

    alter table(:stories) do
      modify :position, :bigint, null: true
      add :user, :map
      add :photo, :map
      add :headline, :map
    end

    alter table(:photos) do
      add :tagged, :boolean, default: false
    end
  end

  def down do
    alter table(:photos) do
      remove :tagged
    end

    alter table(:stories) do
      remove :headline
      remove :photo
      remove :user
      modify :position, :bigint, null: false
    end

    alter table(:users) do
      remove :credit_points
      remove :profile_photo
      remove :city
      remove :roles
      modify :email, :citext, null: false
      modify :username, :citext, null: false
      modify :name, :text, null: false
      modify :birthday, :date, null: false
      modify :country, :text, null: false
      modify :gender, :text, null: false
      modify :height, :bigint, null: false
      modify :mobile_phone, :text, null: false
      modify :legal_terms_accepted, :boolean, default: false
      modify :preapproved_communication_only, :boolean, default: false
      modify :last_registration_page_visited, :text, default: "/my/potential-partner"
      modify :is_private, :boolean, default: false
    end
  end
end
