0

I have designed a relational data model and it's graph data model. I want to know whether I had done it in a correct way and whether my graph data model is correct or not. If there is anything wrong or ambiguous with my model please leave a comment.

As you can see in the graph data model there are 4 labels:

  1. Company
  2. User
  3. Skill
  4. Project

And you can see that each node with it's label has it's properties and the join tables are transformed into relationships between the nodes. I want to know what should I do with the "Primary keys" like userID or SkillID.

Relational data model:

enter image description here

Graph Data model:

enter image description here

5
  • What is a "User"? Commented Mar 27, 2018 at 15:20
  • A user is a person . I think I chose a wrong Name for the entity . By user I mean a person . I think "Person" is a better replacement Commented Mar 27, 2018 at 15:22
  • Hi @PTTT. Your first question will probably produce opinion-based answers. This kind of question is discouraged at StackOverflow. However your data model looks ok at a first glance. But remember that a good practice when modeling a graph database is make the model according your query requirements. So think in the queries you want to ask to your database before start modeling. I answered your question about primary keys, please, take a look. Commented Mar 27, 2018 at 16:28
  • @PTTT also, take a look here and here. Commented Mar 27, 2018 at 16:31
  • thank you . The truth is that I'm having a presentation about graph databases . i want to show the audience a relational data model and run some sql queries and then show them the graph data model and the same cql queries . actually I did my best to make my Relational model unique .I did not want to show them examples which are already exists . So i tried to make an example for myself and then I used some Join Tables so that I can have sql queries with joins and then compare the equivalent cql with the sql query. Do you think that this is a good example to show the advantage of graphdatabase? Commented Mar 27, 2018 at 16:40

1 Answer 1

2

About the primary keys question:

In fact Neo4j nodes and relationships have an internal unique ID that can be accessed using the id() function:

match (d)-[r]-()
return id(d) as nodeId, id(r) as relId

However your application should not rely on these ids because they are reused by Neo4j when a node or relationships is deleted. The Neo4j documentation says:

Neo4j reuses its internal ids when nodes and relationships are deleted. This means that applications using, and relying on internal Neo4j ids, are brittle or at risk of making mistakes. It is therefore recommended to rather use application-generated ids.

More here.

So, if you really want a primary key, I think you have two main options:

  1. Manage the primary keys at application level. That is: create and assign unique ids in the application code that access your Neo4j database.

  2. Use GraphAware UUID plugin. GraphAware UUID is a simple library that transparently assigns a UUID to newly created nodes and relationships in the graph and makes sure nobody can (accidentally or intentionally) change or delete them.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you . what if we keep the primary key?? I mean what if I keep the skill_id for example?? is that wrong?
@PTTT you are welcome! No, it's not wrong. In case you use GraphAware UUID plugin you can customize the property name to store UUIDs using the config parameter com.graphaware.module.UIDM.uuidProperty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.