1
votes

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

1
What is a "User"?N. Paul
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 replacementPTTT
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.Bruno Peres
@PTTT also, take a look here and here.Bruno Peres
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?PTTT

1 Answers

2
votes

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.