Skip to content

Commit 6a0232e

Browse files
committed
Merge tag 'v5.2.1' into release-5.2.2
2 parents 24d57b2 + 078d4fd commit 6a0232e

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CockroachDB adapter for ActiveRecord 4 and 5. This is a lightweight extension of
77
Add this line to your project's Gemfile:
88

99
```ruby
10-
gem 'activerecord-cockroachdb-adapter', '~> 0.2'
10+
gem 'activerecord-cockroachdb-adapter', '~> 5.2.0'
1111
```
1212

1313
If you're using Rails 4.x, use the `0.1.x` versions of this gem.

activerecord-cockroachdb-adapter.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
44

55
Gem::Specification.new do |spec|
66
spec.name = "activerecord-cockroachdb-adapter"
7-
spec.version = "5.2.0"
7+
spec.version = "5.2.1"
88
spec.licenses = ["Apache-2.0"]
99
spec.authors = ["Cockroach Labs"]
1010
spec.email = ["[email protected]"]

lib/active_record/connection_adapters/cockroachdb_adapter.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ def supports_virtual_columns?
212212
false
213213
end
214214

215+
def supports_string_to_array_coercion?
216+
@crdb_version >= 202
217+
end
218+
215219
# This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
216220
# migration from PostgreSQL to CockroachDB. In practice, this limitation
217221
# is arbitrary since CockroachDB supports index name lengths and table alias
@@ -335,7 +339,8 @@ def configure_connection
335339
def extract_value_from_default(default)
336340
super ||
337341
extract_escaped_string_from_default(default) ||
338-
extract_time_from_default(default)
342+
extract_time_from_default(default) ||
343+
extract_empty_array_from_default(default)
339344
end
340345

341346
# Both PostgreSQL and CockroachDB use C-style string escapes under the
@@ -377,6 +382,15 @@ def extract_time_from_default(default)
377382
nil
378383
end
379384

385+
# CockroachDB stores default values for arrays in the `ARRAY[...]` format.
386+
# In general, it is hard to parse that, but it is easy to handle the common
387+
# case of an empty array.
388+
def extract_empty_array_from_default(default)
389+
return unless supports_string_to_array_coercion?
390+
return unless default =~ /\AARRAY\[\]\z/
391+
return "{}"
392+
end
393+
380394
# end private
381395
end
382396
end
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
exclude :test_uniqueness_validation_ignores_uuid, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
2-
exclude :test_add_column_with_default_array, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
32
exclude :test_change_column_default, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
43
exclude :test_uuid_formats, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"

0 commit comments

Comments
 (0)