Skip to content

Commit

Permalink
fix(*): dmmf: add uniqueIndexes on Model & default, hasDefaultValue o…
Browse files Browse the repository at this point in the history
…n Field
  • Loading branch information
Jolg42 committed Jun 5, 2020
1 parent abda193 commit 500f06b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/packages/client/src/runtime/dmmf-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ export namespace DMMF {
enums: Enum[]
}

export interface uniqueIndex {
name: string
fields: string[]
}

export interface Model {
name: string
isEmbedded: boolean
dbName: string | null
fields: Field[]
uniqueFields: string[][]
uniqueIndexes: uniqueIndex[]
documentation?: string
[key: string]: any // safe net for additional new props
idFields: string[]
[key: string]: any // safe net for additional new props
}

export type FieldKind = 'scalar' | 'object' | 'enum'
Expand All @@ -40,17 +46,17 @@ export namespace DMMF {
type: string
dbNames: string[] | null
isGenerated: boolean
hasDefaultValue: boolean
default?: FieldDefault | string | boolean | number
relationToFields?: any[]
relationOnDelete?: string
relationName?: string
documentation?: string
default?: FieldDefault | string | boolean
[key: string]: any // safe net for additional new props
}

export interface FieldDefault {
name: string
returnType: string
args: any[]
}

Expand Down
5 changes: 4 additions & 1 deletion src/packages/client/src/runtime/transformDmmf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ function getFieldType(field: DMMF.Field): string {
if (field.default === 'uuid') {
return 'UUID'
}
} else if (typeof field.default === 'boolean') {
} else if (
typeof field.default === 'boolean' ||
typeof field.default === 'number'
) {
return field.type
} else if (field.default.name === 'uuid') {
return 'UUID'
Expand Down
13 changes: 13 additions & 0 deletions src/packages/generator-helper/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ export namespace DMMF {
enums: DatamodelEnum[]
}

export interface uniqueIndex {
name: string
fields: string[]
}

export interface Model {
name: string
isEmbedded: boolean
dbName: string | null
fields: Field[]
uniqueFields: string[][]
uniqueIndexes: uniqueIndex[]
idFields: string[]
}

Expand All @@ -50,11 +56,18 @@ export namespace DMMF {
type: string
dbNames: string[] | null
isGenerated: boolean
hasDefaultValue: boolean
default?: FieldDefault | string | boolean | number
relationToFields?: any[]
relationOnDelete?: string
relationName?: string
}

export interface FieldDefault {
name: string
args: any[]
}

export interface Schema {
rootQueryType?: string
rootMutationType?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test('sortModels', () => {
name: 'Car',
fields: [],
uniqueFields: [],
uniqueIndexes: [],
isEmbedded: false,
dbName: null,
idFields: [],
Expand All @@ -15,6 +16,7 @@ test('sortModels', () => {
name: 'Bike',
fields: [],
uniqueFields: [],
uniqueIndexes: [],
isEmbedded: false,
dbName: null,
idFields: [],
Expand All @@ -23,13 +25,15 @@ test('sortModels', () => {
name: 'Post',
fields: [],
uniqueFields: [],
uniqueIndexes: [],
isEmbedded: false,
dbName: null,
idFields: [],
},
{
name: 'User',
uniqueFields: [],
uniqueIndexes: [],
fields: [],
isEmbedded: false,
dbName: null,
Expand All @@ -46,6 +50,7 @@ test('sortModels', () => {
"isEmbedded": false,
"name": "User",
"uniqueFields": Array [],
"uniqueIndexes": Array [],
},
Object {
"dbName": null,
Expand All @@ -54,6 +59,7 @@ test('sortModels', () => {
"isEmbedded": false,
"name": "Post",
"uniqueFields": Array [],
"uniqueIndexes": Array [],
},
Object {
"dbName": null,
Expand All @@ -62,6 +68,7 @@ test('sortModels', () => {
"isEmbedded": false,
"name": "Bike",
"uniqueFields": Array [],
"uniqueIndexes": Array [],
},
Object {
"dbName": null,
Expand All @@ -70,6 +77,7 @@ test('sortModels', () => {
"isEmbedded": false,
"name": "Car",
"uniqueFields": Array [],
"uniqueIndexes": Array [],
},
]
`)
Expand Down

0 comments on commit 500f06b

Please sign in to comment.