February 01, 2022

Prisma support for CockroachDB is now in Preview

Today we are excited to expand the range of Prisma compatible databases with Preview support for CockroachDB. Try it out and let us know what you think!

Prisma support for CockroachDB is now in Preview


CockroachDB support in Prisma is now in Preview

Today we are excited to introduce Preview support for CockroachDB as part of the 3.9.0 release of Prisma! 🎉

CockroachDB is a distributed SQL database that shines in its ability to scale efficiently while maintaining developer agility and reducing operational overhead.

CockroachDB support in Prisma is the product of collaboration with the Cockroach Labs team. It has passed rigorous testing internally and is now ready for broader testing by the community.

However, as a Preview feature, it is not production-ready and comes with some limitations. To learn more about the current limitations, see the limitations section.

Today, we're inviting the CockroachDB community to try it out and give us feedback, so we can bring CockroachDB support to General Availability.

Your feedback and suggestions will help us shape the future of CockroachDB support in Prisma. 🙌

Prisma - making databases easy

Prisma is a next-generation open-source ORM for Node.js and TypeScript. It helps you be more productive and confident when developing database-driven applications.

It can be used as an alternative to traditional ORMs and SQL query builders to interact with your database.

It consists of the following tools:

Note: With this Preview release, Prisma Migrate is not supported yet.

To learn more about Prisma, check out the documentation.

Why Prisma & CockroachDB

Ensuring confidence and developer productivity with databases is at the core of our mission at Prisma. But as an ORM, Prisma is agnostic to how you operate your relational database; this is where CockroachDB comes in.

While Prisma helps you reap significant productivity gains throughout the design, review, and implementation phases of database-driven applications, operating and scaling a relational database demands specialized knowledge and attention.

Traditional relational databases like PostgreSQL were designed and built long before the cloud-native era without native horizontal scaling features.

CockroachDB, in contrast, was designed from the offset as a distributed database with automated scaling, failover, and repair at its core. It can be self-hosted on your infrastructure or used as a hosted service with dedicated and serverless offerings.

This is in line with the general shift of the industry toward managed infrastructure as a means to reduce costs; and our vision to unlock the potential of serverless architectures, which we presented at the Prisma Serverless Data Conference.

Since CockroachDB maintains a high degree of PostgreSQL compatibility, some Prisma users were already using the Prisma PostgreSQL connector with CockroachDB. However, we learned that there are subtle differences between CockroachDB and PostgreSQL and decided to invest in a dedicated CockroachDB connector for full support.

With today's release, you can use introspection to populate your Prisma schema and Prisma Client to interact with the database in a type-safe manner.

We have started the design work on schema migrations with Prisma Migrate and CockroachDB so that we can bring CockroachDB support to General Availability.

To learn more about CockroachDB Serverless and how it fits together with Prisma, check out Aydrian Howard's talk from the Prisma Serverless conference:

Getting started

This release allows you to use Prisma Client with an existing CockroachDB database, using the introspection flow.

To enable the Preview feature, add cockroachdb to previewFeatures in your Prisma schema.

With Prima's introspection workflow, you begin by introspecting (prisma db pull) an existing CockroachDB database that populates the Prisma schema with models mirroring the state of your database schema.

Then you can generate Prisma Client (prisma generate) and interact with your database in a type-safe manner with Node.js or TypeScript.

Note that CockroachDB Serverless comes with a generous free-tier (5GB Storage, 250M Request Units/month) so you can experiment and test in a matter of a few clicks.

Get started with Prisma and CockroachDB

You can also dig into our ready-to-run example in the prisma-examples repo which includes instructions on how to start a CockroachDB server, introspect, and query with Prisma Client:

Ready-to-run example


Prisma Migrate is not supported yet with CockroachDB; if you're starting without an existing database, you will need to define the schema with SQL. To follow progress on this, subscribe to the related issue.

We are working on adding support for CockroachDB in Prisma Migrate, which will be available soon; and fully supported when the CockroachDB connector is Generally Available.

CockroachDB supports the PostgreSQL wire protocol and the majority of PostgreSQL syntax. However, there are some nuanced differences with regards to types. To learn more about the Prisma specific differences, check out the Prisma CockroachDB connector docs:

Read the Prisma CockroachDB connector docs

Try Prisma with your existing CockroachDB database and share your feedback

We built this for you and are eager to hear your feedback!

🐜 Found something you'd love to see improved? Please file an issue so our engineering team can look into it.

Get started with Prisma and CockroachDB

Don’t miss the next post!

Sign up for the Prisma Newsletter