Repository navigation
refactor: Enable table primary keys to have other types than int - #3257
Merged
SandPod merged 12 commits intoMar 10, 2025
Merged
Conversation
Contributor
|
Awesome work! Will take a look at this first thing tomorrow morning! 👍 |
SandPod
reviewed
Feb 26, 2025
SandPod
left a comment
Contributor
There was a problem hiding this comment.
Nice clean PR!
Had a couple of comments and suggestions.
We might want to hold off a bit while merging this to get the 3.4 release out of the way.
SandPod
reviewed
Mar 6, 2025
SandPod
left a comment
Contributor
There was a problem hiding this comment.
Changes look good now! Have a last possible change to ensure that we don't add more coupling between our columns class and the sql query builder.
We want to ensure we don't forget about the type, but we don't necessarily want to build (more) sql strings outside of the sql query generator.
SandPod
approved these changes
Mar 10, 2025
SandPod
left a comment
Contributor
There was a problem hiding this comment.
Changes look good to me! Nice diligent work! 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR enables the feature #3255 implementation by removing the core premise of the serverpod package that table ids are exclusively of int type. To do this, the following changes were made:
ComparableColumn<T>. This is the type of valid id columns and implements equality and inequality comparison. All types that have such comparison options on postgres are nowComparableColunn. With this, the string and uuid types can now be compared using less than/more than (and the equal to variant) operators, as supported by Postgres.TableandTableRowconcept classes are now generic to the type of the ID attribute, with theTableRow<T_ID>.idbeing of typeComparableColunn<T_ID>. On theDatabaselevel and below, references to the id column were changed toObjectinstead ofintand all server models were re-generated.ObjectRelationDefinitionandListRelationDefinitionobjects now store the id type of the table that owns the FK field. This reference is used to pass theT_IDgeneric reference to build the attach/detach repository methods on the server models.The PR contains tests of the changes, with an exception of one test that will be added on a subsequent PR of the feature #3255: the test that the stored FK field type on the relation objects is being collected from the correct model. The test exists on the #3152 draft PR, but it requires that more than one type of id is already implemented. Otherwise, it is not be possible to assert that the collected
inttype comes from one or other model of the relation.Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
After the PR, users will have to run
serverpod generateagain to update the models. However, it is already part of the update routine and not considered a breaking change.