Module: ActiveRecord::ConnectionAdapters::CockroachDBConnectionPool

Defined in:
lib/active_record/connection_adapters/cockroachdb_adapter.rb

Instance Method Summary collapse

Instance Method Details

#initialize(pool_config) ⇒ Object

[View source]

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/active_record/connection_adapters/cockroachdb_adapter.rb', line 65

def initialize(pool_config)
  super(pool_config)
  disable_telemetry = pool_config.db_config.configuration_hash[:disable_cockroachdb_telemetry]
  adapter = pool_config.db_config.configuration_hash[:adapter]
  return if disable_telemetry || adapter != "cockroachdb"

  begin
    with_connection do |conn|
      if conn.active?
        begin
          ar_version = conn.quote("ActiveRecord %d.%d" % [ActiveRecord::VERSION::MAJOR,
                                                          ActiveRecord::VERSION::MINOR])
          ar_query = "SELECT crdb_internal.increment_feature_counter(%s)" % ar_version
          adapter_version = conn.quote("activerecord-cockroachdb-adapter #{ActiveRecord::COCKROACH_DB_ADAPTER_VERSION}")
          adapter_query = "SELECT crdb_internal.increment_feature_counter(%s)" % adapter_version

          conn.execute(ar_query)
          conn.execute(adapter_query)
        rescue ActiveRecord::StatementInvalid
          # The increment_feature_counter built-in is not supported on this
          # CockroachDB version. Ignore.
        rescue StandardError => e
          conn.logger.warn "Unexpected error when incrementing feature counter: #{e}"
        end
      end
    end
  rescue StandardError
    # Prevent failures on db creation and parallel testing.
  end
end