-
Notifications
You must be signed in to change notification settings - Fork 46
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
feat: Allow setting of default schema version #1888
feat: Allow setting of default schema version #1888
Conversation
4a6e816
to
c309b76
Compare
Codecov ReportPatch coverage:
@@ Coverage Diff @@
## develop #1888 +/- ##
===========================================
- Coverage 70.82% 70.74% -0.08%
===========================================
Files 233 233
Lines 24232 24295 +63
===========================================
+ Hits 17160 17186 +26
- Misses 5901 5937 +36
- Partials 1171 1172 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
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.
I left some feedback about the public API portions.
// provided. This includes GQL queries and Collection operations. | ||
// | ||
// It will return an error if the provided schema version ID does not exist. | ||
SetDefaultSchemaVersion(context.Context, string) error |
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.
This was confusing for me at first. What do you think about moving this to the Collection interface instead? I think it would be more clear exactly which Collection you are setting a default for.
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.
I don't like that, as if forces users to get a collection object when all they need is the ID, I also like the proximity to PatchSchema
.
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 simplicity is nice but I can see many users getting confused.
This is the use case I see being used most often when you don't know the schema version id:
cols := db.GetAllCollections()
for _, col := range cols {
if isMatchingCollection(col) {
col.SetDefaultSchemaVersion()
}
}
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.
I do disagree :) I see the most common use case to within a migration script:
defradb patchSchema jsonStuff
...
defradb setDefaultSchemaVersion [schemaVersionID]
if it was on the collection object it would be a bit more complicated no, would look something like the below no?
defradb collection [collectionID] setDefaultSchemaVersion [schemaVersionID]
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.
It's definitely more verbose but it's also much easier to parse what that command is doing.
No need to block the PR. I think we could add the shortcut function in the future if users have trouble with it.
@@ -109,7 +110,16 @@ type Store interface { | |||
// | |||
// Field [FieldKind] values may be provided in either their raw integer form, or as string as per | |||
// [FieldKindStringToEnumMapping]. | |||
PatchSchema(context.Context, string) error | |||
PatchSchema(context.Context, string, bool) error |
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.
What are your thoughts on inverting the boolean usage here?
I think it'd be nice when using the http or cli interfaces that the lack of the boolean would indicate the original functionality of setting the default.
Requiring an extra --set-default-schema
cli flag or SetDefaultSchema
http property would break backwards compatibility.
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.
I want switching schema versions to be an explicit choice - it is a major, and likely breaking, change to the user's database and I don't want them to do it accidentally via parameter omission.
@@ -418,6 +418,9 @@ func executeTestCase( | |||
case SchemaPatch: | |||
patchSchema(s, action) | |||
|
|||
case SetDefaultSchemaVersion: |
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.
I think we'll want this action included in the change detector setup steps.
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.
I don't think we do. Normal tests will just set the PatchSchema change to default using the bool, tests that use this action are perhaps going to benefit more from having this in the main (post setup) stage, as they are more likely to be testing that SetDefaultSchemaVersion works.
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.
Looks good! From the discussion there's a minor API addition that we may revisit if needed.
It will be called from other locations shortly, and may be optional within the original source function.
Will allow users to change their default database schema versions on demand, allowing rapid switching between (application) api/database versions. It also allows them to define and apply schema updates eagerly, and then make the switch at a later date.
c309b76
to
9b72197
Compare
## Relevant issue(s) Resolves #1884 ## Description Allows setting of default schema version, allowing rapid switching between (application) api/database versions. It also allows them to define and apply schema updates eagerly, and then make the switch at a later date.
## Relevant issue(s) Resolves sourcenetwork#1884 ## Description Allows setting of default schema version, allowing rapid switching between (application) api/database versions. It also allows them to define and apply schema updates eagerly, and then make the switch at a later date.
Relevant issue(s)
Resolves #1884
Description
Allows setting of default schema version, allowing rapid switching between (application) api/database versions. It also allows them to define and apply schema updates eagerly, and then make the switch at a later date.