Supabase Project
Create a Project from supabase.com
Prisma Setup
Add prisma dependency to the project
bun add prisma@latest -DNow initialize prisma in the project with the following command
bunx prisma initAdd Database url of supabase to prisma
- Copy the Database URL and Direct URL and add it to
.envfile created by prisma - Add the
Providerofdata sourcetoschema.prismafile - There are some preview features we use, like
multiSchemaandpostgresqlExtensionsAdd these to client block
Introspect Database with the following command
bunx prisma db pullThis will update schema.prisma with all the tables as models
Baseline the database
Create a directory to add migrations
mkdir -p prisma/migrations/0_initGenerate the migration diff
bunx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/0_init/migration.sqlWarning
Modify the generated schema with the following github comment https://github.com/prisma/prisma/issues/17734#issuecomment-1452011006 as there is a bug in prisma
Finally Mark the migrations as applied with the following command
bunx prisma migrate resolve --applied 0_initUpdate uuid extension by removing schema key
extensions = [uuid_ossp(map: "uuid-ossp")]