feat: interleaved tables with built-in composite pk#282
Conversation
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
| @@ -0,0 +1,20 @@ | |||
| # Copyright 2022 Google LLC | |||
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
Are these changes (before 7.1) migrated from the previous code/doc?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
why do we need to move albumid?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
same here. Why do we move trackid?
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
does activerecord_spanner_interleaved_table_7_1 mean < 7.1 or >=7.1 or ==7.1?
There was a problem hiding this comment.
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
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