Module: Neighbor::MySQL

Defined in:
lib/neighbor/mysql.rb

Defined Under Namespace

Modules: RegisterTypes

Class Method Summary collapse

Class Method Details

.initialize!Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/neighbor/mysql.rb', line 3

def self.initialize!
  require_relative "type/mysql_vector"

  require "active_record/connection_adapters/abstract_mysql_adapter"

  # ensure schema can be dumped
  ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::NATIVE_DATABASE_TYPES[:vector] = {name: "vector"}

  # ensure schema can be loaded
  unless ActiveRecord::ConnectionAdapters::TableDefinition.method_defined?(:vector)
    ActiveRecord::ConnectionAdapters::TableDefinition.send(:define_column_methods, :vector)
  end

  # prevent unknown OID warning
  ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.singleton_class.prepend(RegisterTypes)
  if ActiveRecord::VERSION::STRING.to_f < 7.1
    ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.register_vector_type(ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::TYPE_MAP)
  end
end