Skip to content

Commit 38dea37

Browse files
committed
Handle empty array default values
1 parent f9b0d4e commit 38dea37

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

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
@@ -114,6 +114,10 @@ def supports_virtual_columns?
114114
false
115115
end
116116

117+
def supports_string_to_array_coercion?
118+
@crdb_version >= 202
119+
end
120+
117121
# This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
118122
# migration from PostgreSQL to CockroachDB. In practice, this limitation
119123
# is arbitrary since CockroachDB supports index name lengths and table alias
@@ -220,7 +224,8 @@ def configure_connection
220224
def extract_value_from_default(default)
221225
super ||
222226
extract_escaped_string_from_default(default) ||
223-
extract_time_from_default(default)
227+
extract_time_from_default(default) ||
228+
extract_empty_array_from_default(default)
224229
end
225230

226231
# Both PostgreSQL and CockroachDB use C-style string escapes under the
@@ -262,6 +267,15 @@ def extract_time_from_default(default)
262267
nil
263268
end
264269

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