activerecord-cockroachdb-adapter 6.1.4 → 6.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee61867492cc8b0c28f58b9090625a08914e610e6a1732924a2b4d925a01a714
4
- data.tar.gz: d7ae4281ca3738f92e84df29243c687693cf8aed64ba006d9c44541c25ba2029
3
+ metadata.gz: 95b9157a969cd938c7500ed5a755120ec9f9bdce6e5e11316d32e2e434e8d7b2
4
+ data.tar.gz: 96f79790d7f0fbbb95b32e3e07425fe8df2d10830165e31302f0d9fa8f27405a
5
5
  SHA512:
6
- metadata.gz: c61ca3b032274dc8cc5063e55465fdc2b418bbda7c6d8a4093405d61c5c2b49758faaf77f95a76eb0c46101e3ec0a4f9c1442744abe49bcc747a0b86de64bec9
7
- data.tar.gz: f91ea52d72dcef0c50e87186b12f10c7118882e48e10ef667c64e59da159493ea8dd23b5bbb4256c9222d703afaf89d7554831d2ef523096151af9fdf9faaf9f
6
+ metadata.gz: ed654032304e706dcab7ab22514b5e1e93facfa946686a9455676fa220c5aff0859044645b778d0ef63f8482809a21440846d733f263ec007c548a4bba18c891
7
+ data.tar.gz: 8a1d4ae16ac33747a80b2a1af1d04095358265d7949e43b66ba3e77aa02d310c9ebc32891d315ce9351197223e6f04e238cb1bd1eb57c8ffef2ecf94a120ed31
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.1.7 - 2022-03-01
4
+
5
+ - Fix query to get the CockroachDB version so it does not require any privileges.
6
+
7
+ ## 6.1.6 - 2022-02-25
8
+
9
+ - Fix mixed versions of CockroachDB v21.1 and v21.2 not working.
10
+
11
+ ## 6.1.5 - 2022-02-08
12
+
13
+ - Support `atttypmod` being sent for DECIMAL types.
14
+ This is needed for CockroachDB v22.1.
15
+
3
16
  ## 6.1.4 - 2021-12-09
4
17
 
5
18
  - Add support for CockroachDB v21.2.
@@ -3,7 +3,7 @@
3
3
  set -euox pipefail
4
4
 
5
5
  # Download CockroachDB
6
- VERSION=v21.2.0
6
+ VERSION=v21.2.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
 
@@ -35,8 +35,28 @@ run_cockroach() {
35
35
  cockroach sql --insecure -e 'CREATE DATABASE activerecord_unittest2;'
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
- 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'"
38
+
39
+ cockroach sql --insecure -e "ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;"
40
+ cockroach sql --insecure -e "ALTER TABLE system.public.jobs CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;"
41
+ cockroach sql --insecure -e "ALTER RANGE meta CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;"
42
+ cockroach sql --insecure -e "ALTER RANGE system CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;"
43
+ cockroach sql --insecure -e "ALTER RANGE liveness CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;"
44
+
45
+ cockroach sql --insecure -e "SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms'"
46
+ cockroach sql --insecure -e "SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = 'true'"
47
+ cockroach sql --insecure -e "SET CLUSTER SETTING jobs.registry.interval.cancel = '180s';"
48
+ cockroach sql --insecure -e "SET CLUSTER SETTING jobs.registry.interval.gc = '30s';"
49
+ cockroach sql --insecure -e "SET CLUSTER SETTING jobs.retention_time = '15s';"
50
+ cockroach sql --insecure -e "SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;"
51
+ cockroach sql --insecure -e "SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s';"
52
+
53
+ # Enable when we test with v22.1.
54
+ # cockroach sql --insecure -e "SET CLUSTER SETTING sql.catalog.unsafe_skip_system_config_trigger.enabled = true;"
55
+
56
+ # Enable experimental features.
57
+ cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';"
58
+ cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.datestyle.enabled = true"
59
+ cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.intervalstyle.enabled = true;"
40
60
  }
41
61
 
42
62
  # Install ruby dependencies.
@@ -228,27 +228,42 @@ module ActiveRecord
228
228
  def initialize(connection, logger, conn_params, config)
229
229
  super(connection, logger, conn_params, config)
230
230
 
231
+ # crdb_version is the version of the binary running on the node. We
232
+ # really want to use `SHOW CLUSTER SETTING version` to get the cluster
233
+ # version, but that is only available to admins. Instead, we can use
234
+ # crdb_internal.is_at_least_version, but that's only available in 22.1.
231
235
  crdb_version_string = query_value("SHOW crdb_version")
232
- if crdb_version_string.include? "v1."
233
- version_num = 1
234
- elsif crdb_version_string.include? "v2."
235
- version_num 2
236
- elsif crdb_version_string.include? "v19.1."
237
- version_num = 1910
238
- elsif crdb_version_string.include? "v19.2."
239
- version_num = 1920
240
- elsif crdb_version_string.include? "v20.1."
241
- version_num = 2010
242
- elsif crdb_version_string.include? "v20.2."
243
- version_num = 2020
244
- elsif crdb_version_string.include? "v21.1."
245
- version_num = 2110
246
- elsif crdb_version_string.include? "v21.2.0"
247
- version_num = 2120
236
+ if crdb_version_string.include? "v22.1"
237
+ version_num = query_value(<<~SQL, "VERSION")
238
+ SELECT
239
+ CASE
240
+ WHEN crdb_internal.is_at_least_version('22.2') THEN 2220
241
+ WHEN crdb_internal.is_at_least_version('22.1') THEN 2210
242
+ ELSE 2120
243
+ END;
244
+ SQL
248
245
  else
249
- version_num = 2121
246
+ # This branch can be removed once the dialect stops supporting v21.2
247
+ # and earlier.
248
+ if crdb_version_string.include? "v1."
249
+ version_num = 1
250
+ elsif crdb_version_string.include? "v2."
251
+ version_num 2
252
+ elsif crdb_version_string.include? "v19.1."
253
+ version_num = 1910
254
+ elsif crdb_version_string.include? "v19.2."
255
+ version_num = 1920
256
+ elsif crdb_version_string.include? "v20.1."
257
+ version_num = 2010
258
+ elsif crdb_version_string.include? "v20.2."
259
+ version_num = 2020
260
+ elsif crdb_version_string.include? "v21.1."
261
+ version_num = 2110
262
+ else
263
+ version_num = 2120
264
+ end
250
265
  end
251
- @crdb_version = version_num
266
+ @crdb_version = version_num.to_i
252
267
 
253
268
  # NOTE: this is normally in configure_connection, but that is run
254
269
  # before crdb_version is determined. Once all supported versions
@@ -256,8 +271,14 @@ module ActiveRecord
256
271
  # back.
257
272
  # Set interval output format to ISO 8601 for ease of parsing by ActiveSupport::Duration.parse
258
273
  if @crdb_version >= 2120
259
- execute("SET intervalstyle_enabled = true", "SCHEMA")
260
- execute("SET intervalstyle = iso_8601", "SCHEMA")
274
+ begin
275
+ execute("SET intervalstyle_enabled = true", "SCHEMA")
276
+ execute("SET intervalstyle = iso_8601", "SCHEMA")
277
+ rescue
278
+ # Ignore any error. This can happen with a cluster that has
279
+ # not yet finalized the v21.2 upgrade. v21.2 does not have
280
+ # a way to tell if the upgrade was finalized (see comment above).
281
+ end
261
282
  end
262
283
  end
263
284
 
@@ -297,9 +318,19 @@ module ActiveRecord
297
318
  precision = extract_precision(sql_type)
298
319
  scale = extract_scale(sql_type)
299
320
 
321
+
322
+ # The type for the numeric depends on the width of the field,
323
+ # so we'll do something special here.
324
+ #
325
+ # When dealing with decimal columns:
326
+ #
327
+ # places after decimal = fmod - 4 & 0xffff
328
+ # places before decimal = (fmod - 4) >> 16 & 0xffff
329
+ #
330
+ # For older versions of CockroachDB (<v22.1), fmod is -1 for 0 width.
300
331
  # If fmod is -1, that means that precision is defined but not
301
332
  # scale, or neither is defined.
302
- if fmod && fmod == -1 && !precision.nil?
333
+ if fmod && ((fmod == -1 && !precision.nil?) || (fmod - 4 & 0xffff).zero?)
303
334
  # Below comment is from ActiveRecord
304
335
  # FIXME: Remove this class, and the second argument to
305
336
  # lookups on PG
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecord
4
- COCKROACH_DB_ADAPTER_VERSION = "6.1.4"
4
+ COCKROACH_DB_ADAPTER_VERSION = "6.1.7"
5
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.4
4
+ version: 6.1.7
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-12-13 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord