activerecord-cockroachdb-adapter 5.2.2 → 6.0.0.pre.beta.5
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 +25 -0
- data/README.md +6 -0
- data/activerecord-cockroachdb-adapter.gemspec +2 -2
- data/lib/active_record/connection_adapters/cockroachdb/column.rb +15 -17
- data/lib/active_record/connection_adapters/cockroachdb/oid/type_map_initializer.rb +26 -0
- data/lib/active_record/connection_adapters/cockroachdb/quoting.rb +3 -4
- data/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb +48 -32
- data/lib/active_record/connection_adapters/cockroachdb/transaction_manager.rb +10 -4
- data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +119 -13
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e242232ac6fcfc87b6bddc17eeb852099a959d3a024064ed3a32e85bd80ad786
|
4
|
+
data.tar.gz: 5ab114df9f5fee7fb5c18c5cf0eb0dfdc822f7513f19d79312f65e0b55e1e459
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2de1e036b53ebeb11185eaeb10bd465f9a1103a34307354bc4bbbe94b8beb4c5a2313938e01703db8b68f5a689ee6b9b778b8282bceac3bb852b6569340351b
|
7
|
+
data.tar.gz: 4138ea2ccad0bac070c277adb9ec4aa837be440900f72fe8f2728bac78d58a96d96ed7df9a830841b3389e5f51678dba9377e0598b3aa96d682d36c609dcedfb
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 6.0.0-beta.5 - 2021-04-02
|
4
|
+
|
5
|
+
- Added a configuration option named `use_follower_reads_for_type_introspection`.
|
6
|
+
If true, it improves the speed of type introspection by allowing potentially stale
|
7
|
+
type metadata to be read. Defaults to false.
|
8
|
+
|
9
|
+
## 6.0.0-beta.4 - 2021-03-06
|
10
|
+
|
11
|
+
- Improved connection performance by refactoring an introspection
|
12
|
+
that loads types.
|
13
|
+
- Changed version numbers to semver.
|
14
|
+
|
15
|
+
## 6.0.0beta3
|
16
|
+
|
17
|
+
- Added support for spatial features.
|
18
|
+
|
19
|
+
## 6.0.0beta2
|
20
|
+
|
21
|
+
- Updated transaction retry logic to work with Rails 6.
|
22
|
+
|
23
|
+
## 6.0.0beta1
|
24
|
+
|
25
|
+
- Initial support for Rails 6.
|
data/README.md
CHANGED
@@ -22,6 +22,12 @@ development:
|
|
22
22
|
user: <username>
|
23
23
|
```
|
24
24
|
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
In addition to the standard adapter settings, CockroachDB also supports the following:
|
28
|
+
|
29
|
+
- `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.
|
30
|
+
|
25
31
|
## Working with Spatial Data
|
26
32
|
|
27
33
|
The adapter uses [RGeo](https://github.com/rgeo/rgeo) and [RGeo-ActiveRecord](https://github.com/rgeo/rgeo-activerecord) to represent geometric and geographic data as Ruby objects and easily interface them with the adapter. The following is a brief introduction to RGeo and tips to help setup your spatial application. More documentation about RGeo can be found in the [YARD Docs](https://rubydoc.info/github/rgeo/rgeo) and [wiki](https://github.com/rgeo/rgeo/wiki).
|
@@ -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 = "
|
7
|
+
spec.version = "6.0.0-beta.5"
|
8
8
|
spec.licenses = ["Apache-2.0"]
|
9
9
|
spec.authors = ["Cockroach Labs"]
|
10
10
|
spec.email = ["cockroach-db@googlegroups.com"]
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = "Allows the use of CockroachDB as a backend for ActiveRecord and Rails apps."
|
14
14
|
spec.homepage = "https://github.com/cockroachdb/activerecord-cockroachdb-adapter"
|
15
15
|
|
16
|
-
spec.add_dependency "activerecord", "~>
|
16
|
+
spec.add_dependency "activerecord", "~> 6.0.3"
|
17
17
|
spec.add_dependency "pg", ">= 0.20"
|
18
18
|
spec.add_dependency "rgeo-activerecord", "~> 7.0.0"
|
19
19
|
|
@@ -4,19 +4,18 @@ module ActiveRecord
|
|
4
4
|
module PostgreSQLColumnMonkeyPatch
|
5
5
|
# most functions taken from activerecord-postgis-adapter spatial_column
|
6
6
|
# https://github.com/rgeo/activerecord-postgis-adapter/blob/master/lib/active_record/connection_adapters/postgis/spatial_column.rb
|
7
|
-
def initialize(name, default, sql_type_metadata = nil, null = true,
|
8
|
-
default_function = nil, collation
|
7
|
+
def initialize(name, default, sql_type_metadata = nil, null = true,
|
8
|
+
default_function = nil, collation: nil, comment: nil,
|
9
|
+
serial: nil, spatial: nil)
|
9
10
|
@sql_type_metadata = sql_type_metadata
|
10
11
|
@geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
|
11
12
|
|
12
|
-
|
13
|
-
@geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
|
14
|
-
if opts
|
13
|
+
if spatial
|
15
14
|
# This case comes from an entry in the geometry_columns table
|
16
|
-
set_geometric_type_from_name(
|
17
|
-
@srid =
|
18
|
-
@has_z = !!
|
19
|
-
@has_m = !!
|
15
|
+
set_geometric_type_from_name(spatial[:type])
|
16
|
+
@srid = spatial[:srid].to_i
|
17
|
+
@has_z = !!spatial[:has_z]
|
18
|
+
@has_m = !!spatial[:has_m]
|
20
19
|
elsif @geographic
|
21
20
|
# Geographic type information is embedded in the SQL type
|
22
21
|
@srid = 4326
|
@@ -29,14 +28,13 @@ module ActiveRecord
|
|
29
28
|
# @geometric_type = geo_type_from_sql_type(sql_type)
|
30
29
|
build_from_sql_type(sql_type_metadata.sql_type)
|
31
30
|
end
|
32
|
-
super(name, default, sql_type_metadata, null,
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
31
|
+
super(name, default, sql_type_metadata, null, default_function,
|
32
|
+
collation: collation, comment: comment, serial: serial)
|
33
|
+
if spatial? && @srid
|
34
|
+
@limit = { srid: @srid, type: to_type_name(geometric_type) }
|
35
|
+
@limit[:has_z] = true if @has_z
|
36
|
+
@limit[:has_m] = true if @has_m
|
37
|
+
@limit[:geographic] = true if @geographic
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module CockroachDB
|
4
|
+
module OID
|
5
|
+
module TypeMapInitializer
|
6
|
+
# override
|
7
|
+
# Replaces the query with a faster version that doesn't rely on the
|
8
|
+
# use of 'array_in(cstring,oid,integer)'::regprocedure.
|
9
|
+
def query_conditions_for_initial_load
|
10
|
+
known_type_names = @store.keys.map { |n| "'#{n}'" }
|
11
|
+
known_type_types = %w('r' 'e' 'd')
|
12
|
+
<<~SQL % [known_type_names.join(", "), known_type_types.join(", ")]
|
13
|
+
WHERE
|
14
|
+
t.typname IN (%s)
|
15
|
+
OR t.typtype IN (%s)
|
16
|
+
OR (t.typarray = 0 AND t.typcategory='A')
|
17
|
+
OR t.typelem != 0
|
18
|
+
SQL
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
PostgreSQL::OID::TypeMapInitializer.prepend(TypeMapInitializer)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -20,12 +20,11 @@ module ActiveRecord
|
|
20
20
|
# but when creating objects, using RGeo features is more convenient than
|
21
21
|
# converting to WKB, so this does it automatically.
|
22
22
|
def _quote(value)
|
23
|
-
|
24
|
-
when Numeric
|
23
|
+
if value.is_a?(Numeric)
|
25
24
|
"'#{quote_string(value.to_s)}'"
|
26
|
-
|
25
|
+
elsif RGeo::Feature::Geometry.check_type(value)
|
27
26
|
"'#{RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(value)}'"
|
28
|
-
|
27
|
+
elsif value.is_a?(RGeo::Cartesian::BoundingBox)
|
29
28
|
"'#{value.min_x},#{value.min_y},#{value.max_x},#{value.max_y}'::box"
|
30
29
|
else
|
31
30
|
super
|
@@ -39,41 +39,32 @@ module ActiveRecord
|
|
39
39
|
nil
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
default_value = extract_value_from_default(default)
|
50
|
-
|
51
|
-
default_function = extract_default_function(default_value, default)
|
52
|
-
new_column(table_name, column_name, default_value, cast_type, type_metadata, !notnull,
|
53
|
-
default_function, collation, comment)
|
54
|
-
end
|
55
|
-
end
|
42
|
+
# override
|
43
|
+
# https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L624
|
44
|
+
def new_column_from_field(table_name, field)
|
45
|
+
column_name, type, default, notnull, oid, fmod, collation, comment = field
|
46
|
+
type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
|
47
|
+
default_value = extract_value_from_default(default)
|
48
|
+
default_function = extract_default_function(default_value, default)
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
null = (null == "t")
|
62
|
-
end
|
50
|
+
serial =
|
51
|
+
if (match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/))
|
52
|
+
sequence_name_from_parts(table_name, column_name, match[:suffix]) == match[:sequence_name]
|
53
|
+
end
|
63
54
|
|
64
|
-
|
55
|
+
# {:dimension=>2, :has_m=>false, :has_z=>false, :name=>"latlon", :srid=>0, :type=>"GEOMETRY"}
|
56
|
+
spatial = spatial_column_info(table_name).get(column_name, type_metadata.sql_type)
|
65
57
|
|
66
|
-
|
58
|
+
PostgreSQL::Column.new(
|
67
59
|
column_name,
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
table_name,
|
60
|
+
default_value,
|
61
|
+
type_metadata,
|
62
|
+
!notnull,
|
72
63
|
default_function,
|
73
|
-
collation,
|
74
|
-
comment,
|
75
|
-
|
76
|
-
|
64
|
+
collation: collation,
|
65
|
+
comment: comment.presence,
|
66
|
+
serial: serial,
|
67
|
+
spatial: spatial
|
77
68
|
)
|
78
69
|
end
|
79
70
|
|
@@ -103,11 +94,36 @@ module ActiveRecord
|
|
103
94
|
end
|
104
95
|
# The call to super might have appeneded [] already.
|
105
96
|
if array && type != :primary_key && !sql.end_with?("[]")
|
106
|
-
sql = "#{sql}[]"
|
97
|
+
sql = "#{sql}[]"
|
107
98
|
end
|
108
99
|
sql
|
109
100
|
end
|
110
101
|
|
102
|
+
# This overrides the method from PostegreSQL adapter
|
103
|
+
# Resets the sequence of a table's primary key to the maximum value.
|
104
|
+
def reset_pk_sequence!(table, pk = nil, sequence = nil)
|
105
|
+
unless pk && sequence
|
106
|
+
default_pk, default_sequence = pk_and_sequence_for(table)
|
107
|
+
|
108
|
+
pk ||= default_pk
|
109
|
+
sequence ||= default_sequence
|
110
|
+
end
|
111
|
+
|
112
|
+
if @logger && pk && !sequence
|
113
|
+
@logger.warn "#{table} has primary key #{pk} with no default sequence."
|
114
|
+
end
|
115
|
+
|
116
|
+
if pk && sequence
|
117
|
+
quoted_sequence = quote_table_name(sequence)
|
118
|
+
max_pk = query_value("SELECT MAX(#{quote_column_name pk}) FROM #{quote_table_name(table)}", "SCHEMA")
|
119
|
+
if max_pk.nil?
|
120
|
+
minvalue = query_value("SELECT seqmin FROM pg_sequence WHERE seqrelid = #{quote(quoted_sequence)}::regclass", "SCHEMA")
|
121
|
+
end
|
122
|
+
|
123
|
+
query_value("SELECT setval(#{quote(quoted_sequence)}, #{max_pk ? max_pk : minvalue}, #{max_pk ? true : false})", "SCHEMA")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
111
127
|
# override
|
112
128
|
def native_database_types
|
113
129
|
# Add spatial types
|
@@ -127,7 +143,7 @@ module ActiveRecord
|
|
127
143
|
|
128
144
|
# override
|
129
145
|
def create_table_definition(*args, **kwargs)
|
130
|
-
CockroachDB::TableDefinition.new(*args, **kwargs)
|
146
|
+
CockroachDB::TableDefinition.new(self, *args, **kwargs)
|
131
147
|
end
|
132
148
|
|
133
149
|
# memoize hash of column infos for tables
|
@@ -8,16 +8,22 @@ module ActiveRecord
|
|
8
8
|
# transactions that fail due to serialization errors. Failed
|
9
9
|
# transactions will be retried until they pass or the max retry limit is
|
10
10
|
# exceeded.
|
11
|
-
def within_new_transaction(
|
12
|
-
attempts = options.fetch(:attempts, 0)
|
11
|
+
def within_new_transaction(isolation: nil, joinable: true, attempts: 0)
|
13
12
|
super
|
14
|
-
rescue ActiveRecord::
|
13
|
+
rescue ActiveRecord::StatementInvalid => error
|
14
|
+
raise unless retryable? error
|
15
15
|
raise if attempts >= @connection.max_transaction_retries
|
16
16
|
|
17
17
|
attempts += 1
|
18
18
|
sleep_seconds = (2 ** attempts + rand) / 10
|
19
19
|
sleep(sleep_seconds)
|
20
|
-
within_new_transaction(
|
20
|
+
within_new_transaction(isolation: isolation, joinable: joinable, attempts: attempts) { yield }
|
21
|
+
end
|
22
|
+
|
23
|
+
def retryable?(error)
|
24
|
+
return true if error.is_a? ActiveRecord::SerializationFailure
|
25
|
+
return retryable? error.cause if error.cause
|
26
|
+
false
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
@@ -13,6 +13,7 @@ require "active_record/connection_adapters/cockroachdb/attribute_methods"
|
|
13
13
|
require "active_record/connection_adapters/cockroachdb/column"
|
14
14
|
require "active_record/connection_adapters/cockroachdb/spatial_column_info"
|
15
15
|
require "active_record/connection_adapters/cockroachdb/setup"
|
16
|
+
require "active_record/connection_adapters/cockroachdb/oid/type_map_initializer"
|
16
17
|
require "active_record/connection_adapters/cockroachdb/oid/spatial"
|
17
18
|
require "active_record/connection_adapters/cockroachdb/arel_tosql"
|
18
19
|
|
@@ -36,10 +37,14 @@ module ActiveRecord
|
|
36
37
|
valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:sslmode, :application_name]
|
37
38
|
conn_params.slice!(*valid_conn_param_keys)
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
conn = PG.connect(conn_params)
|
41
|
+
ConnectionAdapters::CockroachDBAdapter.new(conn, logger, conn_params, config)
|
42
|
+
rescue ::PG::Error, ActiveRecord::ActiveRecordError => error
|
43
|
+
if error.message.include?("does not exist")
|
44
|
+
raise ActiveRecord::NoDatabaseError
|
45
|
+
else
|
46
|
+
raise
|
47
|
+
end
|
43
48
|
end
|
44
49
|
end
|
45
50
|
end
|
@@ -75,9 +80,11 @@ module ActiveRecord
|
|
75
80
|
# override
|
76
81
|
# This method makes a sql query to gather information about columns
|
77
82
|
# in a table. It returns an array of arrays (one for each col) and
|
78
|
-
#
|
83
|
+
# passes each to the SchemaStatements#new_column_from_field method
|
84
|
+
# as the field parameter. This data is then used to format the column
|
85
|
+
# objects for the model and sent to the OID for data casting.
|
79
86
|
#
|
80
|
-
# The issue with the default method is that the sql_type field is
|
87
|
+
# The issue with the default method is that the sql_type field is
|
81
88
|
# retrieved with the `format_type` function, but this is implemented
|
82
89
|
# differently in CockroachDB than PostGIS, so geometry/geography
|
83
90
|
# types are missing information which makes parsing them impossible.
|
@@ -90,7 +97,7 @@ module ActiveRecord
|
|
90
97
|
#
|
91
98
|
# The solution is to make the default query with super, then
|
92
99
|
# iterate through the columns and if it is a spatial type,
|
93
|
-
# access the proper column_type with the information_schema.columns
|
100
|
+
# access the proper column_type with the information_schema.columns
|
94
101
|
# table.
|
95
102
|
#
|
96
103
|
# @see: https://github.com/rails/rails/blob/8695b028261bdd244e254993255c6641bdbc17a5/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L829
|
@@ -171,11 +178,6 @@ module ActiveRecord
|
|
171
178
|
false
|
172
179
|
end
|
173
180
|
|
174
|
-
def supports_ranges?
|
175
|
-
# See cockroachdb/cockroach#17022
|
176
|
-
false
|
177
|
-
end
|
178
|
-
|
179
181
|
def supports_materialized_views?
|
180
182
|
false
|
181
183
|
end
|
@@ -216,6 +218,10 @@ module ActiveRecord
|
|
216
218
|
@crdb_version >= 202
|
217
219
|
end
|
218
220
|
|
221
|
+
def supports_partitioned_indexes?
|
222
|
+
false
|
223
|
+
end
|
224
|
+
|
219
225
|
# This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
|
220
226
|
# migration from PostgreSQL to CockroachDB. In practice, this limitation
|
221
227
|
# is arbitrary since CockroachDB supports index name lengths and table alias
|
@@ -249,7 +255,13 @@ module ActiveRecord
|
|
249
255
|
end
|
250
256
|
@crdb_version = version_num
|
251
257
|
end
|
252
|
-
|
258
|
+
|
259
|
+
def self.database_exists?(config)
|
260
|
+
!!ActiveRecord::Base.cockroachdb_connection(config)
|
261
|
+
rescue ActiveRecord::NoDatabaseError
|
262
|
+
false
|
263
|
+
end
|
264
|
+
|
253
265
|
private
|
254
266
|
|
255
267
|
def initialize_type_map(m = type_map)
|
@@ -391,6 +403,100 @@ module ActiveRecord
|
|
391
403
|
return "{}"
|
392
404
|
end
|
393
405
|
|
406
|
+
# override
|
407
|
+
# This method loads info about data types from the database to
|
408
|
+
# populate the TypeMap.
|
409
|
+
#
|
410
|
+
# Currently, querying from the pg_type catalog can be slow due to geo-partitioning
|
411
|
+
# so this modified query uses AS OF SYSTEM TIME '-10s' to read historical data.
|
412
|
+
def load_additional_types(oids = nil)
|
413
|
+
if @config[:use_follower_reads_for_type_introspection]
|
414
|
+
initializer = OID::TypeMapInitializer.new(type_map)
|
415
|
+
|
416
|
+
query = <<~SQL
|
417
|
+
SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
|
418
|
+
FROM pg_type as t
|
419
|
+
LEFT JOIN pg_range as r ON oid = rngtypid AS OF SYSTEM TIME '-10s'
|
420
|
+
SQL
|
421
|
+
|
422
|
+
if oids
|
423
|
+
query += "WHERE t.oid IN (%s)" % oids.join(", ")
|
424
|
+
else
|
425
|
+
query += initializer.query_conditions_for_initial_load
|
426
|
+
end
|
427
|
+
|
428
|
+
execute_and_clear(query, "SCHEMA", []) do |records|
|
429
|
+
initializer.run(records)
|
430
|
+
end
|
431
|
+
else
|
432
|
+
super
|
433
|
+
end
|
434
|
+
rescue ActiveRecord::StatementInvalid => e
|
435
|
+
raise e unless e.cause.is_a? PG::InvalidCatalogName
|
436
|
+
# use original if database is younger than 10s
|
437
|
+
super
|
438
|
+
end
|
439
|
+
|
440
|
+
# override
|
441
|
+
# This method maps data types to their proper decoder.
|
442
|
+
#
|
443
|
+
# Currently, querying from the pg_type catalog can be slow due to geo-partitioning
|
444
|
+
# so this modified query uses AS OF SYSTEM TIME '-10s' to read historical data.
|
445
|
+
def add_pg_decoders
|
446
|
+
if @config[:use_follower_reads_for_type_introspection]
|
447
|
+
@default_timezone = nil
|
448
|
+
@timestamp_decoder = nil
|
449
|
+
|
450
|
+
coders_by_name = {
|
451
|
+
"int2" => PG::TextDecoder::Integer,
|
452
|
+
"int4" => PG::TextDecoder::Integer,
|
453
|
+
"int8" => PG::TextDecoder::Integer,
|
454
|
+
"oid" => PG::TextDecoder::Integer,
|
455
|
+
"float4" => PG::TextDecoder::Float,
|
456
|
+
"float8" => PG::TextDecoder::Float,
|
457
|
+
"numeric" => PG::TextDecoder::Numeric,
|
458
|
+
"bool" => PG::TextDecoder::Boolean,
|
459
|
+
"timestamp" => PG::TextDecoder::TimestampUtc,
|
460
|
+
"timestamptz" => PG::TextDecoder::TimestampWithTimeZone,
|
461
|
+
}
|
462
|
+
|
463
|
+
known_coder_types = coders_by_name.keys.map { |n| quote(n) }
|
464
|
+
query = <<~SQL % known_coder_types.join(", ")
|
465
|
+
SELECT t.oid, t.typname
|
466
|
+
FROM pg_type as t AS OF SYSTEM TIME '-10s'
|
467
|
+
WHERE t.typname IN (%s)
|
468
|
+
SQL
|
469
|
+
|
470
|
+
coders = execute_and_clear(query, "SCHEMA", []) do |result|
|
471
|
+
result
|
472
|
+
.map { |row| construct_coder(row, coders_by_name[row["typname"]]) }
|
473
|
+
.compact
|
474
|
+
end
|
475
|
+
|
476
|
+
map = PG::TypeMapByOid.new
|
477
|
+
coders.each { |coder| map.add_coder(coder) }
|
478
|
+
@connection.type_map_for_results = map
|
479
|
+
|
480
|
+
@type_map_for_results = PG::TypeMapByOid.new
|
481
|
+
@type_map_for_results.default_type_map = map
|
482
|
+
@type_map_for_results.add_coder(PG::TextDecoder::Bytea.new(oid: 17, name: "bytea"))
|
483
|
+
|
484
|
+
# extract timestamp decoder for use in update_typemap_for_default_timezone
|
485
|
+
@timestamp_decoder = coders.find { |coder| coder.name == "timestamp" }
|
486
|
+
update_typemap_for_default_timezone
|
487
|
+
else
|
488
|
+
super
|
489
|
+
end
|
490
|
+
rescue ActiveRecord::StatementInvalid => e
|
491
|
+
raise e unless e.cause.is_a? PG::InvalidCatalogName
|
492
|
+
# use original if database is younger than 10s
|
493
|
+
super
|
494
|
+
end
|
495
|
+
|
496
|
+
def arel_visitor
|
497
|
+
Arel::Visitors::CockroachDB.new(self)
|
498
|
+
end
|
499
|
+
|
394
500
|
# end private
|
395
501
|
end
|
396
502
|
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:
|
4
|
+
version: 6.0.0.pre.beta.5
|
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-
|
11
|
+
date: 2021-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pg
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +62,7 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
64
|
- ".gitmodules"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- CONTRIBUTING.md
|
66
67
|
- Gemfile
|
67
68
|
- LICENSE
|
@@ -82,6 +83,7 @@ files:
|
|
82
83
|
- lib/active_record/connection_adapters/cockroachdb/database_statements.rb
|
83
84
|
- lib/active_record/connection_adapters/cockroachdb/database_tasks.rb
|
84
85
|
- lib/active_record/connection_adapters/cockroachdb/oid/spatial.rb
|
86
|
+
- lib/active_record/connection_adapters/cockroachdb/oid/type_map_initializer.rb
|
85
87
|
- lib/active_record/connection_adapters/cockroachdb/quoting.rb
|
86
88
|
- lib/active_record/connection_adapters/cockroachdb/referential_integrity.rb
|
87
89
|
- lib/active_record/connection_adapters/cockroachdb/schema_statements.rb
|
@@ -97,7 +99,7 @@ licenses:
|
|
97
99
|
- Apache-2.0
|
98
100
|
metadata:
|
99
101
|
allowed_push_host: https://rubygems.org
|
100
|
-
post_install_message:
|
102
|
+
post_install_message:
|
101
103
|
rdoc_options: []
|
102
104
|
require_paths:
|
103
105
|
- lib
|
@@ -108,12 +110,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
110
|
version: '0'
|
109
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
112
|
requirements:
|
111
|
-
- - "
|
113
|
+
- - ">"
|
112
114
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
115
|
+
version: 1.3.1
|
114
116
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
116
|
-
signing_key:
|
117
|
+
rubygems_version: 3.1.4
|
118
|
+
signing_key:
|
117
119
|
specification_version: 4
|
118
120
|
summary: CockroachDB adapter for ActiveRecord.
|
119
121
|
test_files: []
|