Skip to content

Coming from Prisma

Prisma gives you tables, migrations and a typed client from one schema file. Supatype does the same from TypeScript types, then goes on to access rules, an API, an admin UI, auth and storage, which with Prisma you write yourself.

What maps to what

In PrismaIn Supatype
model in schema.prismaA Model<> type in schema/index.ts. See Models
prisma migrate devsupatype dev: each save is applied to the local database
prisma migrate deploysupatype push, which shows the plan and asks before anything that can lose data
prisma migrate diffsupatype diff: the plan, without applying it
prisma db pullsupatype pull: a draft schema from a live database
prisma generateTypes are written by supatype dev and supatype push. supatype generate writes them on their own
Prisma Client@supatype/client. See Client
Prisma StudioSupatype Studio, a CMS built from the schema. See Studio roles
prisma db seedsupatype seed. See Seeding

Field by field

PrismaSupatype
String @id @default(uuid())id: UUID. The database fills it in
String?Optional<string>. Every other field is NOT NULL
@uniqueUnique<T>
@default(value)Default<T, value>
enum Status { draft published }"draft" | "published"
JsonJSON<T>, typed as T in the client
@relation(fields: [authorId], references: [id])RelatedTo<Author>, which adds the column author_id
The list side, posts Post[]HasMany<Post>. It adds no column
An implicit many-to-manyManyToMany<Tag>, one junction table for the pair
@@index, @@mapindexes and tableName in the model’s second argument

The full list is in Field types and Relations.

Before and after

Prisma

prisma/schema.prisma
enum Status {
draft
published
}
model Author {
id String @id @default(uuid())
email String @unique
name String
posts Post[]
}
model Post {
id String @id @default(uuid())
title String
status Status @default(draft)
author Author @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId String
}
before: Prisma Client
const posts = await prisma.post.findMany({
where: { status: "published" },
select: { id: true, title: true, author: { select: { name: true } } },
})

Supatype

schema/index.ts
import type {
Model, UUID, Email, Unique, Default, SupatypeAuthUserId,
RelatedTo, HasMany, Public, Owner, Any, Eq, Literal,
} from "@supatype/types"
export type Author = Model<{
id: SupatypeAuthUserId
email: Unique<Email>
name: string
posts: HasMany<Post>
}, {
access: { read: Public; create: Owner<"id">; update: Owner<"id">; delete: Owner<"id"> }
}>
export type Post = Model<{
id: UUID
title: string
status: Default<"draft" | "published", "draft">
author: RelatedTo<Author, { required: true; onDelete: "cascade" }>
}, {
access: {
read: Any<[Eq<"status", Literal<"published">>, Owner<"author_id">]>
create: Owner<"author_id">
update: Owner<"author_id">
delete: Owner<"author_id">
}
}>
after: @supatype/client
const { data: posts, error } = await supatype
.from("post")
.select("id, title, author(name)")
.eq("status", "published")

The author’s id is a sign-in user’s id, so each author row belongs to a user. The access blocks are the part Prisma has no place for: they become Postgres row level security, so the same query returns only what the caller may see, whether it runs on your server or in the browser.

What Supatype adds

  • Access rules in the database. Each model’s rules become row level security, and field rules mask single columns. They hold for REST, GraphQL, realtime and the client alike. See Access rules.
  • An API you do not write. Every model with access rules is reachable over REST and GraphQL. A model with no access at all is not.
  • A client that runs in the browser. It holds the anon key and the user’s session, not a database connection.
  • Studio. A form for each model built from its fields, drafts and version history, a media library, and roles for the people who edit content. See Studio roles.
  • Auth, storage, realtime and functions in the same project. Buckets are declared in the schema next to the models. See Auth, Storage, Realtime and Functions.

Bringing an existing database

supatype pull drafts a schema from a live database. Prisma’s _prisma_migrations table is skipped, along with any table whose name starts with _.

Terminal window
$ supatype pull --connection "postgres://..." --out schema/index.ts
$ supatype diff

Prisma’s defaults and Supatype’s differ, so expect to edit the draft:

  • Prisma names a table after the model, such as "Post". Supatype derives the table name from the model name in snake case, so Post means post. Add tableName: "Post" to keep the existing table.
  • A field’s name is its column’s name. A relation’s column is the field name plus _id, and there is no option to name it otherwise, so a Prisma authorId column does not line up with an author relation. Keep it as a plain field, or rename the column.
  • Every drafted model has Public for all four rules. Replace them with the rules you mean before you push.
  • An id column of type uuid is drafted as SupatypeAuthUserId. Change it to UUID on every table whose id is not a user’s id.
  • Prisma fills @default(uuid()) in the client, and stores a String id as text unless you used @db.Uuid. Such an id is drafted as a string, not a UUID.

The first push refuses tables that exist and that Supatype did not create. In a terminal it offers to adopt them: it asks Adopt them now?, shows what adoption will take, and asks again before changing anything. --yes does not answer those questions. Without a terminal, run supatype adopt and then push again. See What a push refuses.

What does not carry over

  • Other databases. Supatype runs on Postgres 17 only. MySQL, SQLite, SQL Server and MongoDB projects need moving to Postgres first.
  • Your migrations folder. Supatype does not read prisma/migrations. It compares the schema with the database and plans the change itself.
  • Nested writes and transactions. The client writes one table per call and has no transaction API. Put a write that must touch several tables at once in a function.
  • Raw queries. There is no $queryRaw. Studio has a SQL runner for one-off queries.
  • Client extensions and middleware. Logic that ran around every query belongs in access rules, model hooks or functions.