# How to set up a version history for the changing data

**URL:** <https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated\
**Created:** [January 2, 2023, 12:17pm UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227 "2023-01-02T12:17:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashika](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shashika](https://community.neo4j.com/u/Shashika)\
**Post date:** [January 2, 2023, 12:17pm UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/1 "2023-01-02T12:17:23Z")

</div>

I have the data source that keep updating every 2 weeks and i want to have a version history which keeps track of the changes for every two weeks. How can i do that on neo4j?

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [January 2, 2023, 9:40pm UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/2 "2023-01-02T21:40:50Z")

</div>

There are many ways to do that. It depends on your data model. Need more information to provide any answer.

---

<div class="post-metadata">

**Author:** ![Shashika](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shashika](https://community.neo4j.com/u/Shashika)\
**Post date:** [January 3, 2023, 8:00am UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/3 "2023-01-03T08:00:19Z")

</div>

Thanks alot for your reply

I have data coming from different sources like lightcast(EMSI), solaris, and katie so i have connected all these data in one graph. And for every two weeks the lightcast(EMSI) changes or is updated. In lightcast there is an API that is gives us the version changes [https://api.lightcast.io/apis/skills#versions-version-changes](https://api.lightcast.io/apis/skills#versions-version-changes) . so i want to know how to integrate this API to the neo4j dashboard so that i can check the version. What type of information do you need on my data model?

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [January 3, 2023, 9:45am UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/4 "2023-01-03T09:45:48Z")

</div>

Thanks for the information. When you import data from lightcast, you should have created some nodes and relationships in Neo4j database. And nodes may have some properties. You can add a property named 'version' and store the version number like version: "7.0".

Q: Are you keeping the data from all versions or updating the nodes with the latest version data?

If answer is yes, then adding a property to store the version number is good enough.

If answer is no, then you are creating new nodes with every import. If possible run

CALL db.schema.visualization() and post the screenshot.

---

<div class="post-metadata">

**Author:** ![Shashika](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shashika](https://community.neo4j.com/u/Shashika)\
**Post date:** [January 3, 2023, 11:50am UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/5 "2023-01-03T11:50:21Z")

</div>

Thanks for your reply.  
Yes the plan is to be able to have a version history so we can always see the how the data has changed over time.  
How do i add the property to store the version number?

![Shashika_0-1672746612859.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/4/3/4333d0781da0493034c953efa7b663af52037988.png "Shashika\_0-1672746612859.png")

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [January 4, 2023, 6:49pm UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/6 "2023-01-04T18:49:59Z")

</div>

(Version {number: "7.0"})-[:PRODUCT]-\>(Product)-[:HAS\_RELATED]-(b): This is not a Cypher query. I meant to show the sequence of nodes with 'Version' node (if implemented) as a root node. Please run this query and post the screenshot of the resulted graph.  
Query: MATCH (n) RETURN n limit 20.

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [January 4, 2023, 8:10am UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/7 "2023-01-04T08:10:28Z")

</div>

Thanks for sharing the schema diagram. I am guessing that 'Product' node is a kind of root node. If you want to keep the data for all versions, then my recommendation is to add a 'Version' node just like we do for date wise storage. (Version {number: "7.0"})-[:PRODUCT]-\>(Product)-[:HAS\_RELATED]-(b).... See if this fits with your model.

---

<div class="post-metadata">

**Author:** ![Shashika](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shashika](https://community.neo4j.com/u/Shashika)\
**Post date:** [January 4, 2023, 10:39am UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/8 "2023-01-04T10:39:49Z")

</div>

Thanks for being patient with me. I am new to neo4j, I am taking some time to understand the model. I dont seem to have understood this model. Can you suggest me a starting point.  
I tried the query you sent.

![Shashika_0-1672828779001.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/6/5/65f80ea9a5b57889db4148fb9ef8b08ea345588c.png "Shashika\_0-1672828779001.png")

---

<div class="post-metadata">

**Author:** ![Shashika](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shashika](https://community.neo4j.com/u/Shashika)\
**Post date:** [January 5, 2023, 8:29am UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/9 "2023-01-05T08:29:19Z")

</div>

Thanks alot for being very patient with me and helping me.  
Please find the screenshot below

![Shashika_0-1672907350278.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/8/c/8cc1bfcf9e8fee71db8a62e5383c93a231234059.png "Shashika\_0-1672907350278.png")

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [January 5, 2023, 10:23pm UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/10 "2023-01-05T22:23:43Z")

</div>

Checking the screenshot, node 'BC'(green) is the starting node. When a new feed comes in, are using 'MERGE' or 'CREATE'. Example MERGE (a:BC {prop1: "V1"}) or CREATE (a:BC {prop1: "V1"}) Let me know. Thanks

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [January 5, 2023, 11:42pm UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/11 "2023-01-05T23:42:08Z")

</div>

```auto
Try this. The property values I added are demonstration purpose only.

Say version number = 7.0

merge (a:Version {version: "7.0"})
merge (b:BC {prop1: "P1"})
merge (c:BA {prop1: "A1"})
merge (d:LoB {prop1: "L1"})

merge (a)-[:HAS_BROADER]->(b)
merge (b)-[:HAS_BROADER]->(c)
merge (c)-[:HAS_BROADER]->(d)
return a, b, c,d

For version number = 7.1
merge (a:Version {version: "7.1"})
merge (b:BC {prop1: "P2"})
merge (c:BA {prop1: "A2"})
merge (d:LoB {prop1: "L2"})

merge (a)-[:HAS_BROADER]->(b)
merge (b)-[:HAS_BROADER]->(c)
merge (c)-[:HAS_BROADER]->(d)

```

Result:  
 ![Screen Shot 2023-01-05 at 3.28.59 PM.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/3/1/31afb048681dd499e5fbd7ab215acb11ce028168.png "Screen Shot 2023-01-05 at 3.28.59 PM.png")

---

<div class="post-metadata">

**Author:** ![Shashika](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shashika](https://community.neo4j.com/u/Shashika)\
**Post date:** [January 6, 2023, 9:53am UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/12 "2023-01-06T09:53:15Z")

</div>

I just checked Merge is used.  
Example:

LOAD CSV WITH HEADERS FROM 'file:///BCM\_ProductReq\_LM.csv' AS row

with row

MERGE (lob:LoB {name: row.LoB})

```
ON CREATE

    SET lob.LOB\_ID = row.\`LoB ID\`,

        lob.type\_id = row.\`LoB Type ID\`

```

MERGE (ba:BA {name: row.`Business Area`})

```
ON CREATE

    SET ba.BA\_ID = row.\`Business Area ID\`

```

MERGE (bc:BC {name: row.`Business Capability`})

```
ON CREATE

    SET bc.BC\_ID = row.\`Business Capability ID\`

```

MERGE (sc:SC {name: row.`Solution Capability`})

```
ON CREATE

    SET sc.SC\_ID = row.\`Solution Capability ID\`,

        sc.industry = row.\`Industry / Segment\`,

        sc.product = row.\`Solution Capability Required Product Name\`,

        sc.PPMS\_ID = row.\`Solution Capability Required Product ID\`

ON MATCH

    SET sc.industry = row.\`Industry / Segment\`,

        sc.product = row.\`Solution Capability Required Product Name\`,

        sc.PPMS\_ID = row.\`Solution Capability Required Product ID\`

```

MERGE (p:Product {name: row.`Solution Capability Required Product Name`})

```
ON CREATE

    SET p.PPMS\_ID = row.\`Solution Capability Required Product ID\`

```

MERGE (p)-[rp:HAS\_RELATED]-\>(sc)

MERGE (sc)-[rsc:HAS\_BROADER]-\>(bc)

MERGE (bc)-[rbc:HAS\_BROADER]-\>(ba)

MERGE (ba)-[rba:HAS\_BROADER]-\>(lob)

---

<div class="post-metadata">

**Author:** ![Shashika](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shashika](https://community.neo4j.com/u/Shashika)\
**Post date:** [January 6, 2023, 10:05am UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/13 "2023-01-06T10:05:35Z")

</div>

Yes i got this result. How to call an API?  
Thanks alot for helping

![Shashika_0-1672999451482.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/a/7/a717e27d4a1f09a80eeab3dab4cdf3327f3f4543.png "Shashika\_0-1672999451482.png")

---

<div class="post-metadata">

**Author:** ![Peter\_Lian](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@Peter\_Lian](https://community.neo4j.com/u/Peter_Lian)\
**Post date:** [January 6, 2023, 6:31am UTC](https://community.neo4j.com/t/how-to-set-up-a-version-history-for-the-changing-data/58227/14 "2023-01-06T06:31:27Z")

</div>

Just to mention, although the "merge" can avoid duplicate node or edge, but it take sever times than "create" if your data is large. Try to avoid merge (or change your data schema to avoid duplicate) if your data is large.
