Race condition when reading and writing data
The way it works is that my system will call convex to update the cache when the data in my other backend changes. The frontend is subscribed to convex as the source of truth.
The issue I am facing is that
existsForToken returns false and multiple repeated rows are inserted into the table, with the same tokenHash and userId. my intent is for the tokenHash + userId to for a unique pair.I've seen some other threads where
.withIndex(<index name>).unique() was suggested, but I don't really see how .unique() is helpful, because this errors out on read (aka the data is already in an inconsistent state).