Sha256: 442394f3cb5ba810e0bc6fe7d25ae12d7cc6ab3e07b2dc6384f18793c14cfe89

Contents?: true

Size: 738 Bytes

Versions: 17

Compression:

Stored size: 738 Bytes

Contents

# frozen_string_literal: true

# New versions of MySQL don't allow NULL values for primary keys, but old
# versions of Rails do. To use both at the same time, we need to update Rails'
# default primary key type to no longer have a default NULL value.
#
class PatchAdapter
  def call
    return unless using_mysql? && using_rails_pre_4_1?

    require 'active_record/connection_adapters/abstract_mysql_adapter'
    ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::
      NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
  end

  def using_mysql?
    ENV.fetch('DATABASE', 'mysql2') == 'mysql2'
  end

  def using_rails_pre_4_1?
    ActiveRecord::VERSION::STRING.to_f < 4.1
  end
end

PatchAdapter.new.call

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 spec/support/mysql.rb
thinking-sphinx-5.5.1 spec/support/mysql.rb
thinking-sphinx-5.5.0 spec/support/mysql.rb
thinking-sphinx-5.4.0 spec/support/mysql.rb
thinking-sphinx-5.3.0 spec/support/mysql.rb
thinking-sphinx-5.2.1 spec/support/mysql.rb
thinking-sphinx-5.2.0 spec/support/mysql.rb
thinking-sphinx-5.1.0 spec/support/mysql.rb
thinking-sphinx-5.0.0 spec/support/mysql.rb
thinking-sphinx-4.4.1 spec/support/mysql.rb
thinking-sphinx-4.4.0 spec/support/mysql.rb
thinking-sphinx-4.3.2 spec/support/mysql.rb
thinking-sphinx-4.3.1 spec/support/mysql.rb
thinking-sphinx-4.3.0 spec/support/mysql.rb
thinking-sphinx-4.2.0 spec/support/mysql.rb
thinking-sphinx-4.1.0 spec/support/mysql.rb
thinking-sphinx-4.0.0 spec/support/mysql.rb