# typed: strict
class AddTypeToDomainUserPostFavs < ActiveRecord::Migration[7.2]
  extend T::Sig

  sig { void }
  def change
    mirai_tablespace!

    create_enum(
      "domain_user_post_fav_type",
      %w[Domain::UserPostFav Domain::UserPostFav::FaUserPostFav],
    )

    change_table :domain_user_post_favs do |t|
      t.enum :type,
             null: false,
             enum_type: "domain_user_post_fav_type",
             default: "Domain::UserPostFav"

      t.jsonb :json_attributes, default: {}
    end

    [
      ["fav_id", "integer", { unique: true }],
      %w[inferred_time integer],
      %w[explicit_time integer],
    ].each do |column_name, column_type, options|
      add_json_index(
        "domain_user_post_favs",
        column_name,
        column_type,
        { where: "type = 'Domain::UserPostFav::FaUserPostFav'" }.merge(
          options || {},
        ),
      )
    end
  end
end
