Skip to content

Commit

Permalink
Add ability to set the TableDefinition class.
Browse files Browse the repository at this point in the history
The table definition class can be set via passing
in `:table_definition_class_name` as a connection
parameter.

This is specifically useful when the default 
table definition does not support the column types
in the schema.rb. Specifically, passing in
`ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition`
allows column types such as `json` to exist in the
schema.
  • Loading branch information
Michael Pearce committed Mar 2, 2018
1 parent c1ea802 commit 9f3c7a1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/active_record/connection_adapters/nulldb_adapter/core.rb
Expand Up @@ -15,6 +15,8 @@ def self.insinuate_into_spec(config)
# Recognized options:
#
# [+:schema+] path to the schema file, relative to Rails.root
# [+:table_definition_class_name+] table definition class
# (e.g. ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition for Postgres) or nil.
def initialize(config={})
@log = StringIO.new
@logger = Logger.new(@log)
Expand All @@ -25,6 +27,12 @@ def initialize(config={})
@config = config.merge(:adapter => :nulldb)
super *initialize_args
@visitor ||= Arel::Visitors::ToSql.new self if defined?(Arel::Visitors::ToSql)

if config[:table_definition_class_name]
ActiveRecord::ConnectionAdapters::NullDBAdapter.send(:remove_const, 'TableDefinition')
ActiveRecord::ConnectionAdapters::NullDBAdapter.const_set('TableDefinition',
self.class.const_get(config[:table_definition_class_name]))
end
end

# A log of every statement that has been "executed" by this connection adapter
Expand Down

0 comments on commit 9f3c7a1

Please sign in to comment.