Skip to content

Commit

Permalink
Merge pull request #171 from rafiss/release-5.2.2
Browse files Browse the repository at this point in the history
Release 5.2.2
  • Loading branch information
otan authored Jan 13, 2021
2 parents 24d57b2 + 0a7f7e8 commit 8b4fe9c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CockroachDB adapter for ActiveRecord 4 and 5. This is a lightweight extension of
Add this line to your project's Gemfile:

```ruby
gem 'activerecord-cockroachdb-adapter', '~> 0.2'
gem 'activerecord-cockroachdb-adapter', '~> 5.2.0'
```

If you're using Rails 4.x, use the `0.1.x` versions of this gem.
Expand Down
2 changes: 1 addition & 1 deletion activerecord-cockroachdb-adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "activerecord-cockroachdb-adapter"
spec.version = "5.2.0"
spec.version = "5.2.2"
spec.licenses = ["Apache-2.0"]
spec.authors = ["Cockroach Labs"]
spec.email = ["[email protected]"]
Expand Down
16 changes: 15 additions & 1 deletion lib/active_record/connection_adapters/cockroachdb_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ def supports_virtual_columns?
false
end

def supports_string_to_array_coercion?
@crdb_version >= 202
end

# This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
# migration from PostgreSQL to CockroachDB. In practice, this limitation
# is arbitrary since CockroachDB supports index name lengths and table alias
Expand Down Expand Up @@ -335,7 +339,8 @@ def configure_connection
def extract_value_from_default(default)
super ||
extract_escaped_string_from_default(default) ||
extract_time_from_default(default)
extract_time_from_default(default) ||
extract_empty_array_from_default(default)
end

# Both PostgreSQL and CockroachDB use C-style string escapes under the
Expand Down Expand Up @@ -377,6 +382,15 @@ def extract_time_from_default(default)
nil
end

# CockroachDB stores default values for arrays in the `ARRAY[...]` format.
# In general, it is hard to parse that, but it is easy to handle the common
# case of an empty array.
def extract_empty_array_from_default(default)
return unless supports_string_to_array_coercion?
return unless default =~ /\AARRAY\[\]\z/
return "{}"
end

# end private
end
end
Expand Down
1 change: 0 additions & 1 deletion test/excludes/PostgresqlUUIDTest.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exclude :test_uniqueness_validation_ignores_uuid, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
exclude :test_add_column_with_default_array, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
exclude :test_change_column_default, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
exclude :test_uuid_formats, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"

0 comments on commit 8b4fe9c

Please sign in to comment.