Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-introspection should not remove relations when foreign keys are not allowed #9147

Closed
pimeys opened this issue Sep 7, 2021 · 0 comments · Fixed by prisma/prisma-engines#2221

Comments

@pimeys
Copy link
Contributor

pimeys commented Sep 7, 2021

Introspection engine should not overwrite relation fields in the PSL, if the datasource has the referential integrity set to happen in Prisma.

Currently if we have the following data model:

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

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
}

model A {
  id  Int @id @default(autoincrement())
  bId Int
  b B @relation(fields: [bId], references: [id], onDelete: Restrict, onUpdate: SetNull)
}

model B {
  id Int @id @default(autoincrement())
  as A[]
}

When we migrate this to the database, the foreign key constraints are not written due to the settings in the datasource. When we again run db pull, the introspection engine will overwrite the data model, removing all relations due to not finding any foreign keys:

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

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
}

model A {
  id  Int @id @default(autoincrement())
  bId Int
}

model B {
  id Int @id @default(autoincrement())
}

We should make the re-introspection to not do anything to the relations, if we do not use foreign keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants