activerecord-cockroachdb-adapter 6.1.0.pre.beta.3 → 6.1.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: 5bc55cc2cb9bfa57e9e0d5757aa2e4e892361b68f9f216de0627d3fc01c165dd
4
- data.tar.gz: 36582fada5f267b47c827c6b30112c8db955cac8606b3ae5d9c3f73cb77c9424
3
+ metadata.gz: c2f121de56f7c6e8cf67c486533873cf2f081ec2dbe32a6d395849ecd9f7f958
4
+ data.tar.gz: 698808276bece741fc6ec06a69e871ca482e6e69ff3b9e5e95b278619bf4ee02
5
5
  SHA512:
6
- metadata.gz: c23656edaccbd223d6573d1a3636263d779ae437b5628d657cd5ed2c0d7773dfa75ea52fd7b228cf06fce477ee35ea9179fa612716dc9d5bbf893d78a8dee797
7
- data.tar.gz: 566d24599b0a74edec6bdba172639130b4d6a92dc688870ee9848d124f4523ea400bf334bfa017e92cdc289f39e06c951301f1a8deb2dc74e7b0889cd617b08e
6
+ metadata.gz: b2e9255a98a5114f7fd644baf0c2bd3e509f78b2fd73f4c5a85748b9e7ae8a1f212721ffcdf7e04f5bcb841bf752740ed4e0d2c97756f46b65677419fab89e10
7
+ data.tar.gz: b7680180bc3c35f350f92912f447a988582b54f6f90f18414f3b7a730b7b57bfa49c6bfbf2c7668e58a1974f140b02979c9d5cbbae5fa81d0871d39c123b6b39
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.1.3 - 2021-07-28
4
+
5
+ - Santitize the input to the telemetry query that is issued on startup.
6
+
7
+ ## 6.1.2 - 2021-05-20
8
+
9
+ - Fix a bug where starting the driver can result in a ConnectionNotEstablished error.
10
+
11
+ ## 6.1.1 - 2021-05-14
12
+
13
+ - Fix a bug where starting the driver can result in a NoDatabaseError.
14
+
15
+ ## 6.1.0 - 2021-04-26
16
+
17
+ - Add a telemetry query on start-up. This helps the Cockroach Labs team
18
+ prioritize support for the adapter. It can be disabled by setting the
19
+ `disable_cockroachdb_telemetry` configuration option to false.
20
+
3
21
  ## 6.1.0-beta.3 - 2021-04-02
4
22
 
5
23
  - Added a configuration option named `use_follower_reads_for_type_introspection`.
data/README.md CHANGED
@@ -1,16 +1,18 @@
1
1
  # ActiveRecord CockroachDB Adapter
2
2
 
3
- CockroachDB adapter for ActiveRecord 4 and 5. This is a lightweight extension of the PostgreSQL adapter that establishes compatibility with [CockroachDB](https://github.com/cockroachdb/cockroach).
3
+ CockroachDB adapter for ActiveRecord 5 and 6. This is a lightweight extension of the PostgreSQL adapter that establishes compatibility with [CockroachDB](https://github.com/cockroachdb/cockroach).
4
4
 
5
5
  ## Installation
6
6
 
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', '~> 6.1.0'
11
11
  ```
12
12
 
13
- If you're using Rails 4.x, use the `0.1.x` versions of this gem.
13
+ If you're using Rails 5.2, use the `5.2.x` versions of this gem.
14
+
15
+ If you're using Rails 6.0, use the `6.0.x` versions of this gem.
14
16
 
15
17
  In `database.yml`, use the following adapter setting:
16
18
 
@@ -27,6 +29,7 @@ development:
27
29
  In addition to the standard adapter settings, CockroachDB also supports the following:
28
30
 
29
31
  - `use_follower_reads_for_type_introspection`: Use follower reads on queries to the `pg_type` catalog when set to `true`. This helps to speed up initialization by reading historical data, but may not find recently created user-defined types.
32
+ - `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.
30
33
 
31
34
  ## Working with Spatial Data
32
35
 
@@ -1,10 +1,14 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
6
+ require './lib/version.rb'
7
+ version = ActiveRecord::COCKROACH_DB_ADAPTER_VERSION
8
+
5
9
  Gem::Specification.new do |spec|
6
10
  spec.name = "activerecord-cockroachdb-adapter"
7
- spec.version = "6.1.0-beta.3"
11
+ spec.version = version
8
12
  spec.licenses = ["Apache-2.0"]
9
13
  spec.authors = ["Cockroach Labs"]
10
14
  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
@@ -3,7 +3,7 @@
3
3
  set -euox pipefail
4
4
 
5
5
  # Download CockroachDB
6
- VERSION=v20.2.3
6
+ VERSION=v21.1.5
7
7
  wget -qO- https://binaries.cockroachdb.com/cockroach-$VERSION.linux-amd64.tgz | tar xvz
8
8
  readonly COCKROACH=./cockroach-$VERSION.linux-amd64/cockroach
9
9
 
@@ -36,6 +36,7 @@ run_cockroach() {
36
36
  cockroach sql --insecure -e 'SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;'
37
37
  cockroach sql --insecure -e 'SET CLUSTER SETTING sql.stats.histogram_collection.enabled = false;'
38
38
  cockroach sql --insecure -e "SET CLUSTER SETTING jobs.retention_time = '180s';"
39
+ cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true'"
39
40
  }
40
41
 
41
42
  # Install ruby dependencies.
@@ -17,6 +17,7 @@ require "active_record/connection_adapters/cockroachdb/oid/type_map_initializer"
17
17
  require "active_record/connection_adapters/cockroachdb/oid/spatial"
18
18
  require "active_record/connection_adapters/cockroachdb/oid/interval"
19
19
  require "active_record/connection_adapters/cockroachdb/arel_tosql"
20
+ require_relative "../../version"
20
21
 
21
22
  # Run to ignore spatial tables that will break schemna dumper.
22
23
  # Defined in ./setup.rb
@@ -56,6 +57,40 @@ end
56
57
 
57
58
  module ActiveRecord
58
59
  module ConnectionAdapters
60
+ module CockroachDBConnectionPool
61
+ def initialize(pool_config)
62
+ super(pool_config)
63
+ disable_telemetry = pool_config.db_config.configuration_hash[:disable_cockroachdb_telemetry]
64
+ adapter = pool_config.db_config.configuration_hash[:adapter]
65
+ return if disable_telemetry || adapter != "cockroachdb"
66
+
67
+ begin
68
+ with_connection do |conn|
69
+ if conn.active?
70
+ begin
71
+ ar_version = conn.quote("ActiveRecord %d.%d" % [ActiveRecord::VERSION::MAJOR,
72
+ ActiveRecord::VERSION::MINOR])
73
+ ar_query = "SELECT crdb_internal.increment_feature_counter(%s)" % ar_version
74
+ adapter_version = conn.quote("activerecord-cockroachdb-adapter #{ActiveRecord::COCKROACH_DB_ADAPTER_VERSION}")
75
+ adapter_query = "SELECT crdb_internal.increment_feature_counter(%s)" % adapter_version
76
+
77
+ conn.execute(ar_query)
78
+ conn.execute(adapter_query)
79
+ rescue ActiveRecord::StatementInvalid
80
+ # The increment_feature_counter built-in is not supported on this
81
+ # CockroachDB version. Ignore.
82
+ rescue StandardError => e
83
+ conn.logger.warn "Unexpected error when incrementing feature counter: #{e}"
84
+ end
85
+ end
86
+ end
87
+ rescue StandardError
88
+ # Prevent failures on db creation and parallel testing.
89
+ end
90
+ end
91
+ end
92
+ ConnectionPool.prepend(CockroachDBConnectionPool)
93
+
59
94
  class CockroachDBAdapter < PostgreSQLAdapter
60
95
  ADAPTER_NAME = "CockroachDB".freeze
61
96
  DEFAULT_PRIMARY_KEY = "rowid"
@@ -74,7 +109,7 @@ module ActiveRecord
74
109
  st_polygon: {},
75
110
  }
76
111
 
77
- # http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
112
+ # http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
78
113
  DEFAULT_SRID = 0
79
114
 
80
115
  include CockroachDB::SchemaStatements
@@ -151,12 +186,10 @@ module ActiveRecord
151
186
  end
152
187
 
153
188
  def supports_comments?
154
- # See cockroachdb/cockroach#19472.
155
- false
189
+ @crdb_version >= 201
156
190
  end
157
191
 
158
192
  def supports_comments_in_create?
159
- # See cockroachdb/cockroach#19472.
160
193
  false
161
194
  end
162
195
 
@@ -194,6 +227,7 @@ module ActiveRecord
194
227
 
195
228
  def initialize(connection, logger, conn_params, config)
196
229
  super(connection, logger, conn_params, config)
230
+
197
231
  crdb_version_string = query_value("SHOW crdb_version")
198
232
  if crdb_version_string.include? "v1."
199
233
  version_num = 1
@@ -205,8 +239,10 @@ module ActiveRecord
205
239
  version_num = 192
206
240
  elsif crdb_version_string.include? "v20.1."
207
241
  version_num = 201
208
- else
242
+ elsif crdb_version_string.include? "v20.2."
209
243
  version_num = 202
244
+ else
245
+ version_num = 210
210
246
  end
211
247
  @crdb_version = version_num
212
248
  end
@@ -247,12 +283,9 @@ module ActiveRecord
247
283
  precision = extract_precision(sql_type)
248
284
  scale = extract_scale(sql_type)
249
285
 
250
- # TODO(#178) this should never use DecimalWithoutScale since scale
251
- # is assumed to be 0 if it is not explicitly defined.
252
- #
253
286
  # If fmod is -1, that means that precision is defined but not
254
287
  # scale, or neither is defined.
255
- if fmod && fmod == -1
288
+ if fmod && fmod == -1 && !precision.nil?
256
289
  # Below comment is from ActiveRecord
257
290
  # FIXME: Remove this class, and the second argument to
258
291
  # lookups on PG
@@ -365,7 +398,7 @@ module ActiveRecord
365
398
  # In general, it is hard to parse that, but it is easy to handle the common
366
399
  # case of an empty array.
367
400
  def extract_empty_array_from_default(default)
368
- return unless supports_string_to_array_coercion?
401
+ return unless supports_string_to_array_coercion?
369
402
  return unless default =~ /\AARRAY\[\]\z/
370
403
  return "{}"
371
404
  end
data/lib/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ COCKROACH_DB_ADAPTER_VERSION = "6.1.3"
5
+ end
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: 6.1.0.pre.beta.3
4
+ version: 6.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cockroach Labs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-02 00:00:00.000000000 Z
11
+ date: 2021-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -95,6 +95,7 @@ files:
95
95
  - lib/active_record/connection_adapters/cockroachdb/type.rb
96
96
  - lib/active_record/connection_adapters/cockroachdb_adapter.rb
97
97
  - lib/activerecord-cockroachdb-adapter.rb
98
+ - lib/version.rb
98
99
  homepage: https://github.com/cockroachdb/activerecord-cockroachdb-adapter
99
100
  licenses:
100
101
  - Apache-2.0
@@ -111,11 +112,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  requirements:
114
- - - ">"
115
+ - - ">="
115
116
  - !ruby/object:Gem::Version
116
- version: 1.3.1
117
+ version: '0'
117
118
  requirements: []
118
- rubygems_version: 3.1.4
119
+ rubygems_version: 3.2.15
119
120
  signing_key:
120
121
  specification_version: 4
121
122
  summary: CockroachDB adapter for ActiveRecord.