question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Introspection] No @default attribute when introspecting on PostgreSQL from Prisma V1

See original GitHub issue

Bug description

I am trying to migrate from Prisma1 to Prisma2. When I introspect the database, default values are not generated in the output schema.

How to reproduce

Here is my database schema:

CREATE TABLE "default$default"."User"
(
    id character varying(25) COLLATE pg_catalog."default" NOT NULL,
    isActive boolean NOT NULL,
    CONSTRAINT "User_pkey" PRIMARY KEY (id)
)

Database schema has no DEFAULT constraint defined for the column isActive so it seems logical that there is no @default attribute in the datamodel after the introspection (Prisma2).

However, it works fine with the Prisma1 introspection where the generated datamodel has the @default attributes.

The introspected schema:

model User {
  id                        String                      @id
  isActive                  Boolean
}

Expected behavior

I was expecting the following Prisma2 schema:

model User {
  id                        String                      @id                      @default(cuid())
  isActive                  Boolean                      @default(true)
}

Same behaviour with the @createdAt and @updatedAt directives.

Where are defined (or stored) these constraints in the underlying database when using Prisma1 ?

Environment & setup

  • OS: Ubuntu 18.04 LTS
  • Database: PostgreSQL in Docker (image: postgres:10.3)
  • Prisma1 version: prisma@1.34.10
  • Prisma2 version: prisma2@2.0.0-preview024
  • Node.js version: 8.16.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, May 25, 2020

FYI: This will be tackled via https://github.com/prisma/prisma/issues/2499

1reaction
janpiocommented, Mar 29, 2020

So it is introspecting the datamodel based on the datamodel… interesting 😉 Thanks for the clarification. We understand the need for a better solution than just P2 introspection and will work on something before GA of P2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schema Incompatibilities | PostgreSQL - Prisma
There's no DEFAULT constraint added to the database column. Because this constraint is not reflected in the database itself, the Prisma 2.x and...
Read more >
Introspection (PostgreSQL) - Prisma 1
IMPORTANT: When introspecting a PostgreSQL database, you're actually introspecting a schema and not a database according to the illustrated model.
Read more >
What is introspection? (Reference) - Prisma
Introspection has one main function: Populate your Prisma schema with a data model that reflects the current database schema. Introspect your database with ......
Read more >
Upgrading the Prisma layer to Prisma 2 | PostgreSQL
Use the Prisma Upgrade CLI to resolve the schema incompatibilities in the new Prisma 2 data model. Install and generate Prisma Client.
Read more >
Introspection | node-postgres - Prisma
Introspect your database with Prisma. For the purpose of this guide, we'll use a demo SQL schema with three tables: CREATE TABLE "public"."User"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found