Class: ActiveRecord::Postgres::Constraints::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/active_record/postgres/constraints/railtie.rb

Instance Method Summary collapse

Instance Method Details

#apply_patch!Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_record/postgres/constraints/railtie.rb', line 16

def apply_patch!
  Rails.logger.info do
    'Applying Postgres Constraints patches to ActiveRecord'
  end
  AR_CAS::TableDefinition.include TableDefinition
  AR_CAS::PostgreSQLAdapter.include PostgreSQLAdapter
  AR_CAS::AbstractAdapter::SchemaCreation.prepend SchemaCreation

  ::ActiveRecord::Migration::CommandRecorder.include CommandRecorder
  ::ActiveRecord::SchemaDumper.prepend SchemaDumper
end

#pg?Boolean



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/active_record/postgres/constraints/railtie.rb', line 28

def pg?
  begin
    connection = ActiveRecord::Base.connection
  rescue ActiveRecord::NoDatabaseError
    Rails.logger.warn do
      'Not applying Postgres Constraints patches to ActiveRecord ' \
        'since the database does not exist'
    end
    return false
  end

  pg = connection.class.to_s == "#{AR_CAS}::PostgreSQLAdapter"
  return true if pg

  Rails.logger.warn do
    'Not applying Postgres Constraints patches to ActiveRecord ' \
      'since the database is not postgres'
  end
  false
end