-
Notifications
You must be signed in to change notification settings - Fork 35
feat: support ActiveRecord 8.1.x #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,26 @@ module ActiveRecord | |
| module ConnectionAdapters | ||
| module Spanner | ||
| class Column < ConnectionAdapters::Column | ||
| # rubocop:disable Style/OptionalBooleanParameter | ||
| def initialize(name, default, sql_type_metadata = nil, null = true, | ||
| default_function = nil, collation: nil, comment: nil, | ||
| primary_key: false, **) | ||
| # rubocop:enable Style/OptionalBooleanParameter | ||
| super | ||
| @primary_key = primary_key | ||
| VERSION_8_1 = Gem::Version.create "8.1.0" | ||
|
|
||
| if ActiveRecord.gem_version < VERSION_8_1 | ||
| # rubocop:disable Style/OptionalBooleanParameter | ||
| def initialize(name, default, sql_type_metadata = nil, null = true, | ||
| default_function = nil, collation: nil, comment: nil, | ||
| primary_key: false, **) | ||
| # rubocop:enable Style/OptionalBooleanParameter | ||
| super | ||
| @primary_key = primary_key | ||
| end | ||
| else | ||
| # rubocop:disable Style/OptionalBooleanParameter | ||
| def initialize(name, cast_type, default, sql_type_metadata = nil, null = true, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 8.1 introduced a new positional parameter |
||
| default_function = nil, collation: nil, comment: nil, | ||
| primary_key: false, **) | ||
| # rubocop:enable Style/OptionalBooleanParameter | ||
| super | ||
| @primary_key = primary_key | ||
| end | ||
| end | ||
olavloite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def auto_incremented_by_db? | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,7 +138,11 @@ def add_column_options! column, sql, options | |
| sql << " NOT NULL" | ||
| end | ||
| if options.key? :default | ||
| sql << " DEFAULT (#{quote_default_expression options[:default], column})" | ||
| sql << if respond_to? :quote_default_expression_for_column_definition, :include_private | ||
| " DEFAULT (#{quote_default_expression_for_column_definition options[:default], column})" | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is related to the same |
||
| else | ||
| " DEFAULT (#{quote_default_expression options[:default], column})" | ||
| end | ||
| elsif column.type == :primary_key | ||
| if @connection.use_auto_increment? | ||
| sql << " AUTO_INCREMENT" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Copyright 2026 Google LLC | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been moved to a separate file, so we can |
||
| # | ||
| # Use of this source code is governed by an MIT-style | ||
| # license that can be found in the LICENSE file or at | ||
| # https://opensource.org/licenses/MIT. | ||
| # | ||
| # frozen_string_literal: true | ||
|
|
||
| NATIVE_DATABASE_TYPES = { | ||
sakthivelmanii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| primary_key: "INT64", | ||
| parent_key: "INT64", | ||
| string: { name: "STRING", limit: "MAX" }, | ||
| text: { name: "STRING", limit: "MAX" }, | ||
| integer: { name: "INT64" }, | ||
| bigint: { name: "INT64" }, | ||
| float: { name: "FLOAT64" }, | ||
| decimal: { name: "NUMERIC" }, | ||
| numeric: { name: "NUMERIC" }, | ||
| datetime: { name: "TIMESTAMP" }, | ||
| time: { name: "TIMESTAMP" }, | ||
| date: { name: "DATE" }, | ||
| binary: { name: "BYTES", limit: "MAX" }, | ||
| boolean: { name: "BOOL" }, | ||
| json: { name: "JSON" } | ||
| }.freeze | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is slightly different in 8.1 than in the other versions. We don't really care about the specific error message, only that it is actually an error message about the index name being too long.