activerecord-cockroachdb-adapter 6.1.6 → 6.1.9
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 +4 -4
- data/CHANGELOG.md +16 -0
- data/lib/active_record/connection_adapters/cockroachdb/column.rb +11 -2
- data/lib/active_record/connection_adapters/cockroachdb/schema_creation.rb +18 -0
- data/lib/active_record/connection_adapters/cockroachdb/schema_dumper.rb +19 -0
- data/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb +12 -2
- data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +59 -25
- data/lib/version.rb +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8b028b8755fedebaa4aff7f1f98218d553726364df8fcc24647c3bfd7c80e2d
|
4
|
+
data.tar.gz: 3f7268dccaf636eb1532697dd525a39930a829eba290f06d7446cc24547e0ea1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cea6678432382da1af4de2fb0216d820bde0be2c254d564fa931fc34683898ec72faf507263bed58187e2f582f55b1c590d1ba8b3fd8487be69518578903821f
|
7
|
+
data.tar.gz: a3e7d5dbc70abfeac236084dbcc7e60530d10413fbee0f8d6c08668c11d7ab3394e882b6a5a4b660520a1c456de09585128f66de92708ab2ad314f9ca3c66498
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 6.1.9 - 2022-04-26
|
4
|
+
|
5
|
+
- Fix bug where duplicate `rowid` columns would be created when loading
|
6
|
+
a schema dump of a table that was not created with an explicit primary key.
|
7
|
+
- Support the NOT VISIBLE syntax from CockroachDB, by using the `hidden`
|
8
|
+
column modifier in the Rails schema.
|
9
|
+
|
10
|
+
## 6.1.8 - 2022-03-14
|
11
|
+
|
12
|
+
- Add a test helper from https://github.com/rails/rails/pull/40822
|
13
|
+
to be able to test against Rails upstream.
|
14
|
+
|
15
|
+
## 6.1.7 - 2022-03-01
|
16
|
+
|
17
|
+
- Fix query to get the CockroachDB version so it does not require any privileges.
|
18
|
+
|
3
19
|
## 6.1.6 - 2022-02-25
|
4
20
|
|
5
21
|
- Fix mixed versions of CockroachDB v21.1 and v21.2 not working.
|
@@ -6,9 +6,10 @@ module ActiveRecord
|
|
6
6
|
# https://github.com/rgeo/activerecord-postgis-adapter/blob/master/lib/active_record/connection_adapters/postgis/spatial_column.rb
|
7
7
|
def initialize(name, default, sql_type_metadata = nil, null = true,
|
8
8
|
default_function = nil, collation: nil, comment: nil,
|
9
|
-
serial: nil, spatial: nil)
|
9
|
+
serial: nil, spatial: nil, generated: nil, hidden: nil)
|
10
10
|
@sql_type_metadata = sql_type_metadata
|
11
11
|
@geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
|
12
|
+
@hidden = hidden
|
12
13
|
|
13
14
|
if spatial
|
14
15
|
# This case comes from an entry in the geometry_columns table
|
@@ -29,7 +30,7 @@ module ActiveRecord
|
|
29
30
|
build_from_sql_type(sql_type_metadata.sql_type)
|
30
31
|
end
|
31
32
|
super(name, default, sql_type_metadata, null, default_function,
|
32
|
-
collation: collation, comment: comment, serial: serial)
|
33
|
+
collation: collation, comment: comment, serial: serial, generated: generated)
|
33
34
|
if spatial? && @srid
|
34
35
|
@limit = { srid: @srid, type: to_type_name(geometric_type) }
|
35
36
|
@limit[:has_z] = true if @has_z
|
@@ -52,6 +53,14 @@ module ActiveRecord
|
|
52
53
|
spatial? ? @limit : super
|
53
54
|
end
|
54
55
|
|
56
|
+
def virtual?
|
57
|
+
@generated.present?
|
58
|
+
end
|
59
|
+
|
60
|
+
def hidden?
|
61
|
+
@hidden
|
62
|
+
end
|
63
|
+
|
55
64
|
def spatial?
|
56
65
|
%i[geometry geography].include?(@sql_type_metadata.type)
|
57
66
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module CockroachDB
|
6
|
+
class SchemaCreation < PostgreSQL::SchemaCreation # :nodoc:
|
7
|
+
private
|
8
|
+
def add_column_options!(sql, options)
|
9
|
+
if options[:hidden]
|
10
|
+
sql << " NOT VISIBLE"
|
11
|
+
end
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module CockroachDB
|
6
|
+
class SchemaDumper < ConnectionAdapters::PostgreSQL::SchemaDumper # :nodoc:
|
7
|
+
private
|
8
|
+
def prepare_column_options(column)
|
9
|
+
spec = super
|
10
|
+
if column.hidden?
|
11
|
+
spec[:hidden] = true
|
12
|
+
end
|
13
|
+
spec
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -77,7 +77,7 @@ module ActiveRecord
|
|
77
77
|
# override
|
78
78
|
# https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L624
|
79
79
|
def new_column_from_field(table_name, field)
|
80
|
-
column_name, type, default, notnull, oid, fmod, collation, comment = field
|
80
|
+
column_name, type, default, notnull, oid, fmod, collation, comment, generated, hidden = field
|
81
81
|
type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
|
82
82
|
default_value = extract_value_from_default(default)
|
83
83
|
default_function = extract_default_function(default_value, default)
|
@@ -99,7 +99,9 @@ module ActiveRecord
|
|
99
99
|
collation: collation,
|
100
100
|
comment: comment.presence,
|
101
101
|
serial: serial,
|
102
|
-
spatial: spatial
|
102
|
+
spatial: spatial,
|
103
|
+
generated: generated,
|
104
|
+
hidden: hidden
|
103
105
|
)
|
104
106
|
end
|
105
107
|
|
@@ -186,6 +188,14 @@ module ActiveRecord
|
|
186
188
|
@spatial_column_info ||= {}
|
187
189
|
@spatial_column_info[table_name.to_sym] ||= SpatialColumnInfo.new(self, table_name.to_s)
|
188
190
|
end
|
191
|
+
|
192
|
+
def create_schema_dumper(options)
|
193
|
+
CockroachDB::SchemaDumper.create(self, options)
|
194
|
+
end
|
195
|
+
|
196
|
+
def schema_creation
|
197
|
+
CockroachDB::SchemaCreation.new(self)
|
198
|
+
end
|
189
199
|
end
|
190
200
|
end
|
191
201
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require "rgeo/active_record"
|
2
2
|
|
3
3
|
require "active_record/connection_adapters/postgresql_adapter"
|
4
|
+
require "active_record/connection_adapters/cockroachdb/attribute_methods"
|
4
5
|
require "active_record/connection_adapters/cockroachdb/column_methods"
|
6
|
+
require "active_record/connection_adapters/cockroachdb/schema_creation"
|
7
|
+
require "active_record/connection_adapters/cockroachdb/schema_dumper"
|
5
8
|
require "active_record/connection_adapters/cockroachdb/schema_statements"
|
6
9
|
require "active_record/connection_adapters/cockroachdb/referential_integrity"
|
7
10
|
require "active_record/connection_adapters/cockroachdb/transaction_manager"
|
@@ -9,7 +12,6 @@ require "active_record/connection_adapters/cockroachdb/database_statements"
|
|
9
12
|
require "active_record/connection_adapters/cockroachdb/table_definition"
|
10
13
|
require "active_record/connection_adapters/cockroachdb/quoting"
|
11
14
|
require "active_record/connection_adapters/cockroachdb/type"
|
12
|
-
require "active_record/connection_adapters/cockroachdb/attribute_methods"
|
13
15
|
require "active_record/connection_adapters/cockroachdb/column"
|
14
16
|
require "active_record/connection_adapters/cockroachdb/spatial_column_info"
|
15
17
|
require "active_record/connection_adapters/cockroachdb/setup"
|
@@ -199,7 +201,7 @@ module ActiveRecord
|
|
199
201
|
end
|
200
202
|
|
201
203
|
def supports_virtual_columns?
|
202
|
-
|
204
|
+
@crdb_version >= 2110
|
203
205
|
end
|
204
206
|
|
205
207
|
def supports_string_to_array_coercion?
|
@@ -228,27 +230,42 @@ module ActiveRecord
|
|
228
230
|
def initialize(connection, logger, conn_params, config)
|
229
231
|
super(connection, logger, conn_params, config)
|
230
232
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
version_num =
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
version_num = 2110
|
246
|
-
elsif crdb_version_string.start_with? "21.2"
|
247
|
-
version_num = 2120
|
233
|
+
# crdb_version is the version of the binary running on the node. We
|
234
|
+
# really want to use `SHOW CLUSTER SETTING version` to get the cluster
|
235
|
+
# version, but that is only available to admins. Instead, we can use
|
236
|
+
# crdb_internal.is_at_least_version, but that's only available in 22.1.
|
237
|
+
crdb_version_string = query_value("SHOW crdb_version")
|
238
|
+
if crdb_version_string.include? "v22.1"
|
239
|
+
version_num = query_value(<<~SQL, "VERSION")
|
240
|
+
SELECT
|
241
|
+
CASE
|
242
|
+
WHEN crdb_internal.is_at_least_version('22.2') THEN 2220
|
243
|
+
WHEN crdb_internal.is_at_least_version('22.1') THEN 2210
|
244
|
+
ELSE 2120
|
245
|
+
END;
|
246
|
+
SQL
|
248
247
|
else
|
249
|
-
|
248
|
+
# This branch can be removed once the dialect stops supporting v21.2
|
249
|
+
# and earlier.
|
250
|
+
if crdb_version_string.include? "v1."
|
251
|
+
version_num = 1
|
252
|
+
elsif crdb_version_string.include? "v2."
|
253
|
+
version_num 2
|
254
|
+
elsif crdb_version_string.include? "v19.1."
|
255
|
+
version_num = 1910
|
256
|
+
elsif crdb_version_string.include? "v19.2."
|
257
|
+
version_num = 1920
|
258
|
+
elsif crdb_version_string.include? "v20.1."
|
259
|
+
version_num = 2010
|
260
|
+
elsif crdb_version_string.include? "v20.2."
|
261
|
+
version_num = 2020
|
262
|
+
elsif crdb_version_string.include? "v21.1."
|
263
|
+
version_num = 2110
|
264
|
+
else
|
265
|
+
version_num = 2120
|
266
|
+
end
|
250
267
|
end
|
251
|
-
@crdb_version = version_num
|
268
|
+
@crdb_version = version_num.to_i
|
252
269
|
|
253
270
|
# NOTE: this is normally in configure_connection, but that is run
|
254
271
|
# before crdb_version is determined. Once all supported versions
|
@@ -256,8 +273,14 @@ module ActiveRecord
|
|
256
273
|
# back.
|
257
274
|
# Set interval output format to ISO 8601 for ease of parsing by ActiveSupport::Duration.parse
|
258
275
|
if @crdb_version >= 2120
|
259
|
-
|
260
|
-
|
276
|
+
begin
|
277
|
+
execute("SET intervalstyle_enabled = true", "SCHEMA")
|
278
|
+
execute("SET intervalstyle = iso_8601", "SCHEMA")
|
279
|
+
rescue
|
280
|
+
# Ignore any error. This can happen with a cluster that has
|
281
|
+
# not yet finalized the v21.2 upgrade. v21.2 does not have
|
282
|
+
# a way to tell if the upgrade was finalized (see comment above).
|
283
|
+
end
|
261
284
|
end
|
262
285
|
end
|
263
286
|
|
@@ -453,7 +476,8 @@ module ActiveRecord
|
|
453
476
|
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
|
454
477
|
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
|
455
478
|
c.collname, NULL AS comment,
|
456
|
-
#{supports_virtual_columns? ? 'attgenerated' : quote('')} as attgenerated
|
479
|
+
#{supports_virtual_columns? ? 'attgenerated' : quote('')} as attgenerated,
|
480
|
+
NULL as is_hidden
|
457
481
|
FROM pg_attribute a
|
458
482
|
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
|
459
483
|
LEFT JOIN pg_type t ON a.atttypid = t.oid
|
@@ -479,8 +503,18 @@ module ActiveRecord
|
|
479
503
|
dtype = field[1]
|
480
504
|
field[1] = crdb_fields[field[0]][2].downcase if re.match(dtype)
|
481
505
|
field[7] = crdb_fields[field[0]][1]&.gsub!(/^\'|\'?$/, '')
|
506
|
+
field[9] = true if crdb_fields[field[0]][3]
|
482
507
|
field
|
483
508
|
end
|
509
|
+
fields.delete_if do |field|
|
510
|
+
# Don't include rowid column if it is hidden and the primary key
|
511
|
+
# is not defined (meaning CRDB implicitly created it).
|
512
|
+
if field[0] == CockroachDBAdapter::DEFAULT_PRIMARY_KEY
|
513
|
+
field[9] && !primary_key(table_name)
|
514
|
+
else
|
515
|
+
false # Keep this entry.
|
516
|
+
end
|
517
|
+
end
|
484
518
|
end
|
485
519
|
|
486
520
|
# Fetch the column comment because it's faster this way
|
@@ -491,7 +525,7 @@ module ActiveRecord
|
|
491
525
|
def crdb_column_definitions(table_name)
|
492
526
|
fields = \
|
493
527
|
query(<<~SQL, "SCHEMA")
|
494
|
-
SELECT c.column_name, c.column_comment, c.crdb_sql_type
|
528
|
+
SELECT c.column_name, c.column_comment, c.crdb_sql_type, c.is_hidden::BOOLEAN
|
495
529
|
FROM information_schema.columns c
|
496
530
|
WHERE c.table_name = #{quote(table_name)}
|
497
531
|
SQL
|
data/lib/version.rb
CHANGED
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
|
+
version: 6.1.9
|
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: 2022-
|
11
|
+
date: 2022-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -87,6 +87,8 @@ files:
|
|
87
87
|
- lib/active_record/connection_adapters/cockroachdb/oid/type_map_initializer.rb
|
88
88
|
- lib/active_record/connection_adapters/cockroachdb/quoting.rb
|
89
89
|
- lib/active_record/connection_adapters/cockroachdb/referential_integrity.rb
|
90
|
+
- lib/active_record/connection_adapters/cockroachdb/schema_creation.rb
|
91
|
+
- lib/active_record/connection_adapters/cockroachdb/schema_dumper.rb
|
90
92
|
- lib/active_record/connection_adapters/cockroachdb/schema_statements.rb
|
91
93
|
- lib/active_record/connection_adapters/cockroachdb/setup.rb
|
92
94
|
- lib/active_record/connection_adapters/cockroachdb/spatial_column_info.rb
|
@@ -101,7 +103,7 @@ licenses:
|
|
101
103
|
- Apache-2.0
|
102
104
|
metadata:
|
103
105
|
allowed_push_host: https://rubygems.org
|
104
|
-
post_install_message:
|
106
|
+
post_install_message:
|
105
107
|
rdoc_options: []
|
106
108
|
require_paths:
|
107
109
|
- lib
|
@@ -116,8 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
118
|
- !ruby/object:Gem::Version
|
117
119
|
version: '0'
|
118
120
|
requirements: []
|
119
|
-
rubygems_version: 3.
|
120
|
-
signing_key:
|
121
|
+
rubygems_version: 3.1.6
|
122
|
+
signing_key:
|
121
123
|
specification_version: 4
|
122
124
|
summary: CockroachDB adapter for ActiveRecord.
|
123
125
|
test_files: []
|