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

@unique is added during Re-Introspection #11026

Closed
janpio opened this issue Jan 8, 2022 · 4 comments · Fixed by prisma/prisma-engines#2944
Closed

@unique is added during Re-Introspection #11026

janpio opened this issue Jan 8, 2022 · 4 comments · Fixed by prisma/prisma-engines#2944
Assignees
Milestone

Comments

@janpio
Copy link
Member

janpio commented Jan 8, 2022

Original migrated schema:

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

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

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

model Foo {
  id     Int @id
  bar    Bar @relation(fields: [bar_id], references: [id])
  bar_id Int
}

model Bar {
  id  Int  @id
  foo Foo?
}

Re-Introspection then adds a @unique:

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

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

model Foo {
  id     Int @id
  bar    Bar @relation(fields: [bar_id], references: [id])
  bar_id Int @unique
}

model Bar {
  id  Int  @id
  foo Foo?
}

(Most probably an expected feature, but still a bit surprising)

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. topic: re-introspection team/schema Issue for team Schema. labels Jan 8, 2022
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jan 10, 2022
@pantharshit00
Copy link
Contributor

I can confirm this. Looks like prisma-fmt also adds this @unique when you reformat the schema to ensure a 1:1 relation.

@janpio
Copy link
Member Author

janpio commented Jan 10, 2022

Ah ok, then it could be a side effect of that behavior.

@do4gr
Copy link
Member

do4gr commented Jan 11, 2022

This is expected. We create a unique constraint in the database to enforce that the relation is 1:1 but currently do not require the @unique to be present in the datamodel. During reformatting or re-introspection we make it explicit though. We want to require the @unique to be explicit, but since this is a major breaking change it's a topic for Prisma 4.

@do4gr do4gr added team/psl-wg topic: breaking change Prisma4 and removed bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. labels Jan 11, 2022
@pantharshit00 pantharshit00 added the kind/improvement An improvement to existing feature and code. label Jan 11, 2022
@janpio janpio removed the Prisma4 label Jan 11, 2022
@janpio
Copy link
Member Author

janpio commented Apr 13, 2022

Issue for that work: #10503

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.

5 participants