-
Notifications
You must be signed in to change notification settings - Fork 44
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: Add SchemaPatch CLI command #1250
Conversation
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.
Mostly looks good. Some questions/comments:
-
nitpick: Slight preference for
schema update
overschema patch
. -
nitpick: Slight preference for sub-router.
-
If no schema is loaded and you try to do an update, here is the output to the user:
Command:$ defradb client schema patch -f=examples/schema/patch/user-add-address.patch.json
Result:
"errors": [
{
"message": "add operation does not apply: doc is missing path: \"/user/Schema/Fields/-\": missing value",
"extensions": {
"status": 500,
"httpError": "Internal Server Error"
}
}
]
question: Is it really an internal error? seems more like invalid usage / user error? perhaps StatusBadRequest
.
Giving LGTM as these are somewhat non-blocking.
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.
LGTM
note that this command wil also be taken up in #928 to be changed slightly and tested. |
@@ -0,0 +1,3 @@ | |||
[ | |||
{ "op": "add", "path": "/user/Schema/Fields/-", "value": {"Name": "address", "Kind": "String"} } |
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.
suggestion: upper case the type
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 is to match the existing example folder types. I can update, just requires updating in both locations.
note: the endpoint expects a list of objects, e.g. |
@orpheuslummis, JSON Patch expects an array of operations so it has to be an array and it's only being decode in the
@shahzadlone, I prefer
@shahzadlone, we have 8 routes, two of which have the same prefix. Let's wait until we have a good reason for sur-routers before adding complexity. 2 matching prefixes is definitely not a good reason 😅.
It is an invalid usage but to get an appropriate error type we would need a way to flag a user error. @jsimnz probably by wrapping the error of |
I have a preference 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.
Looks good, got a couple of minor suggestions that would be good to get addressed before merge, but nothing complicated so don't wait on me once you either done them or pushed back against them :)
cli/schema_patch.go
Outdated
Short: "Update an existing schema type", | ||
Long: `Update an existing schema. | ||
|
||
Uses JSON PATCH formatting as an update DDL. |
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.
suggestion: I think update is slightly inappropriate here (is not always an update), and on this line it could simply be omitted.
Similar thoughts on the use of the word update
below, there may be better words to use (maybe just use patch
?
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.
👍
cli/schema_patch.go
Outdated
if err = cmd.Usage(); err != nil { | ||
return err | ||
} | ||
return errors.New("too many arguments") |
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.
todo: These errors should be defined in errors.go
. I think the CLI package might still only be partially migrated, but new stuff should be done in the way we want longer-term.
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.
👍
@@ -0,0 +1,3 @@ | |||
[ | |||
{ "op": "add", "path": "/user/Schema/Fields/-", "value": {"Name": "address", "Kind": "String"} } | |||
] |
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.
nitpick: (as this is a 'public' example), should really end the file with a line-break 😅
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.
👍
Indeed this is a discussion that needs to be had about the Patch system in general. If we want to be able to support single ops as a JSON object, instead of always requiring an array of ops, even for a single. My intuituin says it should always be an array for simplicity, but it might be nicer DX to allow objects for single ops. RE: @shahzadlone @fredcarle I overall agree with you Shahzad about the use of InternalServerError here, but as Fred noted, the way the errors are structured we don't really know if it is a bad request or a server error. Its not ideal but I would prefer to leave as is and we can address the nature of errors bubbling up to user (cli or http) in a diff PR. |
Codecov Report
@@ Coverage Diff @@
## develop #1250 +/- ##
===========================================
- Coverage 70.56% 70.17% -0.39%
===========================================
Files 182 183 +1
Lines 17251 17343 +92
===========================================
- Hits 12173 12171 -2
- Misses 4140 4241 +101
+ Partials 938 931 -7
|
7fea2c1
to
cfd9a45
Compare
tested this one by applying different patches using inline json strings and json files. |
* Added initial cli command for schema patch * Added PatchSchema API handler and route, updated CLI to use new endpoint * Added an example PATCH to the 'examples' folder * Updated errors * Updated examples to be more consistent * Added nolint err checks to useless err checks that were removed
* Added initial cli command for schema patch * Added PatchSchema API handler and route, updated CLI to use new endpoint * Added an example PATCH to the 'examples' folder * Updated errors * Updated examples to be more consistent * Added nolint err checks to useless err checks that were removed
Relevant issue(s)
Resolves #1209
Description
A fairly straightforward implementation of the
PatchSchema
CLI command. Defined asdefradb client schema patch
. Has almost identical structure and semantics asschema add
, including support for file, stdin, and raw string inputs.Updated the API handlers as well to expose
db.PatchSchema
, again mostly a carbon copy of the existing load schema endpoint.Made a judgment call on the name
schema patch
instead of something likeschema update
. I have no strong opinion here.I don't think its worth it yet, but since this is the first API endpoint to have a common prefix, there is an argument to be made for making a sub router, but things are still pretty simple, so didn't bother going down that route 🙃 (pun intended).
Tasks
How has this been tested?
Manually, no CLI tests at the moment.
Specify the platform(s) on which this was tested: