-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Relevant issue(s) Resolves #2389 ## Description Adds the PatchCollection command. Mutating anything but the collection name is currently disabled, we can expand this as we see fit, but for now I'd prefer to keep the initial PR small. This change means that the Collection Name is no longer always going to be the same as the Schema Name.
- Loading branch information
1 parent
d524320
commit c67bc56
Showing
36 changed files
with
1,798 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func MakeCollectionPatchCommand() *cobra.Command { | ||
var patchFile string | ||
var cmd = &cobra.Command{ | ||
Use: "patch [patch]", | ||
Short: "Patch existing collection descriptions", | ||
Long: `Patch existing collection descriptions. | ||
Uses JSON Patch to modify collection descriptions. | ||
Example: patch from an argument string: | ||
defradb client collection patch '[{ "op": "add", "path": "...", "value": {...} }]' | ||
Example: patch from file: | ||
defradb client collection patch -p patch.json | ||
Example: patch from stdin: | ||
cat patch.json | defradb client collection patch - | ||
To learn more about the DefraDB GraphQL Schema Language, refer to https://docs.source.network.`, | ||
Args: cobra.RangeArgs(0, 1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
store := mustGetContextStore(cmd) | ||
|
||
var patch string | ||
switch { | ||
case patchFile != "": | ||
data, err := os.ReadFile(patchFile) | ||
if err != nil { | ||
return err | ||
} | ||
patch = string(data) | ||
case len(args) > 0 && args[0] == "-": | ||
data, err := io.ReadAll(cmd.InOrStdin()) | ||
if err != nil { | ||
return err | ||
} | ||
patch = string(data) | ||
case len(args) == 1: | ||
patch = args[0] | ||
default: | ||
return fmt.Errorf("patch cannot be empty") | ||
} | ||
|
||
return store.PatchCollection(cmd.Context(), patch) | ||
}, | ||
} | ||
cmd.Flags().StringVarP(&patchFile, "patch-file", "p", "", "File to load a patch from") | ||
return cmd | ||
} |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.