Skip to content

Conversation

@olavloite
Copy link
Collaborator

@olavloite olavloite commented Mar 5, 2025

Adds support for using IDENTITY columns for auto-generated primary keys.
IDENTITY columns are backed by bit-reversed sequences in Spanner. This means
that IDENTITY columns produce unique non-monotonically-increasing values
that are safe to use for primary keys in Spanner.

The default id field and :primary_key type in Ruby ActiveRecord are
mapped to IDENTITY columns.

This feature is disabled by default, as it changes the default behavior
of id and :primary_key fields. These currently use a client-side
generated value. Client-side generated values support mutations, while
server-side generated primary key values cannot be used in combination
with mutations, as Spanner cannot use a THEN RETURN clause to return
these to Ruby ActiveRecord.

Add the following configuration value to your configuration to enable
auto-generated primary keys with IDENTITY columns:

default_sequence_kind: BIT_REVERSED_POSITIVE 

This feature will be enabled by default in the next major version of
this provider.

@olavloite olavloite requested a review from a team as a code owner March 5, 2025 14:14
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/ruby-spanner-activerecord API. label Mar 5, 2025
@olavloite olavloite marked this pull request as draft March 5, 2025 14:14
@olavloite olavloite force-pushed the auto-increment-primary-keys branch 10 times, most recently from bbec818 to a1b71a9 Compare March 6, 2025 11:15
Adds support for using IDENTITY columns for auto-generated primary keys. IDENTITY columns are backed by bit-reversed sequences in Spanner. This means that IDENTITY columns produce unique non-monotonically-increasing values that are safe to use for primary keys in Spanner. The default `id` field and `:primary_key` type in Ruby ActiveRecord are mapped to IDENTITY columns. This feature is disabled by default, as it changes the default behavior of `id` and `:primary_key` fields. These currently use a client-side generated value. Client-side generated values support mutations, while server-side generated primary key values cannot be used in combination with mutations, as Spanner cannot use a THEN RETURN clause to return these to Ruby ActiveRecord. Add the following configuration value to your configuration to enable auto-generated primary keys with IDENTITY columns: ``` default_sequence_kind: BIT_REVERSED_POSITIVE ``` This feature will be enabled by default in the next major version of this provider.
@olavloite olavloite force-pushed the auto-increment-primary-keys branch from a1b71a9 to 1f7129e Compare March 6, 2025 11:25
@olavloite olavloite marked this pull request as ready for review March 6, 2025 11:25
@olavloite olavloite requested a review from hengfengli March 6, 2025 11:25
@olavloite olavloite merged commit 493847c into main Mar 17, 2025
40 checks passed
@olavloite olavloite deleted the auto-increment-primary-keys branch March 17, 2025 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/ruby-spanner-activerecord API.

2 participants