-
Notifications
You must be signed in to change notification settings - Fork 36
Implement Enum datatype in OGM #342
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
base: main
Are you sure you want to change the base?
Conversation
Hi @james-geiger, thank you for the contribution! 🙏 Can you add some tests as well? It would be good to test saving a node with enum property and checking whether it's properly stored. Also, test all procedures you implemented to create, drop and ensure enums. |
There are still quite a few things that need to be done, but wanted to provide a working proof of concept for feedback and alignment. Because we cannot currently drop enums in Memgraph, I'm thinking this needs to be an error or warning at this point. TODO:
|
This will then be a part of the next release and I'll take a closer look later 😄 |
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.
Hi @james-geiger!
I took a look at your PR and left some comments regarding the procedures you created. I still need to try it out to see if all works as expected. It would be create if you could create tests for all the new methods you added and checking how Enum acts as a property on a node and relationship (similar to what you added to the docs).
def sync_enum(self, existing: MemgraphEnum, new: MemgraphEnum) -> None: | ||
"""Ensures that database enum matches input enum.""" | ||
for value in new.members: | ||
if value not in existing.members: | ||
query = f"ALTER ENUM {existing.name} ADD VALUE {value};" | ||
self.execute(query) |
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.
To modify an existing enum by adding a new value use ALTER:
ALTER ENUM Status ADD VALUE Excellent;
To update an existing value in an enum do the following:
ALTER ENUM Status UPDATE VALUE Bad TO Poor;
Maybe instead of having sync_enum
procedure, it would make sense to have two procedures matching the above queries?
Full example:
Create enum:
CREATE ENUM Status VALUES { Good, Okay, Bad };
SHOW ENUMS;
Result:
{"Enum Name":"Status","Enum Values":["Good","Okay","Bad"]}
Add new value to existing enum:
ALTER ENUM Status ADD VALUE Excellent;
SHOW ENUMS;
Result
{"Enum Name":"Status","Enum Values":["Good","Okay","Bad","Excellent"]}
Update existing value in an existing enum:
ALTER ENUM Status UPDATE VALUE Bad TO Poor;
SHOW ENUMS;
Result:
{"Enum Name":"Status","Enum Values":["Good","Okay","Poor","Excellent"]}
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 also listed some errors that can occur when running ALTER
query - memgraph/memgraph#2968.
Description
This PR implements the Enum datatype in the OGM.
Pull request type
Please delete options that are not relevant.
Checklist:
######################################
Reviewer checklist (the reviewer checks this part)
######################################