Convert PostgreSQL schemas to Prisma
See genuine Prisma schema output generated from a 13-table PostgreSQL-shaped schema, including relations, composite keys and explicit caveats.
- target
- Prisma schema
- access
- Pro export
- source specimen
- 2 of 13 tables · seed/schema.json
Trellis exports a schema drafted on its canvas using PostgreSQL types. This page does not claim to parse a PostgreSQL dump or a live database.
01 / models
Models with their relation fields attached
The excerpt keeps two complete models from the 13-table export. Back-relations remain in the model where the full generator placed them.
model article {
/// One row is one piece of writing. The current body lives here; every earlier body is a revision row.
id String @db.Uuid @default(uuid()) @id
author_id String @db.Uuid
title String
slug String
body String @default("")
labels String[] @default([])
search_vector Unsupported("tsvector")?
published_at DateTime?
created_at DateTime @default(now())
updated_at DateTime @default(now())
author account @relation("article_author_id_to_account", fields: [author_id], references: [id])
article_revision_article_id article_revision[] @relation("article_revision_article_id_to_article")
article_embedding_article_id article_embedding? @relation("article_embedding_article_id_to_article")
comment_article_id comment[] @relation("comment_article_id_to_article")
// not expressible in Prisma: primary key (id)
@@unique([author_id, title])
@@unique([slug], where: raw("published_at is not null"))
// not expressible in Prisma: index using gin (search_vector)
@@index([labels], type: Gin)
// not expressible in Prisma without raw SQL: index using gin (title gin_trgm_ops)
// not expressible in Prisma without raw SQL: index (author_id, published_at desc)
// not expressible in Prisma: check (published_at is null or the author's account must still be active)
}
model article_revision {
/// One row is one earlier version of an article's body. The article and the revision number together identify the row, so there is no surrogate key.
article_id String @db.Uuid
revision Int
title String
body String
edited_by String? @db.Uuid
edited_at DateTime @default(now())
article article @relation("article_revision_article_id_to_article", fields: [article_id], references: [id])
edited_by_account account? @relation("article_revision_edited_by_to_account", fields: [edited_by], references: [id])
@@id([article_id, revision])
// not expressible in Prisma: primary key (article_id, revision)
// not expressible in Prisma without raw SQL: index (edited_by, edited_at desc)
}- Columns
- Scalar fields retain nullability and safe defaults.
- Relations
- Foreign keys become named relation fields with references.
- Keys
- Composite identities become model-level declarations.
02 / review
The generated file marks what needs a hand
Prisma cannot express every PostgreSQL type or raw index construct. Trellis leaves those decisions in the output instead of silently deleting them.
The full 13-table export writes its caveats into the generated file. These examples are copied from it:
// Unsupported types are left as Unsupported("...") so the file still parses.// not expressible in Prisma: index using gist (path)// not expressible in Prisma: check (entity_type in ('account', 'article', 'article_revision', 'comment', 'subscription', 'invoice', 'tag'))// not expressible in Prisma without raw SQL: index (occurred_at desc)
source / generated Prisma schema output