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 relationMode="prisma" #16130

Closed
aaron-henselin opened this issue Nov 4, 2022 · 1 comment
Closed
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. topic: re-introspection topic: referentialIntegrity/relationMode
Milestone

Comments

@aaron-henselin
Copy link

Bug description

Expectation based on #2221 is that the usage of relationMode="prisma" should prevent the removal of manually added relationships. This is necessary for Heroku Connect setups, where "sfid"-based relationships are not traditional FK.

However, manually added relationships appear to be automatically removed on prisma 4.5.0.

How to reproduce

(1) Using this or similar schema before introspection:

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

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
  relationMode = "prisma"
}


model Event {
  id                               Int       @id @default(autoincrement())
  sfid                             String?   @unique(map: "hcu_idx_event__c_sfid") @db.VarChar(18)
  Track  Track[]
  @@map("event__c")
}

model Track {
  
  parent         Event	       @relation(fields: [parentId], references: [sfid])
  parentId       String        @map("event__c") @db.VarChar(18)
  sfid           String?       @unique(map: "hcu_idx_track__c_sfid") @db.VarChar(18)
  id             Int           @id @default(autoincrement())
  @@index([parentId], map: "hc_idx_track__c_event__c")
  @@map("track__c")
}

(2) run db pull
(3) schema has had its relations removed:

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

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
  relationMode = "prisma"
}


model Event {
  id                               Int       @id @default(autoincrement())
  sfid                             String?   @unique(map: "hcu_idx_event__c_sfid") @db.VarChar(18)

  @@map("event__c")
}

model Track {
  
  parentId       String        @map("event__c") @db.VarChar(18)
  sfid           String?       @unique(map: "hcu_idx_track__c_sfid") @db.VarChar(18)
  id             Int           @id @default(autoincrement())

  @@index([parentId], map: "hc_idx_track__c_event__c")
  @@map("track__c")
}

Expected behavior

Manually added @relations should never be removed when using relationMode="prisma"

Prisma information

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

	datasource db {
	  provider = "postgresql"
	  url      = env("DATABASE_URL")
	  relationMode = "prisma"
	}


	model Event {
	  id                               Int       @id @default(autoincrement())
	  sfid                             String?   @unique(map: "hcu_idx_event__c_sfid") @db.VarChar(18)
	  Track  Track[]
	  @@map("event__c")
	}

	model Track {
	  
	  parent         Event	       @relation(fields: [parentId], references: [sfid])
	  parentId       String        @map("event__c") @db.VarChar(18)
	  sfid           String?       @unique(map: "hcu_idx_track__c_sfid") @db.VarChar(18)
	  id             Int           @id @default(autoincrement())
	  @@index([parentId], map: "hc_idx_track__c_event__c")
	  @@map("track__c")
	}

Environment & setup

  • OS: Windows
  • Database: PostgreSQL / Heroku Connect
  • Node.js version: v16.15.0

Prisma Version

4.5.0
@aaron-henselin aaron-henselin added the kind/bug A reported bug. label Nov 4, 2022
@SevInf SevInf added team/schema Issue for team Schema. topic: referentialIntegrity/relationMode bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Nov 4, 2022
@Jolg42 Jolg42 added bug/2-confirmed Bug has been reproduced and confirmed. topic: re-introspection and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Nov 4, 2022
@Jolg42 Jolg42 added this to the 4.6.0 milestone Nov 4, 2022
@Jolg42
Copy link
Member

Jolg42 commented Nov 4, 2022

Can reproduce, and it's already fixed via #11022

Note: fix will be available in next 4.6.0 release planned on Tuesday (November 8th).

@Jolg42 Jolg42 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. topic: re-introspection topic: referentialIntegrity/relationMode
Projects
None yet
Development

No branches or pull requests

3 participants