I have a database with users (u:User {id: 1})
, user statuses (us:UserStatus {status: 'pending'})
, and the relationships between them (u)-[hs:HAS_STATUS {from: 1541030400, to: 4102444800}]->(us)
.
Where user statuses can be "pending"
, "active"
or "suspended"
.
And 2100-01-01
is some date in the future meaning the user still has this status.
I'm trying to run a query that updates the status of the user by creating a new relationship with the new status and archives the old relationship by setting the to
property to the current date.
This is what I've tried:
MERGE (u:User { id: 1 })
WITH u
MATCH (u)-[hs1:HAS_STATUS]->(us1:UserStatus)
WHERE us1.status <> 'active' AND hs1.to > 1544400000
SET hs1.to = 1544400000
MERGE (us2:UserStatus {status: 'active'})
MERGE (u)-[hs2:HAS_STATUS {from: 1544400000, to: 4102444800}]->(us2)
If the user already has a status that satisfies the WHERE
clause then it is archived and the new status relationship is created. However if the user doesn't already have a status the SET
clause is skipped (as intended) however the two MERGE
lines are skipped also. How can I ensure that they are executed regardless of the merge?
Edit: Original query had some typos.