New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createdAt @default(now())
and updatedAt @updatedAt
get different times on row creation
#12572
Comments
We are aware of this limitation, and will one day clean this up. We do not know exactly how yet though (move both to Prisma Client? move both to the database?) and it is unfortunately also not the highest on our priority list. (It is also a bit more complex than just these two functions, as the "defaults can be on database and/or Prisma level" problem is wider) |
@janpio would it work if you make Prisma Migrate set the column's default to |
Something like that, yes. But that would be a breaking change and actually unwanted for some users who do not want to have this functionality represented in the database - so this is something more complex we will need to look deep into, and then figure out which solutions we want to support going forward and if we e.g. need a configuration switch etc. |
@janpio I wonder if simply supporting |
It would be ugly, but the same level of ugly as the different timestamp being created on row creation. Of course it would not fix the problem for when you later update the row that the timestamp is still calculated by different code. The problem with the suggestion is that it would a) mean introducing defaults for this type of column (which I think is blocked right now, but most importantly b) would require us to disable some code (the |
@janpio not really hehe. I think it's more of a technical hole you guys are in, which is normal and happens to all. But from a consumer perspective, it doesn't make sense to me 😄 |
This is also tangentially relevant to determine if an |
It may be useful to edit #3432 (comment) which suggests checking equality as a means of determining whether a record was created or updated in an upsert. |
createdAt @default(now())
and updatedAt @updatedAt
get different times on row creation
Internal: As a sidenote, this should not be super hard to fix since currently the QE writes both the values to the db, it just initializes them at different times. |
Can reproduce in our internal dev version When using a local database (docker on my computer) the values are the same
When using a remote database, it doesn't match anymore (946Z vs 947Z)
|
Note generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
} the SQL from migrate dev is -- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
); |
I think the simplest solution would be that |
This will be fixed in next release. The relevant PR is prisma/prisma-engines#3200 |
Bug description
I have standard table like this:
I always assumed that after a
prisma.user.create({})
, thecreatedAt
andupdatedAt
would be the same dates, matching to the millisecond. I'm seeing that's not the case andupdatedAt
many times has a few extra millisecond(s).How to reproduce
Expected behavior
On creation,
createdAt
andupdatedAt
are always identical.I suppose if
@updatedAt
kind of columns would also default toCURRENT_TIMESTAMP
like thedefault(now())
do, the problem would be resolvedPrisma information
The schema above is enough
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: