Skip to content

mismatch between the DateTime types of Prisma and the ones of Postgres (timestamptz unsupported) #552

@infoverload

Description

@infoverload

I experienced an issue with the date format after introspecting a Postgres database.

The SQL migration statements of the initial DB schema:

CREATE TABLE IF NOT EXISTS "users" ("id"   SERIAL , "username" VARCHAR(255) NOT NULL UNIQUE, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));

CREATE TABLE IF NOT EXISTS "tasks" ("id"   SERIAL , "title" VARCHAR(255), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, "userId" INTEGER REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE, PRIMARY KEY ("id"));

The resulting Prisma data model after introspection:

model Task {
  id        Int      @id
  createdAt DateTime @default(now())
  title     String?
  updatedAt DateTime @updatedAt
  userId    User?

  @@map("tasks")
}

model User {
  id        Int      @id
  createdAt DateTime @default(now())
  tasks     Task[]
  updatedAt DateTime @updatedAt
  username  String   @unique

  @@map("users")
}

The Photon API call that caused the issue:

photon.users.findMany()

The error message:

(node:21575) UnhandledPromiseRejectionWarning: Error: 
Invalid `const users = await photon.users.findMany()` invocation in /Users/daisyt/Documents/Code/migration_sequelize_photon/src/index.ts:11:38

   7 
   8 const photon = new Photon()
   9 
  10 app.get('/users', async (req,[object Object], res) => {
→ 11     const users = await photon.users.findMany(

Error querying the database: db error: FATAL: role "user" does not exist date=2019-09-13T15:45:14.949Z
    at PhotonFetcher.<anonymous> (/Users/daisyt/Documents/Code/migration_sequelize_photon/node_modules/@generated/photon/index.js:46:27)
    at Generator.throw (<anonymous>)
    at rejected (/Users/daisyt/Documents/Code/migration_sequelize_photon/node_modules/@generated/photon/index.js:5:65)
(node:21575) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21575) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions