Moe Green
03/07/2022, 5:58 PMmodel Article {
id Int @id @default(autoincrement())
slug String @db.VarChar(255)
title String @db.VarChar(255)
description String? @db.VarChar(255)
body String? @db.VarChar(255)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
tagList String[]
favoritesCount Int @default(0)
@@map("articles")
}
... and then make migration with result:
CREATE TABLE "articles" (
"id" SERIAL NOT NULL,
"slug" VARCHAR(255) NOT NULL,
"title" VARCHAR(255) NOT NULL,
"description" VARCHAR(255),
"body" VARCHAR(255),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"tagList" TEXT[],
"favoritesCount" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "articles_pkey" PRIMARY KEY ("id")
);
... but I have a question about this field - "updatedAt" TIMESTAMP(3) NOT NULL,
because I expected that this field should be like this - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
why did it happen? I do not understand something?Ian Ray
03/07/2022, 6:26 PM@default(now()), @default(uuid())
don't produce a table with db-level DEFAULT CURRENT_TIMESTAMP
. Instead, it does it's datetimes, default autoincrementations, etc in-memory. (If memory serves)
If you need this feature, you'll need to use @db(dbgenerated("CURRENT_TIMESTAMP"))
or @db(dbgenerated("gen_random_uuid()"))
.Ian Ray
03/07/2022, 6:31 PMjanpio
@updatedAt
currently is a Prisma level feature that is not reflected in the database.Moe Green
03/10/2022, 6:05 PM