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

fix: Allow adding of new schema to database #635

Merged
merged 2 commits into from
Jul 14, 2022

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented Jul 14, 2022

Relevant issue(s)

Resolves #489

Description

Allows calling db.AddSchema multiple times - this was broken at some point whilst implementing aggregates - the generator code would try and add existing types a second time which would error. This checks checks whether the aggregate input types already exist before trying to add them.

@AndrewSisley AndrewSisley added bug Something isn't working area/schema Related to the schema system action/no-benchmark Skips the action that runs the benchmark. labels Jul 14, 2022
@AndrewSisley AndrewSisley added this to the DefraDB v0.3 milestone Jul 14, 2022
@AndrewSisley AndrewSisley requested a review from a team July 14, 2022 15:02
@AndrewSisley AndrewSisley self-assigned this Jul 14, 2022
@codecov
Copy link

codecov bot commented Jul 14, 2022

Codecov Report

Merging #635 (ae20a41) into develop (7e96e2a) will increase coverage by 0.09%.
The diff coverage is 88.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #635      +/-   ##
===========================================
+ Coverage    57.00%   57.09%   +0.09%     
===========================================
  Files          122      122              
  Lines        14636    14638       +2     
===========================================
+ Hits          8343     8358      +15     
+ Misses        5578     5566      -12     
+ Partials       715      714       -1     
Impacted Files Coverage Δ
query/graphql/schema/generate.go 85.23% <87.50%> (+1.47%) ⬆️
query/graphql/schema/types/types.go 100.00% <100.00%> (ø)

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.

The code looks good! I'm just not sure how the test you added relate to the fix. Does it relate because users and books already exists and if you were defining them once again in the test case it would fail?

@@ -1266,6 +1261,16 @@ func (g *Generator) genTypeQueryableFieldList(
return field
}

func (g *Generator) appendIfNotExists(obj gql.Type) error {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion(non-blocking): I read this as some element named Not that exists. Perhaps a rename to appendIfNewSchema or appendIfNew ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely not a fan of appendIfNewSchema, as that is incorrect/overly-specific. I'm pretty sure I have seen IfNotExists in a number of code bases before, I don't think it is particularly uncommon. appendIfNew might be seen as slightly misleading in another direction, suggesting that new instances (of the same name) will still be appended, but THB I don't think appendIfNotExists vs appendIfNew matters at all.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ifNotExist is quite fine in my opinion. I would remove the last s though.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Jul 14, 2022

Choose a reason for hiding this comment

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

😆 appendIfNotExists I think fits with what I have seen before, but running it over in my head I can't quite figure out whether with the trailing s is more or less correct than the current - I think without an s is logically more correct, but it feels slightly wrong lol @orpheuslummis ? 🤣

Copy link
Collaborator

Choose a reason for hiding this comment

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

Go uses os.ErrNotExist 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keeping it with the s as I see this as a singular 3rd person verb lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keeping it with the s as I see this as a singular 3rd person verb lol

feels like there is another grammar rule at play here though RE negatives - it exists vs it does not exist - maybe in English the negative is forced to use the infinitive? Feels weird that I dont know this stuff lol

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like to follow what the language uses: https://pkg.go.dev/os#IsExist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's no fun though :) And it feels like that lib is breaking English, assuming exist is not an adjective, then IsExist should really be DoesExist (not great programming-wise as Is is a nice prefix for bools), or IsExisting?

Wish I knew this stuff better lol

Copy link
Collaborator

Choose a reason for hiding this comment

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

The function I linked to is returning a bool so IsExist makes sense according to your logic. They also use it for errors: https://pkg.go.dev/os#pkg-variables

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

Just a non-blocking suggestion, otherwise looks good to me.

LGTM

@AndrewSisley
Copy link
Contributor Author

The code looks good! I'm just not sure how the test you added relate to the fix. Does it relate because users and books already exists and if you were defining them once again in the test case it would fail?

Test failed before the fix went in - each item in that testCase slice corresponds to a db.AddSchema call - users would be created fine, the books would fail on the second call.

@fredcarle
Copy link
Collaborator

Test failed before the fix went in - each item in that testCase slice corresponds to a db.AddSchema call - users would be created fine, the books would fail on the second call.

Ok thanks for clarifying :)

Should be using the schema type map, is cleaner, and correct if adding a new schema to existing set.
@AndrewSisley AndrewSisley force-pushed the sisley/fix/I480-second-schema branch from 79ac586 to ae20a41 Compare July 14, 2022 19:37
@AndrewSisley AndrewSisley merged commit ebe32e3 into develop Jul 14, 2022
@AndrewSisley AndrewSisley deleted the sisley/fix/I480-second-schema branch July 14, 2022 19:50
@AndrewSisley AndrewSisley linked an issue Jul 14, 2022 that may be closed by this pull request
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
* Allow adding of new schema

* Remove extra variable

Should be using the schema type map, is cleaner, and correct if adding a new schema to existing set.
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/schema Related to the schema system bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure when adding a second schema set
3 participants