From 9f3c7a12a531c3c8cbad19f3da4257e58fc6a6a1 Mon Sep 17 00:00:00 2001 From: Michael Pearce Date: Thu, 1 Mar 2018 19:05:39 -0800 Subject: [PATCH] Add ability to set the TableDefinition class. 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. --- .../connection_adapters/nulldb_adapter/core.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/active_record/connection_adapters/nulldb_adapter/core.rb b/lib/active_record/connection_adapters/nulldb_adapter/core.rb index 4a052b1..ed05550 100644 --- a/lib/active_record/connection_adapters/nulldb_adapter/core.rb +++ b/lib/active_record/connection_adapters/nulldb_adapter/core.rb @@ -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) @@ -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