nikolasburk
DROP DATABASE
and CREATE DATABASE
, due to insufficient privileges. Prisma Migrate so far relied on these statements to ensure the database is empty when it needs to be reset.
Database resets in the context of Prisma Migrate now gracefully fall back to dropping constraints, indexes and tables, if there are insufficient privileges to reset the database using DROP DATABASE
.
🚪 Improvements and changes for prisma db push
• prisma db push
now handles unexecutable migrations better, offering a path forward by resetting the database. For example, adding a new required field without a default value when there are rows in the table is considered an unexecutable migration; in such situations you will be prompted to first reset the database.
• Changes to command options:
• The flag —-force
has been renamed to --accept-data-loss
to be more explicit - this is required for certain changes that involve losing data, e.g. dropping a table or dropping a column if there are rows.
• We've added a new flag —-force-reset
which first resets the database and then updates the schema - this can useful to start from scratch and as a way to deal with unexecutable migrations (see above).
🌱 prisma db seed
now supports custom schema locations
You can now point the prisma db seed
command to a custom schema location using either of two approaches:
• Use the --schema
option when running the command
• Define a default schema location in your package.json
which will be picked up every time you run the command
🦟 Lots of bug fixes in Prisma Client, Prisma Migrate & Prisma Studio
Check out the release notes to learn about all the bugs and other issues that were fixed in this release!
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we'd very much appreciate if you would star the repo 🌟 And if you're excited about the features in this week's release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the "What's new in Prisma" livestream
As usual, my colleague @ryan and I will discuss the latest release and other news from the Prisma ecosystem in a livestream on on Thursday at 5pm Berlin | 8am San Francisco. This week, we'll be joined by our VP of Product @Hervé - Product at Prisma as well as by @User from KeystoneJS 😄nikolasburk
nativeTypes
preview feature flag has first been introduced in 2.11.0. Thanks to your continuous and awesome feedback for this feature, we're now able to release usage of native database types in the Prisma schema for General Availability 🎉
Note that this release comes with a few minor breaking changes compared to previous versions. Please read about the Breaking Changes in the release notes.
☁️ Prisma Migrate now works with cloud-hosted databases (e.g. Heroku)
Before this release, Prisma Migrate could be used to apply migrations in a cloud-hosted environment (CI/CD pipeline, manual deployment to production, staging, etc.), but it was impossible to create new migrations, due to the requirement of a shadow database.
Starting from this release, prisma migrate dev
can now be used in development with cloud-hosted databases by configuring a separate connection URL for the shadow database via a shadowDatabaseUrl
variable:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}
nikolasburk
prisma introspect
is becoming prisma db pull
In 2.10.0
we introduced the prisma db push
command that enables developers to update their database schema from a Prisma schema file without using migrations.
For the "opposite" motion (i.e., updating the Prisma schema from an existing database schema), we currently have the prisma introspect
command. In this release, prisma introspect
is being renamed to prisma db pull
. However, the prisma introspect
command will be kept around for a few more releases so that you have enough time to switch over to the new command.
Here is how we are planning to execute the renaming:
1. In this release, we are introducing a new command prisma db pull
, which behaves exactly the same as prisma introspect
.
2. We will at some point in the near future add a deprecation warning to the prisma introspect
CLI command.
3. Eventually, prisma introspect
will be removed.
There is no specific timeline to execute on this deprecation and we want to make sure we give developers a generous period of time to switch over.
🌱 More flexible seeding in TypeScript
The ts-node
command options can now be customized via package.json
to pass specific options to ts-node
. This makes prisma db seed
work with tools that have specific requirements when used with TypeScript, such as Next.js.
Here is an example that works with Next.js:
{
"name": "my-project",
"version": "1.0.0",
"scripts": {
"ts-node": "ts-node --compiler-options '{\"module\":\"CommonJS\"}'"
},
"devDependencies": {
"@types/node": "^14.14.21",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
}
}
⚠️ Relation syntax will not be updated automatically any more
Prisma has a set of rules for defining relations between models in the Prisma schema. The prisma format
command automatically helps to apply these rules by inserting missing pieces.
In previous releases, this expansion logic was applied automatically in several scenarios without running npx prisma format
explicitly, e.g. when running a prisma migrate
command. While helpful in some scenarios, these "magic" insertions often resulted in others errors that were harder to interpret and to debug for developers and ourselves.
In this release, the "magical" instertions are removed and developers need to explicitly run npx prisma format
if they want still make use of them.
🆕 New Upsert API for Prisma Client Go
Prisma Client Go now supports upsert operations:
post, _ := client.Post.UpsertOne(
// query
Post.ID.Equals("upsert"),
).Create(
// set these fields if document doesn't exist already
Post.Title.Set("title"),
Post.Views.Set(0),
Post.ID.Set("upsert"),
).Update(
// update these fields if document already exists
Post.Title.Set("new-title"),
Post.Views.Increment(1),
).Exec(ctx)
nikolasburk
nikolasburk
--preview-feature
flag is being removed, you can now use it as follows:
npx prisma migrate <COMMAND>
↕️ Order by aggregates of relations in Prisma Client queries (Preview)
This release makes it possible to order by the aggregates (e.g. count) of relations in your Prisma Client queries. Here's is an example that orders a list of users by the number of the posts they created:
const orderedUsers = await prisma.user.findMany({
orderBy: {
posts: {
count: 'asc'
}
}
})
This feature is released in Preview which means you have to explicitly enable it via the orderByRelation
feature flag in your Prisma schema:
generator client {
provider = "prisma-client-js"
previewFeatures = ["orderByRelation"]
}
🦦 Prisma Client Go now returns results from the Transaction
API
Previously in the Go Client, you could write data within a transaction, but you couldn't get the results back from the transaction. Now you can! Learn more in the documentation.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we'd very much appreciate if you would star the repo 🌟 And if you're excited about the features in this week's release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the "What's new in Prisma" livestream
As usual, my colleague @ryan and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.nikolasburk
nikolasburk
_count
to the select
or include
options and then specifying which relation counts should be included in the resulting objects via another select
.
For example, counting the number of posts that an user has written:
const users = await prisma.user.findMany({
include: {
_count: {
select: { posts: true },
},
},
})
The structure of the returned User
objects is as follows:
{
id: 1,
email: '<mailto:alice@prisma.io|alice@prisma.io>',
name: 'Alice',
_count: { posts: 2 }
}
You can enable this feature with the selectRelationCount
feature flag:
generator client {
provider = "prisma-client-js"
previewFeatures = ["selectRelationCount"]
}
There may be some rough edges during the Preview period. If you run into any problems, you can reach us in this issue.
⚡️ Reducing the communication overhead between the Node.js and Rust layers with N-API (Preview)
N-API is a new technique for binding Prisma's Rust-based query engine directly to Prisma Client. This reduces the communication overhead between the Node.js and Rust layers when resolving Prisma Client's database queries.
You can enable this feature with the napi
feature flag:
generator client {
provider = "prisma-client-js"
previewFeatures = ["napi"]
}
Enabling the N-API will not affect your workflows in any way, the experience of using Prisma will remain exactly the same. The N-API has different runtime characteristics than the current communication layer between Node.js and Rust. These are likely (but not certain) to result in a positive effect on the performance of your application. There may be some rough edges during the Preview period. If you run into any problems, you can reach us in this issue.
🐘 New push
operation available for arrays on PostgreSQL
PostgreSQL supports array data structures (sometimes also called scalar lists). As an example, consider the permissions
field on the following User
model:
model User {
id Int @id @default(autoincrement())
permissions String[]
}
As of this release, you can append a new item to existing lists atomically with the push
command:
await prisma.user.update({
where: { id: 42 },
data: {
permission: {
push: "chat:read",
},
},
})
Learn more in this issue.
🚀 groupBy
and createMany
are now Generally Available
For the pioneers among you, you can now remove the groupBy
and createMany
from your Preview features:
generator client {
provider = "prisma-client-js"
previewFeatures = ["groupBy", "createMany"] // can be removed now
}
🦦 Prisma Client Go now supports BigInt
, Decimal
and Bytes
Prisma Client Go continues to get more powerful every release. With this release, we've added support for more native database types: BigInt
, Decimal
and `Bytes`:
var views db.BigInt = 1
bytes := []byte("abc")
dec := decimal.NewFromFloat(1.23456789)
created, err := client.User.CreateOne(
db.User.Picture.Set(bytes),
db.User.Balance.Set(dec),
db.User.Views.Set(views),
).Exec(ctx)
Daniel Norman
2.21.0
, now you can!
const userRatingsCount = await prisma.user.groupBy({
by: ['city'],
count: {
city: true,
},
orderBy: {
_count: {
city: 'desc',
},
},
})
The query returns the following:
[
{ city: 'Berlin', count: { city: 3 } },
{ city: 'Paris', count: { city: 2 } },
{ city: 'Amsterdam', count: { city: 1 } },
]
Enable this feature with the orderByAggregateGroup
preview flag:
generator client {
provider = "prisma-client-js"
previewFeatures = ["orderByAggregateGroup"]
}
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🚢 The next 2.22.0 release will be postponed by a week
We release Prisma normally every two weeks. The next 2.22.0
release will be postponed by a week and happen on May 5, 2021.
🌳 Help us spread the word about Prisma and we’ll donate trees 🌳
To help spread the word about Prisma, we’d very much appreciate if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
Quick reminder that for every tweet tagging Prisma in the month of April, we’ll be donating a tree as part of Tweets for Trees .
📺 Join us on Thursday for the “What’s new in Prisma” livestream
This week, my colleague @ryan and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.
🙏 Big thanks to all the external contributors who helped with this release!nikolasburk
nikolasburk
prisma db push
is now Generally Available
prisma db push
enables you to update the database schema from the Prisma schema file, without generating any migrations.
This is especially useful when prototyping a new feature, iterating on the schema changes before creating migrations or generally if you are at stage of your development process, where you don't need to persist the schema change history via database migrations. It is now promoted from Preview to General Availability.
You can find more info on prisma db push
in the official docs .
👀 Deprecation of array notation for provider
fields
In this release, we are also entirely removing the array notation for the provider
fields on datasource
blocks. This has been deprecated since 2.11.0 (November 2020).
You can read more about our reasons for this deprecation here.
🦦 Prisma Client Go gets support for AND
operator
We've always had OR
, but this release we also added AND
support:
first, err := client.User.FindFirst(
User.Or(
User.Email.Equals("<mailto:john@example.com|john@example.com>"),
User.And(
User.Name.Equals("John"),
User.Username.Equals("johno"),
),
),
).Exec(ctx)
Learn more in our docs and share your feedback in the #prisma-client-go channel.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we'd very much appreciate if you would star the repo 🌟 And if you're excited about the features in this week's release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the "What's new in Prisma" livestream
This week, my colleague @Daniel Norman and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco. Would love to see you there 🙌Natalia
nikolasburk
Json
type. JSON filtering support is available in PostgreSQL and MySQL.
You can try it today by adding the filterJson
preview flag to your generator
block. This has been one of our most popular feature requests, so we're very excited to be getting it into your hands! For an example of what JSON filtering looks like in practice, check out the release notes.
🌱 Improvement for prisma db seed
In previous versions, a seed file could only be executed as a script. prisma db seed
was simply executing the script by either calling node ./prisma/seed.js
for JavaScript or ts-node ./prisma/seed.ts
for TypeScript.
Now, you can directly export a function that Prisma executes on your behalf. To learn more about this feature, check out the release notes.
⚠️ Breaking change
The options in groupBy
queries are now prefixed with an underscore.
Before `2.23.0`:
const result = await prisma.user.groupBy({
by: ['name'],
count: true,
})
2.23.0
and later:
const result = await prisma.user.groupBy({
by: ['name'],
_count: true,
})
For more details, check out the release notes.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we'd very much appreciate if you would star the repo 🌟 And if you're excited about the features in this week's release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the "What's new in Prisma" livestream
As usual, @ryan and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco which is in ~1 hour.
🌎 Prisma Day is happening on June 29/30
Save the date for Prisma Day 2021 and join us for two days of talks and workshops by the most exciting members of the Prisma community:
• June 29th: Workshops
• June 30th: Talks (Submit a talk proposal — CfP deadline is on Sunday)
We look forward to seeing you there! 👋nikolasburk
nikolasburk
Json
and Enum
Support
We just added Json
and enum
support to the MongoDB provider
for Prisma Client. Here's a sample schema with both:
prisma
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["mongodb"]
}
model Log {
id String @id @default(dbgenerated()) @map("_id")
message String
level Level @default(Info)
meta Json
}
enum Level {
Info
Warn
Error
}
As a reminder, the mongodb
provider is still in Early Access. If you'd like to use MongoDB with Prisma, please fill out this 2-minute Typeform and we'll get you an invite to our Getting Started guide and private Slack channel right away!
🚀 New features for the Prisma Data Platform
The Prisma Data Platform (PDP) helps developers collaborate better in projects that are using Prisma's open-source tools. One of its main features is an online data browser. In addition to this, you can now also view your Prisma schema, as well as delete and edit projects. Since recently, you can now also connect databases that are running behind a proxy server to your PDP projects using a static IP address.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we'd very much appreciate if you would star the repo 🌟 And if you're excited about the features in this week's release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the "What's new in Prisma" livestream
As usual, my colleague @ryan and I will discuss the latest release and other news from the Prisma ecosystem in a livestream on YouTube on Thursday at 5pm Berlin | 8am San Francisco.
🌎 Prisma Day is happening on June 29/30
Save the date for Prisma Day 2021 and join us for two days of talks and workshops by the most exciting members of the Prisma community.
• June 29th: Workshops
• June 30th: Talks
We look forward to seeing you there! 👋nikolasburk
prisma migrate dev
Database schema drift occurs when your database schema is out of sync with your migration history, i.e. the database schema has drifted away from the source of truth.
With this release, we improve the way how the drift is printed to the console when detected in the prisma migrate dev
command. While this is thew only command that uses this notation in today's release, we plan to use it in other places where it would be useful for debugging in the future.
Here is an example how the drift is presented with the new format:
[*] Changed the `Color` enum
[+] Added variant `TRANSPARENT`
[-] Removed variant `RED`
[*] Changed the `Cat` table
[-] Removed column `color`
[+] Added column `vaccinated`
[*] Changed the `Dog` table
[-] Dropped the primary key on columns (id)
[-] Removed column `name`
[+] Added column `weight`
[*] Altered column `isGoodDog` (arity changed from Nullable to Required, default changed from `None` to `Some(Value(Boolean(true)))`)
[+] Added unique index on columns (weight)
✅ Support for .env
files in Prisma Client Go
You can now use a .env
file with Prisma Client Go. This makes it easier to keep database credentials outside your Prisma schema and potentially work with multiple clients at the same time:
example/
├── .env
├── main.go
└── schema.prisma
Learn more about using the .env
file in our documentation. If you have any questions or issues with Prisma Client Go, you can raise them in the #prisma-client-go channel.
❌ Breaking change: Dropping support for Node.js v10
Node.js v10 reached End of Life on April 30th 2021. Many of our dependencies have already dropped support for Node.js v10 so staying up-to-date requires us to drop Node.js v10, too. We recommend upgrading to Node.js v14 or greater for longterm support. You can learn more about Node.js releases on this page.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we'd very much appreciate if you would star the repo 🌟 And if you're excited about the features in this week's release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the "What's new in Prisma" livestream
As usual, my colleague @ryan and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.
🌎 Prisma Day is happening on June 29/30
Join us for Prisma Day 2021, two days of talks and workshops by the most exciting members of the Prisma community. We look forward to seeing you there! 👋Mahmoud
06/29/2021, 2:46 PMmodel User {
id String @id
posts Post[]
}
model Post {
id String @id
authorId String
author User @relation(fields: [authorId], onDelete: Cascade, onUpdate: Cascade)
}
The feature can be enabled by setting the preview feature flag referentialActions
in the generator
block of Prisma Client in your Prisma schema file:
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialActions"]
}
If you run into any questions or have any feedback, we’re available in this issue.
📟 prisma init
now accepts a --datasource-provider
argument
This argument lets you configure the default provider for the initially generated datasource
block in your Prisma schema when using prisma init
to setup a new Prisma project.
⚡️ Node-API improvements (Preview)
Node-API is a new technique for binding Prisma’s Rust-based query engine directly to Prisma Client. This reduces the communication overhead between the Node.js and Rust layers when resolving Prisma Client’s database queries.
You can enable this feature with the nApi
feature flag:
generator client {
provider = "prisma-client-js"
previewFeatures = ["nApi"]
}
Enabling the N-API will not affect your workflows in any way, the experience of using Prisma will remain exactly the same. If you run into any problems, you can reach us in this issue.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we’d very much appreciate if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the “What’s new in Prisma” livestream
@ryan and @Daniel Norman will discuss the latest release and other news from the Prisma ecosystem in a livestream on YouTube on Thursday at 5pm Berlin | 8am San Francisco.
🌎 Prisma Day is happening today and tomorrow!
Join us for two days of talks and workshops by the most exciting members of the Prisma community.
• June 29th (today): Workshops
• June 30th: Talks
Make sure to sign up join the #prismaday channel so you can chat with the speakers 😄
We look forward to seeing you there! 👋Mahmoud
07/13/2021, 3:02 PMschema.prisma
file, you’ll need to set the database provider to mongodb
. You’ll also need to add mongoDb
to the previewFeatures
property in the generator
block:
// Set the database provider to "mongodb"
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
// We want to generate a Prisma Client
// Since mongodb is a preview feature, we need to enable it.
generator client {
provider = "prisma-client-js"
previewFeatures = ["mongoDb"]
}
// Create our Post model which will be mapped to a collection in the database.
// The id attributes tell Prisma it's a primary key and to generate
// object ids by default when inserting posts.
model Post {
id String @id @default(dbgenerated()) @map("_id") @db.ObjectId
slug String @unique
title String
body String
}
You’ll also need to add a database connection string to your .env
file. We recommend using MongoDB Atlas to spin up a MongoDB database for free.
Learn more in our Getting Started Guide
We would love to know your feedback! If you have any comments or run into any problems we’re available in this issue. You can also browse existing issues that have the MongoDB label.
⚡️ Prisma native support for M1 Macs
This one’s for our Mac users. Prisma now runs natively on the new M1 chips. Best of all, there’s nothing to configure, it just works. Enjoy the speed bump!
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we’d very much appreciate if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the “What’s new in Prisma” livestream
@ryan and @Daniel Norman will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.Mahmoud
07/27/2021, 10:57 AMMahmoud
08/10/2021, 5:12 PMinteractiveTransactions
preview feature in your Prisma Schema:
generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
}
Note that the interactive transactions API does not support controlling isolation levels or locking for now.
You can find out more about implementing use cases with transactions in the docs, and share your feedback.
🎉 namedConstraints
are now in Preview
So far the Prisma schema could only represent the underlying database names for @@unique
and @@index
.
Names for primary keys and foreign keys could not be represented even when the database supported these. This could lead to problems with the names of constraints in different environments getting out of sync and generated migrations therefore failing.
You can opt-in to namedConstraints
by setting the namedConstraints
preview feature in your Prisma Schema:
generator client {
provider = "prisma-client-js"
previewFeatures = ["namedConstraints"]
}
When using prisma db pull
these names will now automatically be pulled into your Prisma schema unless they match our default naming convention (which follows the Postgres convention).
Please check our upgrade guide before enabling the preview flag and running migrate operations for the first time.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we’d very much appreciate if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the “What’s new in Prisma” livestream
@Daniel Norman and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.Mahmoud
08/24/2021, 4:54 PMfullTextSearch
preview flag:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch"]
}
After you regenerate your client, you’ll see a new search
field on your String
fields that you can query on. Here’s an example:
// returns all posts that contain the words cat *or* dog.
const result = await prisma.post.findMany({
where: {
body: {
search: 'cat | dog',
},
},
})
You can learn more about how the query format works in our documentation. We would love to know your feedback! If you have any comments or run into any problems we’re available in this in this Github issue.
ℹ️ Validation errors for referential action cycles on Microsoft SQL Server
Prisma now checks for referential cycle actions when it validates your schema file and shows you the exact location of the cycle in your schema when using Microsoft SQL Server.
👋🏻 prisma introspect
is being deprecated in favor of prisma db pull
The prisma introspect
command is an alias for prisma db pull
, which allows you to pull the schema from the database into your local schema.prisma
file. Starting with this release, you will get a warning that encourages you to use prisma db pull
instead of prisma introspect
.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma🌟
To help spread the word about Prisma, we’d very much appreciate if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the “What’s new in Prisma” livestream
@Mahmoud will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.Daniel Norman
prisma db seed
has been revamped
prisma red Node-API
prisma darkblue Order by Aggregate in Group By
prisma Order by Relation
prisma red Select Relation Count
🤓 To read more about the GA release of the M*icrosoft SQL Server* and Azure SQL Connector, check out the blog post
📚 We recommend that you carefully read through the breaking changes in the release notes and make sure that you’ve correctly upgraded your application.📚
prisma rainbow Help us spread the word about Prisma prisma rainbow
To help spread the word about Prisma, we’d appreciate it if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter 🙌
🎥 **, where @User and I will discuss the latest release and other news from the Prisma ecosystem in a livestream on YouTube on Thursday at 5pm Berlin | 8am San Francisco.
📺 If you haven’t already, be sure to subscribe to our YouTube channel, so you get notified about new videos and livestreams!Daniel Norman
User:Post
, you can configure the deletion of a user to cascade to posts so that no posts are left pointing to a User that doesn’t exist. In Prisma, these constraints are defined in the Prisma schema with the @relation()
attribute.
However, databases like PlanetScale do not support defining foreign keys. To work around this limitation so that you can use Prisma with PlanetScale, we’re introducing a new referentialIntegrity
setting in Preview.
This was initially introduced in version 2.24.0
of Prisma with the planetScaleMode
Preview feature and setting. Starting with this release both have been renamed to referentialIntegrity
.
The setting lets you control whether referential integrity is enforced by the database with foreign keys (default), or by Prisma, by setting referentialIntegrity = "prisma"
.
Setting Referential Integrity to prisma
has the following implications:
• Prisma Migrate will generate SQL migrations without any foreign key constraints.
• Prisma Client will emulate foreign key constraints and referential actions on a best-effort basis.
You can give it a try in version 3.1.1 by enabling the referentialIntegrity
preview flag:
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
⚠️ Note that Referential Integrity is set to prisma
by default when using MongoDB.
📚Learn more about Referential Integrity in our documentation.
prisma red Full-Text Search for the Go Client
In an earlier release, we added Full-Text Search (for PostgreSQL) to the Typescript Client. This was released as a Preview feature.
In this release, we’ve added that Preview feature to the Go Client. Enable it in your Go project by adding the fullTextSearch
preview feature.
Here’s an example:
// Fetch all drafts with a title that contains the words fox or dog
posts, _ := client.Post.FindMany(
db.Post.Title.Search("fox | dog"),
db.Post.Status.Equals("Draft"),
).Exec(context.Background())
// Loop over the posts and print the title
for _, post := range posts {
fmt.Println(post.Title)
}
Daniel Norman
nikolasburk
prisma db pull
against a MongoDB database with existing data will sample the data and create a Prisma data model based on the stored documents.
This comes with a few caveats:
• The preview feature mongoDb
must be enabled on the datasource
block in the Prisma schema.
• The MongoDB instance must have at least one collection with at least one document.
• To introspect indices, there must be at least one document in the collection with the indexed fields.
• If any fields have conflicting types, the most common type is chosen and the other types are written to a comment above the field in the Prisma schema.
• Relations must be added manually after introspection.
• Running prisma db pull
multiple times will overwrite any added text in the data model for now.
We're constantly iterating on this feature, so please provide feedback for introspecting MongoDB databases!
🔢 Get the count of a relation in MongoDB
This release, we're giving MongoDB developers the ability to query the count of a relation. In the example below, we're getting the number of posts each user wrote:
const userWithPostsCount = await prisma.user.findMany({
include: {
_count: {
select: { posts: true },
},
},
})
// => [
// {
// email: "<mailto:alice@prisma.io|alice@prisma.io>",
// _count: { posts: 3 }
// }
// ]
This feature was previously available for SQL databases and now it's also available in MongoDB. Learn more in our documentation.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we'd very much appreciate if you would star the repo 🌟 And if you're excited about the features in this week's release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the "What's new in Prisma" livestream
This week, my colleague @Daniel Norman and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.nikolasburk
3.3.0
, we're releasing Early Access support for Prisma Client connection pooling using the Prisma Data Proxy. The Data Proxy feature of the Prisma Data Platform is now accessible to all users of the Prisma Data Platform (no need to request access). For detailed documentation and instructions about the Data Proxy, check out pris.ly/data-proxy.
Using this new feature in Prisma Client and leveraging the Data Proxy, developers can now also deploy Prisma applications on Cloudflare Workers. Here's what it looks like to use Prisma Client inside of this environment:
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request: Request): Promise<Response> {
await prisma.log.create({
data: {
level: 'Info',
message: `${request.method} ${request.url}`,
},
})
return new Response(`request method: ${request.method}!`)
}
Follow this deployment guide to learn how to use Prisma Client with your own Cloudflare Workers.
🔀 Support for ordering by relation fields in MongoDB
In 2.16.0
, we first introduced ordering by a relation for relational databases. As of today's release, you can now order by a relation field in MongoDB as well:
ts
// Return a list of posts ordered by the author's email address
// in ascending order.
await prisma.post.findMany({
orderBy: {
author: {
email: "asc",
},
},
})
5️⃣ MongoDB 5 is now supported
Prisma now supports connecting to MongoDB 5 databases. Take advantage of the latest and greatest from the fine folks at MongoDB HQ and share your feedback in the #mongodb channel here on Slack!
🦦 Prisma Client Go now supports scalar list operations
With 3.3.0
, you can now filter and atomically update scalar lists with Prisma Client Go.
Given the following Prisma schema:
model User {
id Int @id @default(autoincrement())
name String
pets String[]
}
You can filter pets with the following code:
user, err := client.User.FindFirst(
db.User.Pets.HasSome([]string{"Fido", "Scooby"}),
).Exec(ctx)
And when you add a new furry addition to your family, you can update your list with `Push`:
user, err := client.User.FindUnique(
db.User.Name.Equals(1),
).Update(
db.User.Items.Push([]string{"Charlemagne"}),
).Exec(ctx)
Learn more about how to use this new feature in our documentation and share your feedback in the #prisma-client-go channel here on Slack!
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we'd very much appreciate if you would star the repo 🌟 And if you're excited about the features in this week's release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the "What's new in Prisma" livestream
This week, my colleague @Daniel Norman and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.nikolasburk
3.4.0
provides support for PostgreSQL 14. For a full list of our supported databases and their versions, see our documentation.
🔀 Support for ordering by aggregate group in MongoDB
In Prisma version 3.4.0
, we add support on MongoDB databases for using the ORDER BY
clause in an aggregate function. This was previously available for relational databases.
For example, if the data about your application’s users includes their city of residence, you can determine which cities have the largest user groups. The following query sorts each city
group by the number of users in that group, and returns the results in descending order (largest group first):
const groupBy = await prisma.user.groupBy({
by: ['city'],
_count: {
city: true,
},
orderBy: {
_count: {
city: 'desc',
},
},
})
For more information refer to our documentation about ordering by groups.
✨ Initial support for MongoDB in prisma db push
The prisma db push
command is used to sync your Prisma schema and your database schema in development. Because MongoDB has a unique approach to database schema management, this initial release only syncs @unique
, @@unique
and @@index
annotations in your schema.
Check out the release notes for a practical example of using prisma db push
with MongoDB.
🔎 Introspection of embedded documents in MongoDB
For those interested in helping us getting introspection of embedded documents right, we packaged a first iteration into the CLI. More info in the Github issue.
🚀 Prisma Client Go now supports the Data Proxy
Connection limit issues got you down? By using Prisma’s Data Proxy, you can pool your connections to avoid overloading your database. With this release, Prisma Client Go can now read and write to the Data Proxy.
Check out the release notes for more info about this!
🦦 JSON filtering support in Prisma Client Go
We’ve had JSON filtering support in the TypeScript Client since . In today’s release, we’re bringing support to the Go Client. Here’s an example snippet of the API:
logs, _ := client.Log.FindMany(
db.Log.Meta.Path([]string{"service"}),
db.Log.Meta.Equals(db.JSON("\"api\"")),
).Exec(ctx)
Learn more about how to use this new feature in our documentation and share your feedback in the #prisma-client-go channel here on Slack!
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we’d very much appreciate if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
🌐 The Prisma Serverless Data Conference is happening on November 18
Make sure to claim your ticket for our free Prisma Serverless Data Conference about all things databases and serverless with fantastic speakers from companies like PlanetScale, MongoDB, Vercel, Netlify, Cloudflare and CockroachDB.
📰 Join us on Thursday for the “What’s new in Prisma” livestream
This week, my colleague @Alex Ruheni and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.nikolasburk
3.5.0
, we’ve added support for ordering full text search results by relevance. Ordering by relevance gives you a way to order search results by the best match.
While this feature is useful standalone, it’s most commonly used in combination with the full text search
field in the where
clause:
const query = "node.js developer"
const developers = await prisma.people.findMany({
where: {
bio: {
// Only select people whose bio's contain "node.js developer"
search: query,
},
},
orderBy: {
// Order that selection by query relevance.
_relevance: {
fields: ["bio"],
search: query,
sort: "desc",
},
},
})
Learn more in our documentation and if you run into any issues or have feedback for us, you can reach us in this issue.
⚙️ More configuration options for indexes and constraints in the Prisma schema (Preview)
We are extending the syntax in the Prisma schema to add support for configuration of length and sort order for:
• indexes
• unique constraints
• primary key constraints
The following example demonstrates the use of the sort
and length
arguments:
model Post {
title String @db.VarChar(300)
abstract String @db.VarChar(3000)
slug String @db.VarChar(3000) @unique(sort: Desc, length: 42)
author String
created_at DateTime
@@id([title(length: 100, sort: Desc), abstract(length: 10)])
@@index([author, created_at(sort: Desc)])
}
⚠️ Warning: This might be a breaking change for some users. To learn how to mitigate that, please read the documentation linked below.
Learn more in the documentation on index configuration.
🦦 Case insensitive filtering for Prisma Client Go
We’ve had this feature in the Prisma Client JS for a while, but in this release, we’ve added case-insensitive query support to the Go Client as well. Now you can worry a bit less about what kind of data the user is going to send your way.
users, err := client.User.FindMany(
User.Email.Equals("prisMa"),
User.Email.Mode(QueryModeInsensitive), // sets case insensitivity
).Exec(ctx)
Learn more in our documentation and share your feedback in the #prisma-client-go channel here on Slack!
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we’d very much appreciate if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
🌐 The Prisma Serverless Data Conference is happening on Thursday (Nov 18)
Make sure to claim your ticket for our free Prisma Serverless Data Conference about all things databases and serverless with fantastic speakers from companies like PlanetScale, MongoDB, Vercel, Netlify, Cloudflare and CockroachDB.
📰 Join us on Wednesday(!!!) for the “What’s new in Prisma” livestream
This week, my colleague @Daniel Norman and I will discuss the latest release and other news from the Prisma ecosystem in a on Wednesday at 5pm Berlin | 8am San Francisco.Alex Ruheni
db pull+
, db push
and migrate
commands for MySQL and MongoDB databases as a Preview feature. For now, we do not enable the full-text search commands in the Prisma Client. They will be implemented separately. You can follow the progress in the MongoDB and MySQL issues.
Add the Preview feature fullTextIndex
to the Prisma schema, after which the @@fulltext
attribute is allowed in the Prisma schema:
generator js {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
}
model A {
id Int @id
title String @db.VarChar(255)
content String @db.Text
@@fulltext([title, content])
}
Note: It is mandatory to do db pull
with the Preview feature enabled before using Prisma Migrate on existing MySQL databases, so the index types can be converted and will not get overwritten in the next migration.
For more details checkout our documentation.
💥 Hash index support for PostgreSQL (Preview)
With the extendedIndexes
Preview feature, it is now possible to use Hash
instead of the default BTree
as the index algorithm on PostgreSQL databases. A hash index can be much faster for inserts, but it only supports equals operation in the database. Here’s an example of using a hash index:
generator js {
provider = "prisma-client-js"
previewFeatures = ["extendedIndexes"]
}
model A {
id Int @id
value Int
@@index([value], type: Hash)
}
For more details checkout our documentation.
🚀 VS Code extension now uses a Wasm module
Starting with 3.6.0
, the language server and the VS Code extension use logic compiled to WebAssembly and distributed through npm. If you have any feedback, please leave an issue in the `prisma/language-tools` repository.
✨ Bytes
can now be filtered with in
and notIn
You can now use in
and notIn
operations on the Bytes
type:
const audioTracks = raws.map(raw => {
return Buffer.from(raw)
})
const result = await prisma.audio.find({
where: {
track:
in: audioTracks
}
}
})
👀 Json
fields now accept read-only types
You can now pass immutable values into Json
fields. In the following example, audit
is a Json
field that accepts a read-only array:
const trail = [
{ event: "signup" },
{ event: "subscribe" },
{ event: "invite friend" }
] as const
await prisma.user.create({
data: {
audit: trail
}
})
Learn more in this issue.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we’d very much appreciate if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the “What’s new in Prisma” livestream
This week, @nikolasburk and @Daniel Norman will discuss the latest release and other news from the Prisma ecosystem in a on Wednesday at 5 pm Berlin | 8 am San FranciscoAlex Ruheni
3.7.0
prisma rainbow
🧪 Referential actions support for MongoDB
In 3.7.0
, we’ve added MongoDB support for onDelete
and onUpdate
to specify how you want to handle changes to relationships. MongoDB does not support referential actions out of the box, but we can emulate this feature inside the Prisma Query Engine. Given the following schema:
model User {
id String @id @default(dbgenerated()) @map("_id") @db.ObjectId
posts Post[]
name String
}
model Post {
id String @id @default(dbgenerated()) @map("_id") @db.ObjectId
author User @relation(fields: [userId], references: [id], *onDelete: Cascade*)
title String
userId String @db.ObjectId
}
By specifying onDelete: Cascade
, Prisma will also delete posts whenever the author of the posts is deleted. There’s a lot more to referential actions than cascading deletes. Head over to our documentation to learn more. Prisma exposes features and workflows that database vendors don’t offer.
🔁 Prevent referential cycles on MongoDB
As part of getting onDelete
and onUpdate
ready for MongoDB, we’ve tightened up our validation rules to prevent a potential stack overflow if you create a loop with referential actions.
This change may cause some existing schemas using the mongodb
preview feature to become invalid, where your schema now errors out with the following message:
Error parsing attribute "@relation": Reference causes a cycle.
If you run into this, you can learn how to resolve it with this documentation. If you’re still stuck, feel free to open a discussion, and we’ll lend a hand!
⚠️ Deprecating undocumented usage of type
in Prisma Schema
With Prisma 3.7.0
release, the VS Code extension (and other IDEs using our language server implementation) will start to show a warning when detecting unsupported usage of the type
keyword. We plan to remove that functionality entirely with the next major release of Prisma. If you depend on similar functionality for type aliasing, please comment on the issue. Here’s an example of a string alias:
type MyId = String @id @default(dbgenerated(new_uuid()))
model A {
id MyId
}
🔒 Prisma Studio improvements
• Due to how Prisma Studio executes Prisma Client queries, it was possible to execute arbitrary code on Studio’s local server. This has since been patched.
• Issues with viewing and updating models with BigInt
fields are also resolved.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we’d very much appreciate it if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
📰 Join us today for the “What’s new in Prisma” livestream
This week, @nikolasburk and @Alex Ruheni R. will discuss the latest release and other news from the Prisma ecosystem in a livestream on YouTube today at 5 pm Berlin | 8 am San Francisco.Alex Ruheni
3.8.0
prisma rainbow
🔍 Full-text search support for MySQL is now in Preview
Prisma now supports full-text search in MySQL. You can enable full-text support by adding the fullTextIndex
and fullTextSearch
Preview flags in your Prisma schema and defining @@fulltext()
index on fields you’d like to use full-text search on.
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex", "fullTextSearch"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Post {
id Int @id @default(autoincrement())
title String @unique
@@fulltext([title])
}
Run prisma db push
or prisma migrate dev
to update your database schema. Prisma Client will also be re-generated, enabling you to use full-text search in your application.
// search for titles that contain cat, but not fox
await prisma.post.findMany({
where: {
title: {
search: "+cat -fox",
},
},
})
Learn more in our documentation.
🚧 dataProxy
and interactiveTransactions
are now mutually exclusive
Before Prisma 3.8.0
, Prisma queries would fail whenever the Data Proxy and interactive transactions Preview features were used together. The interactiveTransactions and dataProxy Preview flags cannot be used together in this release. Generating the Prisma Client when both Preview features are enabled will throw an error.
🔧 Fixed support for push
when adding an element to an array in MongoDB
Prisma 3.8.0
fixed push
support for `ObjectId`s on MongoDB. Given the following schema:
model Course {
id String @id @default(dbgenerated()) @map("_id") @db.ObjectId
title String
students String[] @db.Array(ObjectId)
}
You can now run the following query:
// Add a new student to the course
await prisma.course.update({
where: {
id: 1
},
data: {
students: {
push: new ObjectID("...")
}
}
})
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma 🌟
To help spread the word about Prisma, we’d very much appreciate it if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the “What’s new in Prisma” livestream
This week, I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5 pm Berlin | 8 am San Francisco