Skip to content
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 schema migration get and set cmds to CLI #1650

Merged
merged 6 commits into from
Jul 18, 2023

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented Jul 18, 2023

Relevant issue(s)

Resolves #1648

Description

Adds schema migration set and schema migration get commands to the CLI, and the http API.

Command/endpoint assumes the db server has access to the file path(s) provided in the lens cfg - it will error early if it doesn't (tested manually).

I've done some manual testing of this and it looks all good. I'm happy merging this ASAP as time is now very short. Tests can be added later, possibly within this PR if I have time but do not count on it (#1652).

@AndrewSisley AndrewSisley added feature New feature or request area/schema Related to the schema system area/api Related to the external API component action/no-benchmark Skips the action that runs the benchmark. area/cli Related to the CLI binary labels Jul 18, 2023
@AndrewSisley AndrewSisley added this to the DefraDB v0.6 milestone Jul 18, 2023
@AndrewSisley AndrewSisley requested a review from a team July 18, 2023 12:31
@AndrewSisley AndrewSisley self-assigned this Jul 18, 2023
@AndrewSisley AndrewSisley force-pushed the 1648-lens-set-cli branch 2 times, most recently from 4771cfa to baa9c8e Compare July 18, 2023 12:35
@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Patch coverage: 17.36% and project coverage change: -0.76 ⚠️

Comparison is base (effd4eb) 75.65% compared to head (22a7ea0) 74.89%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1650      +/-   ##
===========================================
- Coverage    75.65%   74.89%   -0.76%     
===========================================
  Files          200      203       +3     
  Lines        20807    21072     +265     
===========================================
+ Hits         15740    15781      +41     
- Misses        3990     4211     +221     
- Partials      1077     1080       +3     
Flag Coverage Δ
all-tests 74.89% <17.36%> (-0.76%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/http/handlerfuncs.go 70.86% <0.00%> (-13.21%) ⬇️
cli/schema_migration_set.go 14.39% <14.39%> (ø)
cli/schema_migration_get.go 17.74% <17.74%> (ø)
api/http/router.go 100.00% <100.00%> (ø)
cli/cli.go 74.31% <100.00%> (+1.50%) ⬆️
cli/schema_migration.go 100.00% <100.00%> (ø)

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update effd4eb...22a7ea0. Read the comment docs.

@AndrewSisley AndrewSisley changed the title feat: Add migration set verb to CLI, and http API feat: Add schema migration get and set cmds to CLI, and http API Jul 18, 2023
@AndrewSisley AndrewSisley force-pushed the 1648-lens-set-cli branch 2 times, most recently from 442e02e to 00dc5a6 Compare July 18, 2023 13:00
@AndrewSisley AndrewSisley changed the title feat: Add schema migration get and set cmds to CLI, and http API feat: Add schema migration get and set cmds to CLI Jul 18, 2023
Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with a todo and a couple suggestions.

Tests can be added later, possibly within this PR if I have time but do not count on it.

In the interest of getting this merged before your time off tomorrow and the code freeze, I can agree to this but I just want to put it out there that we should in the majority of cases avoid this delaying of test writing. We agreed to stay on top of test coverage and that means having tests that cover what is added/changed in the PRs.

func MakeSchemaMigrationSetCommand(cfg *config.Config) *cobra.Command {
var lensFile string
var cmd = &cobra.Command{
Use: "set [src] [dst] [cfg]",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought (out-of-scope): We have a few different representations of args and flags. We should standardize the format #1651.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that ticket, it is a very good thing to do I think

defradb client schema migration set bae123 bae456 '{"lenses": [...'

Example: set from file:
defradb client schema migration set bae123 bae456 -f schema_migration.graphql
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I find it odd that the file extension is graphql. Isn't it a json file that represents the config?

Copy link
Contributor Author

@AndrewSisley AndrewSisley Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is odd. I'll change it to something slightly less odd.

  • change example file extension

cli/schema_migration_set.go Show resolved Hide resolved
cli/schema_migration_get.go Show resolved Hide resolved
return errors.Wrap("join paths failed", err)
}

res, err := http.Post(endpoint.String(), "json", strings.NewReader(string(migrationCfgJson)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: json isn't a valid content type. It should be application/json

Copy link
Contributor Author

@AndrewSisley AndrewSisley Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁 my bad lol

  • application/json

@AndrewSisley
Copy link
Contributor Author

I just want to put it out there that we should in the majority of cases avoid this delaying of test writing

100% agree with you

@AndrewSisley AndrewSisley merged commit 49bced3 into sourcenetwork:develop Jul 18, 2023
@AndrewSisley AndrewSisley deleted the 1648-lens-set-cli branch July 18, 2023 14:10
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
## Relevant issue(s)

Resolves sourcenetwork#1648

## Description

Adds `schema migration set` and `schema migration get` commands to the
CLI, and the http API.

Command/endpoint assumes the db server has access to the file path(s)
provided in the lens cfg..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/api Related to the external API component area/cli Related to the CLI binary area/schema Related to the schema system feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add migration system to CLI (and http)
2 participants