prisma / prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://www.prisma.io
Apache License 2.0
38.8k stars 1.52k forks source link

updatedAt before createdAt #18767

Open kewp opened 1 year ago

kewp commented 1 year ago

Bug description

I just started playing with prisma. In prisma studio I made a new record with the Example table. It is showing updatedAt as having happened before createdAt. Clearly this is incorrect. See screenshot below.

Screenshot 2023-04-16 at 11 08 43

How to reproduce

I'm busy going through the T3 tutorial https://www.youtube.com/watch?v=YkOSUVzOAA4&t=412s

  1. Create T3 app using create-t3-app
  2. Change DATABASE_URL to PlanetScale url
  3. Change schema.prisma to value below
  4. Run npx prisma studio
  5. Add new record to Example table
  6. Note createdAt and updatedAt (see screenshot above)

Expected behavior

No response

Prisma information

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
  relationMode = "prisma"
}

generator client {
  provider = "prisma-client-js"
}

model Example {
    id        String   @id @default(cuid())
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}
import { PrismaClient } from "@prisma/client";

import { env } from "~/env.mjs";

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };

export const prisma =
  globalForPrisma.prisma ||
  new PrismaClient({
    log:
      env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
  });

if (env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;

Environment & setup

Prisma Version

SevInf commented 7 months ago

I can confirm it on 5.9.0-dev with the provided schema, but only when using Studio to create the records - prisma.example.create({ data: {} }) on the other hand returns identical timestamps.

SevInf commented 7 months ago

Internal not: possible cause is here