Skip to content

Conversation

james-geiger
Copy link
Contributor

Description

This PR implements the Enum datatype in the OGM.

Pull request type

Please delete options that are not relevant.

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring with functional or API changes
  • Refactoring without functional or API changes
  • Build or packaging related changes
  • Documentation content changes
  • Other (please describe):

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

######################################

Reviewer checklist (the reviewer checks this part)

  • Core feature implementation
  • Tests
  • Code documentation
  • Documentation on gqlalchemy/docs

######################################

@katarinasupe
Copy link
Contributor

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.

@james-geiger
Copy link
Contributor Author

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:

  • Implement default for supported databases which do not have an enum type (neo4j).
  • Implement enum creation on node/relationship instantiation where it needs to exist.
  • Implement alter statements or issue warning when enum in OGM does not match the values in database
  • Documentation
  • Tests

@katarinasupe
Copy link
Contributor

This will then be a part of the next release and I'll take a closer look later 😄
Btw. can you check my last comment on #341 so we can merge it?

@katarinasupe katarinasupe added this to the GQLAlchemy 1.8.0 milestone Mar 25, 2025
@katarinasupe katarinasupe requested a review from antejavor April 17, 2025 11:35
Copy link
Contributor

@katarinasupe katarinasupe left a 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).

Comment on lines +184 to +189
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)
Copy link
Contributor

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"]}

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants