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

  sig { void }
  def change
    up_only { execute "SET default_tablespace = mirai" }

    # prefix search file URLs
    add_index :domain_post_files,
              "lower((json_attributes->>'url_str')::text) text_pattern_ops",
              name: "idx_domain_post_files_on_url_str_lower"

    # suffix search file URLs
    add_index :domain_post_files,
              "reverse(lower((json_attributes->>'url_str')::text)) text_pattern_ops",
              name: "idx_domain_post_files_on_url_str_lower_reverse"

    # InkbunnyUser#name
    add_index :domain_users,
              "lower((json_attributes->>'name')::text) text_pattern_ops",
              name: "idx_domain_users_inkbunny_on_name_lower",
              where: "type = 'Domain::User::InkbunnyUser'"

    # E621User#name
    add_index :domain_users,
              "lower((json_attributes->>'name')::text) text_pattern_ops",
              name: "idx_domain_users_e621_on_name_lower",
              where: "type = 'Domain::User::E621User'"
  end
end
