Sha256: 61fec5ddd77bd5e5049000005139037e3782ee173c2d84a0aec0b69b1ddab532

Contents?: true

Size: 762 Bytes

Versions: 9

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

require "active_record"

# 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", "sqlite") == "mysql"
  end

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

PatchAdapter.new.call

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gutentag-2.6.2 spec/support/mysql.rb
gutentag-2.6.1 spec/support/mysql.rb
gutentag-2.6.0 spec/support/mysql.rb
gutentag-2.5.4 spec/support/mysql.rb
gutentag-2.5.3 spec/support/mysql.rb
gutentag-2.5.2 spec/support/mysql.rb
gutentag-2.5.1 spec/support/mysql.rb
gutentag-2.5.0 spec/support/mysql.rb
gutentag-2.4.1 spec/support/mysql.rb