-
Notifications
You must be signed in to change notification settings - Fork 51
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,8 @@ type Store interface { | |
AddSchema(context.Context, string) ([]CollectionDescription, error) | ||
|
||
// PatchSchema takes the given JSON patch string and applies it to the set of CollectionDescriptions | ||
// present in the database. | ||
// present in the database. If true is provided, the new schema versions will be made default, otherwise | ||
// [SetDefaultSchemaVersion] should be called to set them so. | ||
// | ||
// It will also update the GQL types used by the query system. It will error and not apply any of the | ||
// requested, valid updates should the net result of the patch result in an invalid state. The | ||
|
@@ -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 | ||
|
||
// SetDefaultSchemaVersion sets the default schema version to the ID provided. It will be applied to all | ||
// collections using the schema. | ||
// | ||
// This will affect all operations interacting with the schema where a schema version is not explicitly | ||
// 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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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:
if it was on the collection object it would be a bit more complicated no, would look something like the below no?
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
// SetMigration sets the migration for the given source-destination schema version IDs. Is equivilent to | ||
// calling `LensRegistry().SetMigration(ctx, cfg)`. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 orSetDefaultSchema
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.