Skip to content

Commit c3bbb75

Browse files
committed
feat: support ActiveRecord 8.1.x
Adds support for ActiveRecord 8.1.x.
1 parent 453e85f commit c3bbb75

File tree

12 files changed

+83
-30
lines changed

12 files changed

+83
-30
lines changed

.github/workflows/acceptance-tests-on-emulator.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ jobs:
1919
max-parallel: 4
2020
matrix:
2121
ruby: ["3.1", "3.2", "3.3", "3.4"]
22-
ar: ["~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"]
22+
ar: ["~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0", "~> 8.1.0"]
2323
# Exclude combinations that are not supported.
2424
exclude:
2525
- ruby: "3.1"
2626
ar: "~> 8.0.0"
27+
- ruby: "3.1"
28+
ar: "~> 8.1.0"
2729
- ruby: "3.4"
2830
ar: "~> 7.0.0"
2931
- ruby: "3.4"

.github/workflows/ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ jobs:
1111
max-parallel: 4
1212
matrix:
1313
ruby: ["3.1", "3.2", "3.3", "3.4"]
14-
ar: ["~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"]
14+
ar: ["~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0", "~> 8.1.0"]
1515
# Exclude combinations that are not supported.
1616
exclude:
1717
- ruby: "3.1"
1818
ar: "~> 8.0.0"
19+
- ruby: "3.1"
20+
ar: "~> 8.1.0"
1921
- ruby: "3.4"
2022
ar: "~> 7.0.0"
2123
- ruby: "3.4"

.github/workflows/nightly-acceptance-tests-on-emulator.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ jobs:
1919
max-parallel: 4
2020
matrix:
2121
ruby: ["3.1", "3.2", "3.3", "3.4"]
22-
ar: ["~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"]
22+
ar: ["~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0", "~> 8.1.0"]
2323
# Exclude combinations that are not supported.
2424
exclude:
2525
- ruby: "3.1"
2626
ar: "~> 8.0.0"
27+
- ruby: "3.1"
28+
ar: "~> 8.1.0"
2729
- ruby: "3.4"
2830
ar: "~> 7.0.0"
2931
- ruby: "3.4"

.github/workflows/nightly-unit-tests.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ jobs:
1212
matrix:
1313
# Run acceptance tests all supported combinations of Ruby and ActiveRecord.
1414
ruby: ["3.1", "3.2", "3.3", "3.4"]
15-
ar: ["~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"]
15+
ar: ["~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0", "~> 8.1.0"]
1616
# Exclude combinations that are not supported.
1717
exclude:
1818
- ruby: "3.1"
1919
ar: "~> 8.0.0"
20+
- ruby: "3.1"
21+
ar: "~> 8.1.0"
2022
- ruby: "3.4"
2123
ar: "~> 7.0.0"
2224
- ruby: "3.4"

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ source "https://rubygems.org"
33
# Specify your gem's dependencies in activerecord-spanner.gemspec
44
gemspec
55

6-
ar_version = ENV.fetch("AR_VERSION", "~> 7.1.0")
6+
ar_version = ENV.fetch("AR_VERSION", "~> 8.1.0")
77
gem "activerecord", ar_version
88
gem "ostruct"
99
gem "minitest", "~> 5.27.0"
10-
gem "minitest-rg", "~> 5.3.0"
10+
gem "minitest-rg", "~> 5.4.0"
1111
gem "pry", "~> 0.14.2"
1212
gem "pry-byebug", "~> 3.11.0"
1313
gem "mutex_m"

acceptance/cases/migration/index_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_rename_index_too_long
5757
e = assert_raises(ArgumentError) {
5858
connection.rename_index(table_name, "old_idx", too_long_index_name)
5959
}
60-
assert_match(/too long; the limit is #{connection.index_name_length} characters/, e.message)
60+
assert_match(/too long/, e.message)
6161

6262
assert connection.index_name_exists?(table_name, "old_idx")
6363
end
@@ -79,7 +79,7 @@ def test_add_index_does_not_accept_too_long_index_names
7979
e = assert_raises(ArgumentError) {
8080
connection.add_index(table_name, "foo", name: too_long_index_name)
8181
}
82-
assert_match(/too long; the limit is #{connection.index_name_length} characters/, e.message)
82+
assert_match(/too long/, e.message)
8383

8484
assert_not connection.index_name_exists?(table_name, too_long_index_name)
8585
connection.add_index(table_name, "foo", name: good_index_name)

activerecord-spanner-adapter.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Gem::Specification.new do |spec|
2929
spec.add_runtime_dependency "activerecord", [">= 7.0", "< 9"]
3030

3131
spec.add_development_dependency "autotest-suffix", "~> 1.1"
32-
spec.add_development_dependency "bundler", "~> 2.0"
32+
spec.add_development_dependency "bundler", [">= 2.0", "< 5.0"]
3333
spec.add_development_dependency "google-style", "~> 1.31.0"
3434
spec.add_development_dependency "minitest", "~> 5.10"
3535
spec.add_development_dependency "minitest-autotest", "~> 1.0"
3636
spec.add_development_dependency "minitest-focus", "~> 1.1"
37-
spec.add_development_dependency "minitest-rg", "~> 5.2"
37+
spec.add_development_dependency "minitest-rg", "~> 5.4"
3838
spec.add_development_dependency "rake", "~> 13.0"
3939
spec.add_development_dependency "redcarpet", "~> 3.0"
4040
spec.add_development_dependency "simplecov", "~> 0.9"

lib/active_record/connection_adapters/spanner/column.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,26 @@ module ActiveRecord
1010
module ConnectionAdapters
1111
module Spanner
1212
class Column < ConnectionAdapters::Column
13-
# rubocop:disable Style/OptionalBooleanParameter
14-
def initialize(name, default, sql_type_metadata = nil, null = true,
15-
default_function = nil, collation: nil, comment: nil,
16-
primary_key: false, **)
17-
# rubocop:enable Style/OptionalBooleanParameter
18-
super
19-
@primary_key = primary_key
13+
VERSION_8_1 = Gem::Version.create "8.1.0"
14+
15+
if ActiveRecord.gem_version < VERSION_8_1
16+
# rubocop:disable Style/OptionalBooleanParameter
17+
def initialize(name, default, sql_type_metadata = nil, null = true,
18+
default_function = nil, collation: nil, comment: nil,
19+
primary_key: false, **)
20+
# rubocop:enable Style/OptionalBooleanParameter
21+
super
22+
@primary_key = primary_key
23+
end
24+
else
25+
# rubocop:disable Style/OptionalBooleanParameter
26+
def initialize(name, cast_type, default, sql_type_metadata = nil, null = true,
27+
default_function = nil, collation: nil, comment: nil,
28+
primary_key: false, **)
29+
# rubocop:enable Style/OptionalBooleanParameter
30+
super
31+
@primary_key = primary_key
32+
end
2033
end
2134

2235
def auto_incremented_by_db?

lib/active_record/connection_adapters/spanner/schema_creation.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ def add_column_options! column, sql, options
138138
sql << " NOT NULL"
139139
end
140140
if options.key? :default
141-
sql << " DEFAULT (#{quote_default_expression options[:default], column})"
141+
sql << if respond_to? :quote_default_expression_for_column_definition, :include_private
142+
" DEFAULT (#{quote_default_expression_for_column_definition options[:default], column})"
143+
else
144+
" DEFAULT (#{quote_default_expression options[:default], column})"
145+
end
142146
elsif column.type == :primary_key
143147
if @connection.use_auto_increment?
144148
sql << " AUTO_INCREMENT"

lib/active_record/connection_adapters/spanner/schema_statements.rb

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Spanner
2222
#
2323
module SchemaStatements
2424
VERSION_7_2 = Gem::Version.create "7.2.0"
25+
VERSION_8_1 = Gem::Version.create "8.1.0"
2526

2627
def current_database
2728
@connection.database_id
@@ -116,18 +117,37 @@ def column_definitions table_name
116117
information_schema { |i| i.table_columns table_name }
117118
end
118119

119-
def new_column_from_field _table_name, field, _definitions = nil
120-
Spanner::Column.new \
121-
field.name,
122-
field.default,
123-
fetch_type_metadata(field.spanner_type,
124-
field.ordinal_position,
125-
field.allow_commit_timestamp,
126-
field.generated,
127-
is_identity: field.is_identity),
128-
field.nullable,
129-
field.default_function,
130-
primary_key: field.primary_key
120+
if ActiveRecord.gem_version < VERSION_8_1
121+
def new_column_from_field _table_name, field, _definitions = nil
122+
Spanner::Column.new \
123+
field.name,
124+
field.default,
125+
fetch_type_metadata(field.spanner_type,
126+
field.ordinal_position,
127+
field.allow_commit_timestamp,
128+
field.generated,
129+
is_identity: field.is_identity),
130+
field.nullable,
131+
field.default_function,
132+
primary_key: field.primary_key
133+
end
134+
else
135+
def new_column_from_field _table_name, field, _definitions = nil
136+
cast_type = type_map.lookup field.type
137+
raise ArgumentError, "unknown type: `#{field.type}`" if cast_type.nil?
138+
Spanner::Column.new \
139+
field.name,
140+
cast_type,
141+
field.default,
142+
fetch_type_metadata(field.spanner_type,
143+
field.ordinal_position,
144+
field.allow_commit_timestamp,
145+
field.generated,
146+
is_identity: field.is_identity),
147+
field.nullable,
148+
field.default_function,
149+
primary_key: field.primary_key
150+
end
131151
end
132152

133153
def fetch_type_metadata sql_type, ordinal_position = nil, allow_commit_timestamp = nil, generated = nil,

0 commit comments

Comments
 (0)