Skip to content

feat: interleaved tables with built-in composite pk#282

Merged
olavloite merged 16 commits into
mainfrom
interleaved-tables-7-1
Dec 20, 2023
Merged

feat: interleaved tables with built-in composite pk#282
olavloite merged 16 commits into
mainfrom
interleaved-tables-7-1

Conversation

@olavloite

Copy link
Copy Markdown
Collaborator

Adds support for interleaved tables using the built-in support for composite primary keys in Rails 7.1. The original support for interleaved tables using the third-party composite-primary-key gem still works for Rails vresions < 7.1. Anyone updgrading from Rails 7.0 to 7.1 and using interleaved tables must update their code to use the new built-in feature for composite primary keys, and must remove the third-party composite primary keys gem. The latter will automatically show up as a problem, as there is no version of that gem that supports Rails 7.1.

Fixes #281

Adds support for interleaved tables using the built-in support for
composite primary keys in Rails 7.1. The original support for
interleaved tables using the third-party composite-primary-key gem
still works for Rails vresions < 7.1. Anyone updgrading from Rails 7.0
to 7.1 and using interleaved tables must update their code to use the
new built-in feature for composite primary keys, and must remove the
third-party composite primary keys gem. The latter will automatically
show up as a problem, as there is no version of that gem that supports
Rails 7.1.

Fixes #281
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the googleapis/ruby-spanner-activerecord API. label Dec 7, 2023
@olavloite olavloite marked this pull request as ready for review December 10, 2023 13:16
@olavloite olavloite requested review from a team and hengfengli December 10, 2023 13:16
Base automatically changed from rails-7-1 to main December 13, 2023 14:07

@hengfengli hengfengli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,20 @@
# Copyright 2022 Google LLC

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2023?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the existing sample for using the third-party composite primary key gem. GitHub is just not very good at showing a change that renames a folder.

@@ -0,0 +1,167 @@
# Sample - Interleaved Tables - Before Rails 7.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes (before 7.1) migrated from the previous code/doc?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just renamed the folder where they are in, but GitHub shows it like it's all new.

CREATE TABLE albums (
albumid INT64 NOT NULL,
singerid INT64 NOT NULL,
albumid INT64 NOT NULL,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to move albumid?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order in which the columns are generated by Ruby on Rails 7.1 is different from how they were generated by the composite-pk third-party gem that we used before. I updated the order in the README as well so it corresponds 100% with the actual table that is created.

trackid INT64 NOT NULL,
singerid INT64 NOT NULL,
albumid INT64 NOT NULL,
trackid INT64 NOT NULL,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. Why do we move trackid?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as with albumid, Ruby on Rails 7.1 generates the columns in a different order than the third-party composite-pk gem.

@@ -0,0 +1,16 @@
# Copyright 2023 Google LLC

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does activerecord_spanner_interleaved_table_7_1 mean < 7.1 or >=7.1 or ==7.1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means >=7.1. I changed the name to better reflect that.

* feat: support bit-reversed sequences

* chore: cleanup

* fix: add pk to returning statement for Rails 7.1 and higher

* chore: fix rubocop issues

* test: add mock server + acceptance tests

* test: fix expected sql for prod

* fix: only check positive ID for prod

* docs: add example for using bit-reversed sequence
@olavloite olavloite merged commit e053973 into main Dec 20, 2023
@olavloite olavloite deleted the interleaved-tables-7-1 branch December 20, 2023 11:03
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support built-in composite primary keys with interleaved tables

2 participants