diff --git a/generator/src/functions/tableDescriptionWriters/writeTableSchemas.ts b/generator/src/functions/tableDescriptionWriters/writeTableSchemas.ts index 9bd25d58f7..48c47877c3 100644 --- a/generator/src/functions/tableDescriptionWriters/writeTableSchemas.ts +++ b/generator/src/functions/tableDescriptionWriters/writeTableSchemas.ts @@ -107,7 +107,6 @@ function pgType(field: ExtendedDMMFField, modelName: string): string { const prismaType = field.type const attributes = field.attributes switch (prismaType) { - // BigInt, Boolean, Bytes, DateTime, Decimal, Float, Int, JSON, String case 'String': return stringToPg(attributes) case 'Int': @@ -125,12 +124,22 @@ function pgType(field: ExtendedDMMFField, modelName: string): string { case 'Float': return 'FLOAT8' case 'Json': - return 'JSON' + return jsonToPg(attributes) default: return 'UNRECOGNIZED PRISMA TYPE' } } +function jsonToPg(attributes: Array) { + const pgTypeAttribute = attributes.find((a) => a.type.startsWith('@db')) + if (pgTypeAttribute && pgTypeAttribute.type === '@db.Json') { + return 'JSON' + } else { + // default mapping for Prisma's `Json` type is PG's JSONB + return 'JSONB' + } +} + function dateTimeToPg( attributes: Array, field: string,