Skip to content

Instantly share code, notes, and snippets.

@blimmer
Created March 21, 2018 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blimmer/1ef562ac5981dd8f65653075f16c1157 to your computer and use it in GitHub Desktop.
Save blimmer/1ef562ac5981dd8f65653075f16c1157 to your computer and use it in GitHub Desktop.
Rails Issue #30947 Workaround
# This patch is to work around this bug in Rails 5.0.x and 5.1.x
# https://github.com/rails/rails/issues/30947
# Because we use SQLite for tests and MySQL in prod, having the options hash
# containing ENGINE=InnoDB causes problems when we try to prepare the test database.
#
# Because of this, we need to remove those options from the generated schema.rb file.
# Here is the source that's setting `options`
# https://github.com/rails/rails/blob/81787a895126ead62a2859b33eccbbb74ef38892/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L561
#
# This should be removed for Rails 5.2 ++
module TableOptionsScrubber
def self.prepended(_base)
raise('Please remove the monkey patch for schema options for Rails 5.2.x') if Gem::Version.new(Rails.version) >= Gem::Version.new(5.2)
end
def table_options(table_name)
to = super
to.delete(:options)
to
end
end
if ActiveRecord::Base.is_mysql_connection?
module ActiveRecord
module ConnectionAdapters
class AbstractMysqlAdapter
prepend TableOptionsScrubber
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment