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

Remove opinionated casing for back relation field names #1851

Closed
divyenduz opened this issue Feb 21, 2020 · 0 comments · Fixed by prisma/prisma-engines#599
Closed

Remove opinionated casing for back relation field names #1851

divyenduz opened this issue Feb 21, 2020 · 0 comments · Fixed by prisma/prisma-engines#599
Assignees
Labels
kind/improvement An improvement to existing feature and code. topic: dx topic: introspection
Milestone

Comments

@divyenduz
Copy link
Contributor

divyenduz commented Feb 21, 2020

Upper case database tables create back field names with weird casing that is not consistent with model naming in the schema:

model ATOMS {
  ATOM_TYPE                   Int?
  CHARGE                      Float?
  ELEMENT                     String?
  ID                          Int         @default(0) @id
  DRUG_ID                     DRUGS?
  bONDS_ATOMSToBONDS_ATOM1_ID BONDS[]     @relation("ATOMSToBONDS_ATOM1_ID")
  bONDS_ATOMSToBONDS_ATOM2_ID BONDS[]     @relation("ATOMSToBONDS_ATOM2_ID")
  rING_ATOM                   RING_ATOM[]

  @@index([DRUG_ID], name: "ATOMS_DRUG_ID")
}

model BONDS {
  BOND_TYPE Int?
  ID        Int    @default(0) @id
  ATOM1_ID  ATOMS? @relation("ATOMSToBONDS_ATOM1_ID")
  ATOM2_ID  ATOMS? @relation("ATOMSToBONDS_ATOM2_ID")
  DRUG_ID   DRUGS?

  @@index([ATOM1_ID], name: "BONDS_ATOM1_ID")
  @@index([ATOM2_ID], name: "BONDS_ATOM2_ID")
  @@index([DRUG_ID], name: "BONDS_DRUG_ID")
}

...

model RING_ATOM {
  ID      Int    @default(0) @id
  ATOM_ID ATOMS?
  RING_ID RINGS?

  @@index([ATOM_ID], name: "RING_ATOM_ATOM_ID")
  @@index([RING_ID], name: "RING_ATOM_RING_ID")
}

(example via https://github.com/prisma/introspection-engine-output/blob/03469b95bbdb28a599eabc20437691df4fd81ba9/mysql_127/Bench6.log)

rING_ATOM and bONDS_ATOMSToBONDS_ATOM1_ID are unexpectedly formatted here.

(SQL:

CREATE TABLE `ATOMS` (
  `ID` int(11) NOT NULL DEFAULT '0',
  `DRUG_ID` int(11) DEFAULT NULL,
  `ELEMENT` varchar(2) DEFAULT NULL,
  `ATOM_TYPE` int(11) DEFAULT NULL,
  `CHARGE` float DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `ATOMS_DRUG_ID` (`DRUG_ID`),
  CONSTRAINT `ATOMS_IBFK_1` FOREIGN KEY (`DRUG_ID`) REFERENCES `DRUGS` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;

CREATE TABLE `BONDS` (
  `ID` int(11) NOT NULL DEFAULT '0',
  `DRUG_ID` int(11) DEFAULT NULL,
  `ATOM1_ID` int(11) DEFAULT NULL,
  `ATOM2_ID` int(11) DEFAULT NULL,
  `BOND_TYPE` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `BONDS_DRUG_ID` (`DRUG_ID`),
  KEY `BONDS_ATOM1_ID` (`ATOM1_ID`),
  KEY `BONDS_ATOM2_ID` (`ATOM2_ID`),
  CONSTRAINT `BONDS_IBFK_1` FOREIGN KEY (`DRUG_ID`) REFERENCES `DRUGS` (`ID`),
  CONSTRAINT `BONDS_IBFK_2` FOREIGN KEY (`ATOM1_ID`) REFERENCES `ATOMS` (`ID`),
  CONSTRAINT `BONDS_IBFK_3` FOREIGN KEY (`ATOM2_ID`) REFERENCES `ATOMS` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;

...

CREATE TABLE `RING_ATOM` (
  `ID` int(11) NOT NULL DEFAULT '0',
  `RING_ID` int(11) DEFAULT NULL,
  `ATOM_ID` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `RING_ATOM_RING_ID` (`RING_ID`),
  KEY `RING_ATOM_ATOM_ID` (`ATOM_ID`),
  CONSTRAINT `RING_ATOM_IBFK_1` FOREIGN KEY (`RING_ID`) REFERENCES `RINGS` (`ID`),
  CONSTRAINT `RING_ATOM_IBFK_2` FOREIGN KEY (`ATOM_ID`) REFERENCES `ATOMS` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;

)

@janpio janpio assigned janpio and sorenbs and unassigned janpio Feb 21, 2020
@janpio janpio changed the title Casing for Prisma client models Casing for Prisma Client model and field names Feb 28, 2020
@janpio janpio assigned timsuchanek, Jolg42 and do4gr and unassigned sorenbs Mar 16, 2020
@janpio janpio transferred this issue from prisma/prisma-client-js Mar 16, 2020
@janpio janpio added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: introspection labels Mar 16, 2020
@janpio janpio added this to the Preview 25 milestone Mar 16, 2020
@janpio janpio changed the title Casing for Prisma Client model and field names Casing for back relation field names Mar 16, 2020
@janpio janpio changed the title Casing for back relation field names Casing for relation field names Mar 16, 2020
@janpio janpio changed the title Casing for relation field names Casing for back relation field names Mar 16, 2020
@janpio janpio added kind/improvement An improvement to existing feature and code. and removed bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. labels Mar 16, 2020
@janpio janpio changed the title Casing for back relation field names Remove opinionated casing for back relation field names Mar 16, 2020
@schickling schickling assigned schickling and unassigned do4gr Mar 17, 2020
@janpio janpio assigned janpio and do4gr and unassigned schickling Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. topic: dx topic: introspection
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants