activerecord-cockroachdb-adapter 6.1.7 → 6.1.10
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 +19 -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 +21 -5
- data/lib/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72a654c4b06b42fbaae48bc9610420b2103f38b72d4170b7ae59983860d6e9d6
|
4
|
+
data.tar.gz: fb400dec89ffb39d202a081ff09a34330a498e3e9ce4363433d55de255a0288a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f39c8a1fb5da46833e2ebb25a7224fd4c7d6bf1b71649d06550e60bd00e6dc084ef6675d9314995a002a507aa3e382efb7947fdc951221612fbc12b730b95fed
|
7
|
+
data.tar.gz: b133873824c59d673b9aed7a8cb45933aa7298bf9b5dc533240e9e43e99820ab1abe0be09874a9d0f5b6f7ce599441b7c1e462ecc83754f0de87dab9ca8ce50b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 6.1.10 - 2022-05-06
|
4
|
+
|
5
|
+
- Disable supports_expression_index regardless of CockroachDB version until
|
6
|
+
`ON CONFLICT expression` is supported.
|
7
|
+
|
8
|
+
See https://github.com/cockroachdb/cockroach/issues/67893.
|
9
|
+
|
10
|
+
## 6.1.9 - 2022-04-26
|
11
|
+
|
12
|
+
- Fix bug where duplicate `rowid` columns would be created when loading
|
13
|
+
a schema dump of a table that was not created with an explicit primary key.
|
14
|
+
- Support the NOT VISIBLE syntax from CockroachDB, by using the `hidden`
|
15
|
+
column modifier in the Rails schema.
|
16
|
+
|
17
|
+
## 6.1.8 - 2022-03-14
|
18
|
+
|
19
|
+
- Add a test helper from https://github.com/rails/rails/pull/40822
|
20
|
+
to be able to test against Rails upstream.
|
21
|
+
|
3
22
|
## 6.1.7 - 2022-03-01
|
4
23
|
|
5
24
|
- Fix query to get the CockroachDB version so it does not require any privileges.
|
@@ -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"
|
@@ -179,7 +181,10 @@ module ActiveRecord
|
|
179
181
|
end
|
180
182
|
|
181
183
|
def supports_expression_index?
|
182
|
-
|
184
|
+
# Expression indexes are partially supported by CockroachDB v21.2,
|
185
|
+
# but activerecord requires "ON CONFLICT expression" support.
|
186
|
+
# See https://github.com/cockroachdb/cockroach/issues/67893
|
187
|
+
false
|
183
188
|
end
|
184
189
|
|
185
190
|
def supports_datetime_with_precision?
|
@@ -199,7 +204,7 @@ module ActiveRecord
|
|
199
204
|
end
|
200
205
|
|
201
206
|
def supports_virtual_columns?
|
202
|
-
|
207
|
+
@crdb_version >= 2110
|
203
208
|
end
|
204
209
|
|
205
210
|
def supports_string_to_array_coercion?
|
@@ -474,7 +479,8 @@ module ActiveRecord
|
|
474
479
|
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
|
475
480
|
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
|
476
481
|
c.collname, NULL AS comment,
|
477
|
-
#{supports_virtual_columns? ? 'attgenerated' : quote('')} as attgenerated
|
482
|
+
#{supports_virtual_columns? ? 'attgenerated' : quote('')} as attgenerated,
|
483
|
+
NULL as is_hidden
|
478
484
|
FROM pg_attribute a
|
479
485
|
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
|
480
486
|
LEFT JOIN pg_type t ON a.atttypid = t.oid
|
@@ -500,8 +506,18 @@ module ActiveRecord
|
|
500
506
|
dtype = field[1]
|
501
507
|
field[1] = crdb_fields[field[0]][2].downcase if re.match(dtype)
|
502
508
|
field[7] = crdb_fields[field[0]][1]&.gsub!(/^\'|\'?$/, '')
|
509
|
+
field[9] = true if crdb_fields[field[0]][3]
|
503
510
|
field
|
504
511
|
end
|
512
|
+
fields.delete_if do |field|
|
513
|
+
# Don't include rowid column if it is hidden and the primary key
|
514
|
+
# is not defined (meaning CRDB implicitly created it).
|
515
|
+
if field[0] == CockroachDBAdapter::DEFAULT_PRIMARY_KEY
|
516
|
+
field[9] && !primary_key(table_name)
|
517
|
+
else
|
518
|
+
false # Keep this entry.
|
519
|
+
end
|
520
|
+
end
|
505
521
|
end
|
506
522
|
|
507
523
|
# Fetch the column comment because it's faster this way
|
@@ -512,7 +528,7 @@ module ActiveRecord
|
|
512
528
|
def crdb_column_definitions(table_name)
|
513
529
|
fields = \
|
514
530
|
query(<<~SQL, "SCHEMA")
|
515
|
-
SELECT c.column_name, c.column_comment, c.crdb_sql_type
|
531
|
+
SELECT c.column_name, c.column_comment, c.crdb_sql_type, c.is_hidden::BOOLEAN
|
516
532
|
FROM information_schema.columns c
|
517
533
|
WHERE c.table_name = #{quote(table_name)}
|
518
534
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cockroach Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-12 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
|