# typed: true
class CreateDomainFaUserFactorsTable < ActiveRecord::Migration[7.0]
  def up
    create_table :domain_fa_user_factors do |t|
      t.references :user, index: { unique: true }, null: false
      t.vector :for_follower, limit: 32
      t.vector :for_followed, limit: 32
      t.timestamps
    end

    add_index :domain_fa_user_factors,
              :for_follower,
              using: :ivfflat,
              opclass: :vector_l2_ops
    add_index :domain_fa_user_factors,
              :for_followed,
              using: :ivfflat,
              opclass: :vector_l2_ops
    add_foreign_key :domain_fa_user_factors,
                    :domain_fa_users,
                    column: :user_id,
                    primary_key: :id,
                    validate: true
  end

  def down
    drop_table :domain_fa_user_factors
  end
end
