Skip to content

Commit

Permalink
feat!: support prisma 2.30 (#114)
Browse files Browse the repository at this point in the history
@prisma/client versions _before_ 2.29.x are no longer supported
  • Loading branch information
jasonkuhrt authored Aug 26, 2021
1 parent 9c7e552 commit b7c7927
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 202 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"devDependencies": {
"@homer0/prettier-plugin-jsdoc": "^4.0.1",
"@prisma-labs/prettier-config": "0.1.0",
"@prisma/client": "2.27.0",
"@prisma/sdk": "^2.27.0",
"@prisma/client": "2.30.0",
"@prisma/sdk": "2.30.0",
"@types/debug": "^4.1.7",
"@types/expand-tilde": "^2.0.0",
"@types/jest": "26.0.24",
Expand All @@ -72,7 +72,7 @@
"nexus": "^1.1.0",
"nodemon": "^2.0.12",
"prettier": "2.3.2",
"prisma": "2.27.0",
"prisma": "2.30.0",
"strip-ansi": "^6",
"ts-jest": "27.0.4",
"ts-node": "^10.1.0",
Expand All @@ -82,14 +82,14 @@
},
"prettier": "@prisma-labs/prettier-config",
"peerDependencies": {
"@prisma/client": "2.17.x || 2.18.x || 2.19.x || 2.20.x || 2.21.x || 2.22.x || 2.23.x || 2.24.x || 2.25.x || 2.26.x || 2.27.x",
"@prisma/client": "2.29.x || 2.30.x",
"nexus": "^1.0.0"
},
"resolutions": {
"comment-parser": "1.1.5"
},
"dependencies": {
"@prisma/generator-helper": "^2.27.0",
"@prisma/generator-helper": "^2.29.x",
"debug": "^4.3.2",
"decimal.js": "^10.3.1",
"dindist": "^1.0.2",
Expand Down
25 changes: 13 additions & 12 deletions src/generator/helpers/constraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@ import { DMMF } from '@prisma/client/runtime'
import { RecordUnknown } from '../../helpers/utils'

/**
* Find the unique identifiers necessary to indentify a field
* Find the unique identifiers necessary to indentify a field.
*
* Unique fields for a model can be one of (in this order):
* 1. One (and only one) field with an @id annotation
* 2. Multiple fields with @@id clause
* 3. One (and only one) field with a @unique annotation (if there are multiple, use the first one)
* 4. Multiple fields with a @@unique clause
* @remarks Unique fields for a model can be one of (in this order):
*
* 1. Exacrly one field with an `@id` annotation.
* 2. Multiple fields with `@@id` clause.
* 3. Exactly one field with a `@unique` annotation (if multiple, use first).
* 4. Multiple fields with a `@@unique` clause.
*/
export function resolveUniqueIdentifiers(model: DMMF.Model): string[] {
// Try finding 1.
// Try finding 1
const singleIdField = model.fields.find((f) => f.isId)

if (singleIdField) {
return [singleIdField.name]
}

// Try finding 2.
if (model.idFields && model.idFields.length > 0) {
return model.idFields
// Try finding 2
if (model.primaryKey && model.primaryKey.fields.length > 0) {
return model.primaryKey.fields
}

// Try finding 3.
// Try finding 3
const singleUniqueField = model.fields.find((f) => f.isUnique)

if (singleUniqueField) {
return [singleUniqueField.name]
}

// Try finding 4.
// Try finding 4
if (model.uniqueFields && model.uniqueFields.length > 0) {
return model.uniqueFields[0] as string[] // I don't know why typescript want a cast here
}
Expand Down
Loading

0 comments on commit b7c7927

Please sign in to comment.