_creationTime schema setup
Hi,
I am trying to add a updateAt to my schema. Similar to how the default _creationTime is. I attached a screenshot of what I am referring to.
What does the schema look like for this? I can't find it in the docs. I see when I hover over it a timestamp shows as well.
35 Replies
_creationTime
is a numeric timestamp with fractional milliseconds, it's designed to be unique across documents within a given table from my understanding. Short answer is the schema type is number, and the dashboard just recognizes the numeric timestamp and formats it as a date.
I've implemented updatedAt
across my tables and personally just use string datetimes, really comes down to preference.Awesome, makes sense, thank you!
is creationTime utc time? And milliseconds since when? is it a UNIX timestamp?
I also noticed that the _creationTime is a little off by 10mins for me.
I have a field also named "last_updated" which i use Date.now() when executing the mutation.
When i check the table, the document is inserted in realtime but the "last_updated" and "_creationTime" are different by 10mins.
Don't know how that is possible.
@erquhart
it's a unix timestamp (milliseconds since 1970-01-01 utc)
i don't think there are guarantees on clock skew between server and client. 10 minutes does seem like a lot, so we can look into measuring and bounding server clock skew. If you want the timestamps to match client timestamps, i recommend passing the time in as an argument instead of using Date.now()
when you say passing it in as an arguement. I dont understand.
Do you mean i can use the server time in he document?
If that is possible, then it would be easier to keep everything in sync
I mean your mutation can take in an argument which is the current time, calculated on the client by
Date.now()
, and stored in a document's field
Like this
hmmm
But what is the difference between passing it as a value and initiating it in the function?
when i initiate it as a function currently, it passes the correct time stamp in the database
but the _creationTime field which is auto created when the document is first inserted is the one behind by 10mins
The difference is that
Date.now()
on the client uses the client machine's clock, while on the server it uses the convex server's clock. And these might be different
There is no "correct timestamp". Every computer has its own clock, and the best you can get is pass timestamps between computers. Clock skew is a tricky problemhmmm...
@DaReal sounds like you're observing a big difference between
_creationTime
and Date.now()
in a mutation.
Can you share your code? Are you sure that you don't have another update changing the updatedAt
field's value?I experience the same. I create a value and the timestamp is 1 to 10 minutes old
Thanks for the report, we'll have a look. Which instance and mutation name is it?
GitHub
chat-io/src/app/(internal-sites)/chats/[chatId]/page.tsx at chats Β·...
Contribute to FleetAdmiralJakob/chat-io development by creating an account on GitHub.
@FleetAdmiralJakob π π π in your case the difference is between the client clock (which determines the "how many minutes ago" logic), and the
_creationTime
on the server. We're looking at this as well, but as Lee pointed out you can sync them by passing the +Date.now()
value from client to the server (although I wouldn't really advise doing this, since you can trust the client clock even less than the server clock - your computer's clock could be off by minutes or set to any time you like).ok, hope you find the problem. I don't want to implement a crazy sync solution. If the _creationTime is accurate enough it would be really cool
(just in case) Are you sure your computer has time set accurately?
yes, compared it with the time on my phone and synced it
/t/chatio/chat-io/youthful-caribou-100 <- my dev instance
@Michal Srb Were you able to find the problem?
As you said I do not want to pass the time from the client to the server because of many reasons
I have checked and i believe the mutation is okay. It seems to be something from the server.
Even with a simple mutation following the books mutation guide from the docs, the time is till a bit off by 5-10 mins
Are you looking at Date objects to calculate the difference? If you're just looking at the numbers, could you be thinking the are seconds instead if milliseconds? 1-10 minutes in seconds divided by equals conceivable latency numbers (60-600ms). Convex timestamps are in milliseconds.
I think Im doing it correctly
One way to measure clock skew is to have a mutation that just does
return Date.now()
and compare that to your browser's Date.now()
. The question seems to be whether the clock difference is between different Convex servers or Convex & the client, right?as said here my client is synced so it has the correct time
the issue perists between different devices so the problem has to be in convex somewhere
I will try this one out, wait a sec
Cool, thanks for verifying. And are you still seeing the clock differences consistently, or was it an isolated issue? I've never seen it personally, and not sure if it was some machine issue that has since resolved, or something we can reproduce to isolate the issue
I happened to test out Scroll the other day (as in ~1 week ago or so?) and saw this skew there as well, of ~9 mins
Tested it just now and see a difference of ~3 mins
(test yourself at https://scroll.ink, see the "n time ago" label on a new note)
We're looking into this, and have isolated the issue a bit. Stay tuned
Thank you. Since 3 people now have had the issue seems like there has to be systematically something wrong in thr creation process of the timestamps
Apologies for this causing issues. The problem was us using a slightly stale creation time on idle backends where there hadn't been any intervening writes to advance time forward. The time still advanced monotonically but the drift from wallclock time certainly could cause confusion. We just rolled out a fix so that you should always see the latest timestamp.
Cool will check the timestamps soon
looks fine now, will update if I see any other problems but for now this should be fixed. thank you so much for the nice support
Thanks for consistent support Convex Team.