Skip to content

Commit 57ca51a

Browse files
authored
Merge branch 'master' into feature/rails-6-update
2 parents 62e3995 + 078d4fd commit 57ca51a

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
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 = "6.0.0"
7+
spec.version = "6.0.0beta1"
88
spec.licenses = ["Apache-2.0"]
99
spec.authors = ["Cockroach Labs"]
1010
spec.email = ["[email protected]"]

build/teamcity-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -euox pipefail
44

55
# Download CockroachDB
6-
VERSION=v20.2.0-beta.3
6+
VERSION=v20.2.1
77
wget -qO- https://binaries.cockroachdb.com/cockroach-$VERSION.linux-amd64.tgz | tar xvz
88
readonly COCKROACH=./cockroach-$VERSION.linux-amd64/cockroach
99

lib/active_record/connection_adapters/cockroachdb_adapter.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def supports_virtual_columns?
116116
false
117117
end
118118

119+
def supports_string_to_array_coercion?
120+
@crdb_version >= 202
121+
end
122+
119123
# This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
120124
# migration from PostgreSQL to CockroachDB. In practice, this limitation
121125
# is arbitrary since CockroachDB supports index name lengths and table alias
@@ -222,7 +226,8 @@ def configure_connection
222226
def extract_value_from_default(default)
223227
super ||
224228
extract_escaped_string_from_default(default) ||
225-
extract_time_from_default(default)
229+
extract_time_from_default(default) ||
230+
extract_empty_array_from_default(default)
226231
end
227232

228233
# Both PostgreSQL and CockroachDB use C-style string escapes under the
@@ -264,6 +269,15 @@ def extract_time_from_default(default)
264269
nil
265270
end
266271

272+
# CockroachDB stores default values for arrays in the `ARRAY[...]` format.
273+
# In general, it is hard to parse that, but it is easy to handle the common
274+
# case of an empty array.
275+
def extract_empty_array_from_default(default)
276+
return unless supports_string_to_array_coercion?
277+
return unless default =~ /\AARRAY\[\]\z/
278+
return "{}"
279+
end
280+
267281
# end private
268282
end
269283
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)