hi, guys! I created such model: ```model Article ...
# orm-help
m
hi, guys! I created such model:
Copy code
model 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:
Copy code
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?
👀 1
i
Prisma produces database table schema that are primarily designed to work with the prisma client. In part, that means things like
@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()"))
.
I don't know that I necessarily agree with the way they've designed this, but I am also not privy to all the facts. It almost implies that they expect Prisma's users (us) to need to switch database providers (ie Postgres to MySql) more than zero times, which just seems untrue in any real world context. That, or they've found that their db engine can handle these values faster. Which could be true. In any case this is the solution we've got today. But I'll gladly take it, Prisma is awesome.
j
Welcome to decision of the past still being there in the present 😄 Ian described it correctly why that is the case:
@updatedAt
currently is a Prisma level feature that is not reflected in the database.
💯 1
m
thanks guys for the detailed answer; now i have no questions
👍 1