activerecord-cockroachdb-adapter 5.2.2 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef8a3ba83448f71d7a2d0e5a4d21f065531f17a862aa8a33e7ed4e9470927f0a
4
- data.tar.gz: ae23824599ad3bc37773f99e08a143b7242e81094098674d22499df7153c5856
3
+ metadata.gz: a28ccd96cddcfaf334a3a854f8312a754e11b3a610ce338e53465abc567dcd71
4
+ data.tar.gz: 37ea9e0cb5d202128a46fbeb97fce75a9ef6aa8ae8043fc2c1f11fc38ae01ff1
5
5
  SHA512:
6
- metadata.gz: 4100c35b51262901f1f087be1d0a5b4864f45a89585878e5d00aa12919863cdc66cd8ffddfcd0f3b16037bd6b21539845ddbe18c7901fd2f48f7d7e807f61f0b
7
- data.tar.gz: accca94dcb97b512e261a676d031657c8cc34d22590866744ffd6dbaf757a67386d9c642638d77aa4354d5281437e7a5e8c5c5dc141335f441422e20a3605aee
6
+ metadata.gz: 2a3a26fe9bbd9043bbbcd50b1c262cdc88bfded513b8f4d1fb2488d0a76cc9943c8201c082f6a6a5c65123801ad3fa10851ff708e771f3be9b07b53464ed4ae5
7
+ data.tar.gz: f5e123cce6d782b4427b4e97066cd874b9539a4a7de78d122ed46672326864bf4640aa3a9810b506f3bd307e6a1ff2fdf9447f2e215a391022350e023c41278d
data/README.md CHANGED
@@ -7,7 +7,7 @@ CockroachDB adapter for ActiveRecord 4 and 5. This is a lightweight extension of
7
7
  Add this line to your project's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'activerecord-cockroachdb-adapter', '~> 5.2.0'
10
+ gem 'activerecord-cockroachdb-adapter', '~> 5.2'
11
11
  ```
12
12
 
13
13
  If you're using Rails 4.x, use the `0.1.x` versions of this gem.
@@ -21,6 +21,11 @@ development:
21
21
  host: <hostname>
22
22
  user: <username>
23
23
  ```
24
+ ## Configuration
25
+
26
+ In addition to the standard adapter settings, CockroachDB also supports the following:
27
+
28
+ - `disable_cockroachdb_telemetry`: Determines if a telemetry call is made to the database when the connection pool is initialized. Setting this to `true` will prevent the call from being made.
24
29
 
25
30
  ## Working with Spatial Data
26
31
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "activerecord-cockroachdb-adapter"
7
- spec.version = "5.2.2"
7
+ spec.version = "5.2.3"
8
8
  spec.licenses = ["Apache-2.0"]
9
9
  spec.authors = ["Cockroach Labs"]
10
10
  spec.email = ["cockroach-db@googlegroups.com"]
@@ -11,6 +11,7 @@ connections:
11
11
  user: root
12
12
  requiressl: disable
13
13
  min_messages: warning
14
+ disable_cockroachdb_telemetry: true
14
15
  arunit_without_prepared_statements:
15
16
  database: activerecord_unittest
16
17
  host: localhost
@@ -19,6 +20,7 @@ connections:
19
20
  requiressl: disable
20
21
  min_messages: warning
21
22
  prepared_statements: false
23
+ disable_cockroachdb_telemetry: true
22
24
  arunit2:
23
25
  database: activerecord_unittest2
24
26
  host: localhost
@@ -26,3 +28,4 @@ connections:
26
28
  user: root
27
29
  requiressl: disable
28
30
  min_messages: warning
31
+ disable_cockroachdb_telemetry: true
@@ -40,12 +40,49 @@ module ActiveRecord
40
40
  # PG::Connection object, so just pass a nil connection object for the
41
41
  # time being.
42
42
  ConnectionAdapters::CockroachDBAdapter.new(nil, logger, conn_params, config)
43
+ # This rescue flow appears in new_client, but it is needed here as well
44
+ # since Cockroach will sometimes not raise until a query is made.
45
+ rescue ActiveRecord::StatementInvalid => error
46
+ if conn_params && conn_params[:dbname] && error.cause.message.include?(conn_params[:dbname])
47
+ raise ActiveRecord::NoDatabaseError, error.cause.message
48
+ else
49
+ raise ActiveRecord::ConnectionNotEstablished, error.message
50
+ end
43
51
  end
44
52
  end
45
53
  end
46
54
 
47
55
  module ActiveRecord
48
56
  module ConnectionAdapters
57
+ module CockroachDBConnectionPool
58
+ def initialize(pool_config)
59
+ super(pool_config)
60
+ disable_telemetry = pool_config.config[:disable_cockroachdb_telemetry]
61
+ adapter = pool_config.config[:adapter]
62
+ return if disable_telemetry || adapter != "cockroachdb"
63
+
64
+
65
+ begin
66
+ with_connection do |conn|
67
+ if conn.active?
68
+ begin
69
+ query = "SELECT crdb_internal.increment_feature_counter('ActiveRecord %d.%d')"
70
+ conn.execute(query % [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR])
71
+ rescue ActiveRecord::StatementInvalid
72
+ # The increment_feature_counter built-in is not supported on this
73
+ # CockroachDB version. Ignore.
74
+ rescue StandardError => e
75
+ conn.logger.warn "Unexpected error when incrementing feature counter: #{e}"
76
+ end
77
+ end
78
+ end
79
+ rescue StandardError
80
+ # Prevent failures on db creation and parallel testing.
81
+ end
82
+ end
83
+ end
84
+ ConnectionPool.prepend(CockroachDBConnectionPool)
85
+
49
86
  class CockroachDBAdapter < PostgreSQLAdapter
50
87
  ADAPTER_NAME = "CockroachDB".freeze
51
88
  DEFAULT_PRIMARY_KEY = "rowid"
@@ -216,6 +253,10 @@ module ActiveRecord
216
253
  @crdb_version >= 202
217
254
  end
218
255
 
256
+ def supports_partitioned_indexes?
257
+ false
258
+ end
259
+
219
260
  # This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
220
261
  # migration from PostgreSQL to CockroachDB. In practice, this limitation
221
262
  # is arbitrary since CockroachDB supports index name lengths and table alias
@@ -233,6 +274,7 @@ module ActiveRecord
233
274
 
234
275
  def initialize(connection, logger, conn_params, config)
235
276
  super(connection, logger, conn_params, config)
277
+
236
278
  crdb_version_string = query_value("SHOW crdb_version")
237
279
  if crdb_version_string.include? "v1."
238
280
  version_num = 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cockroachdb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.2
4
+ version: 5.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cockroach Labs
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-13 00:00:00.000000000 Z
11
+ date: 2021-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -97,7 +97,7 @@ licenses:
97
97
  - Apache-2.0
98
98
  metadata:
99
99
  allowed_push_host: https://rubygems.org
100
- post_install_message:
100
+ post_install_message:
101
101
  rdoc_options: []
102
102
  require_paths:
103
103
  - lib
@@ -112,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubygems_version: 3.0.3
116
- signing_key:
115
+ rubygems_version: 3.2.15
116
+ signing_key:
117
117
  specification_version: 4
118
118
  summary: CockroachDB adapter for ActiveRecord.
119
119
  test_files: []