[Introspection] Wrong relation type when introspecting on PostgreSQL from Prisma V1
See original GitHub issueBug description
I’m trying to migrate from Prisma1 to Prisma2 (brownfield) but I encounter a problem with introspection.
A relation between two of my types (User
and Payout
) is “translated” into a 1:m
relation instead of 1:1
.
How to reproduce
Here is my SQL (Postgresql) schema created by Prisma V1 the first time where I deployed the service :
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)
)
CREATE TABLE "default$default"."Payout"
(
id character varying(25) COLLATE pg_catalog."default" NOT NULL,
user character varying(25) COLLATE pg_catalog."default",
CONSTRAINT "Payout_pkey" PRIMARY KEY (id),
CONSTRAINT "Payout_user_fkey" FOREIGN KEY ("user") REFERENCES "default$default"."User" (id) MATCH SIMPLE
)
I kept the most important columns only.
As you can see, there is no UNIQUE
attribute on User.id
or Payout.id
columns).
My datamodel (Prisma1) :
type User {
id: ID! @id
isActive: Boolean! @default(value: true)
payout: Payout @relation(name: "UserOnPayout", onDelete: CASCADE)
}
type Payout {
id: ID! @id
user: User @relation(link: INLINE, name: "UserOnPayout", onDelete: SET_NULL)
}
If I Introspect the database with the prisma introspect
command (Prisma1), everything works fine but when I introspect with Prisma2 (npx prisma2 introspect
with the latest alpha or preview024 version), I have the following datamodel with a 1:m
relation:
model User {
id String @id
isActive Boolean
payout Payout[]
}
model Payout {
id String @id
user User?
}
What am I doing wrong ?
Expected behavior
I was expecting the following Prisma2 schema:
model User {
id String @id
isActive Boolean
payout Payout?
}
model Payout {
id String @id
user User?
}
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:
- Created 3 years ago
- Comments:5 (4 by maintainers)
FYI: This will be tackled via a later iteration of https://github.com/prisma/prisma/issues/1937
Should be solved via https://www.prisma.io/docs/guides/upgrade-guides/upgrade-from-prisma-1