You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before 2.21.0, aggregations on nullable fields always returned 0, even when there was no record or if all aggregated records were nulls. Returning 0 for null values made it impossible to differentiate between these two different results.
We are changing aggregates to follow what the database returns:
All aggregated fields are now nullable. Aggregated fields can return null when there's either no record in the database or if all the aggregated records are null.
The only exception is count, which still returns 0, even if records are null or if there's no record.
For example, previously, if there's no record in the database or if all records are nulls, the following aggregation:
And no profile was connected to Bob, the client would throw with this error:
The records for relation `UserToProfile` between the `User` and `Profile` models are not connected.
We learned from you that handling this added unnecessary boilerplate to your applications. As of 2.21.0, we've removed this error. Now, if you try disconnecting an unconnected record, the operation does nothing and passes through.
This change is unlikely to affect you unless you explicitly handle the disconnect error. In that case, adjust your code because the command no longer throws an error.
@default(dbgenerated("")) is no longer permitted
The dbgenerated() function allows you to define default values generated directly by the database and cannot yet be represented in the Prisma schema.
Previously, you could pass an empty string, i.e., @default(dbgenerated("")), which would fail since the contents are added into the migration SQL as columnName COLUMN_TYPE DEFAULT <contents of dbgenerated>
As of 2.21.0, if a value is present, it cannot be an empty string.
If you want an empty string default, the correct syntax is @default(dbgenerated("''") (or other quotation marks, depending on the database provider).
On PostgreSQL, when changing column types that are also in an index, Migrate would generate a DROP COLUMN ..., ADD COLUMN ... sequence of SQL statements. These silently drop the indexes present on the column, and migrate would only re-create them with the next migration. With this release, the issue has been fixed, and Migrate recreates the index in the same migration.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Today, we are excited to share the
2.21.0stable release 🎉🌟 Help us spread the word about Prisma by starring the repo ☝️ or tweeting about the release.
Major improvements & new features
Order by an aggregate in groupBy is now in Preview
Whew, that's a tongue-twister for a neat feature.
Let's say you want to group your users by the city they live in and then order the results by the cities with the most users. In
2.21.0, now you can!Click to view the underlying model
The query returns the following:
Enable this feature with the
orderByAggregateGrouppreview flag:Breaking Changes
Aggregates are now nullable
Before
2.21.0, aggregations on nullable fields always returned 0, even when there was no record or if all aggregated records were nulls. Returning 0 for null values made it impossible to differentiate between these two different results.We are changing aggregates to follow what the database returns:
For example, previously, if there's no record in the database or if all records are nulls, the following aggregation:
Results in:
The
result.sumtype is currently of type{ amount: number }.Starting this release, the same query returns:
And
result.sumis of type{ amount: number | null }disconnectno longer throws an error on unconnected recordsPrior to
2.21.0, if you ran the following code:And no profile was connected to Bob, the client would throw with this error:
We learned from you that handling this added unnecessary boilerplate to your applications. As of
2.21.0, we've removed this error. Now, if you try disconnecting an unconnected record, the operation does nothing and passes through.This change is unlikely to affect you unless you explicitly handle the
disconnecterror. In that case, adjust your code because the command no longer throws an error.@default(dbgenerated(""))is no longer permittedThe
dbgenerated()function allows you to define default values generated directly by the database and cannot yet be represented in the Prisma schema.Previously, you could pass an empty string, i.e.,
@default(dbgenerated("")), which would fail since the contents are added into the migration SQL ascolumnName COLUMN_TYPE DEFAULT <contents of dbgenerated>As of
2.21.0, if a value is present, it cannot be an empty string.If you want an empty string default, the correct syntax is
@default(dbgenerated("''")(or other quotation marks, depending on the database provider).Fixes and improvements
Prisma Client
countthrows an error ifincludeis specified12.22.0Prisma Migrate
DROP COLUMN ..., ADD COLUMN ...sequence of SQL statements. These silently drop the indexes present on the column, and migrate would only re-create them with the next migration. With this release, the issue has been fixed, and Migrate recreates the index in the same migration.This line is invalid. It does not start with any known Prisma schema keyword.in introspection for an invalid schema.db pushcrashes when used on specific Postgres connection string with non existing databasePrisma Studio
We worked on shipping some minor improvements and bug fixes:
prisma-engines
Credits
Huge thanks to @Sytten, @endor, @iBluemind, @schiller-manuel, @mongolyy, @matthewmueller, @paularah, @Iamshankhadeep, @meeq, @safinsingh for helping!
This discussion was created from the release 2.21.0.
All reactions