Today, we are issuing the `2.2.0` stable release.
Major improvements
Next to a lot of bug fixes, this version includes a number of new features!
Quick fix suggestions in Prisma VSCode Extension
The [Prisma VS Code extension](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma) now helps you fix any accidental typos and offers more convenient ["Quick Fixes"](https://github.com/prisma/vscode/issues/227) right inside your editor.
<img src="https://imgur.com/SmgDmZM.gif" width="500px" />
Make datasource `provider` dynamic via environment variables
The `provider` field on the `datasource` defininitions in your Prisma schema now also accepts an _array_ of strings (instead of just a plain string). This can be helpful when you want to switch environments which point to different databases based on an environment variable. Learn more about this feature [here](https://github.com/prisma/prisma/issues/1487).
prisma
datasource db {
provider = ["sqlite", "postgres"]
url = env("DATABASE_URL")
}
Experimental features
Already existing experimental features
Just a quick reminder: In [`v2.1.0`](https://github.com/prisma/prisma/releases/tag/2.1.0) we introduced two experimental features, namely **`connectOrCreate`** and **`transactionApi`**. In case they're useful for you, please give them a try! They stay experimental in this release.
Re-Introspection
We were able to continue to improve the re-introspection flow based on your feedback. Thanks!
Aggregations API
While Prisma Client already provides a `count` query for each model, we now introduce further aggregation functionality for _number_ fields.
If your model has a field of type `Int` or `Float`, the following aggregations will be available:
- `sum`: Sum up all values of a field for the selected rows.
- `min`: Get the minimum value for a field for the selected rows.
- `max`: Get the maximum value for a field for the selected rows.
- `avg`: Get the average value for a field for the selected rows.
Example
Note, that the `count` API is always available, while `sum`, `min`, `max`, and `avg` are only available for a model if it has a number field.
<table>
<thead>
<tr>
<th>Prisma Schema</th>
<th>Prisma Client Query</th>
<th><pre>Result</pre></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<pre lang="prisma">
model User {
id Int id
age Int
name String
}
</pre>
</td>
<td>
<pre lang="js">
const result = await prisma.user.aggregate({
where: { age: { gt: 5 } }, // optional
count: true,
avg: {
age: true,
},
max: {
age: true,
},
min: {
age: true,
},
sum: {
age: true
}
})
</pre>
</td>
<td>
<pre lang="js">
{
"count": 10,
"avg": {
"age": 80
},
"max": {
"age": 163
},
"min": {
"age": 5
},
"sum": {
"age": 800
}
}
</pre>
</td>
</tr>
</tbody>
</table>
Feature flag
In order to enable this experimental feature, note that you need to set the feature flag `aggregateApi` in the Prisma Client generator block in your schema:
prisma
generator client {
provider = "prisma-client-js"
experimentalFeatures = ["aggregateApi"]
}
Please [share your feedback](https://github.com/prisma/prisma/issues/2838) on how this feature works for you. We are interested in both positive and negative feedback, so we know if this feature is already ready for production! (If encounter any problems, please open a new issue [here](https://github.com/prisma/prisma/issues/new/choose)).
Fixes and improvements
`prisma`
- [Make datasource provider dynamic via environment variables](https://github.com/prisma/prisma/issues/1487)
- [Introspection doesn't recognize enums in PostgreSQL](https://github.com/prisma/prisma/issues/2548)
- [[Introspection] Investigate if our Introspection queries (can) return the correct order of columns](https://github.com/prisma/prisma/issues/2554)
- [PrismaClient throw error on missing is env even when overwriting database connection](https://github.com/prisma/prisma/issues/2609)
- [Pagination: cursor is ignored when using negative take argument](https://github.com/prisma/prisma/issues/2696)
- [Generator error hidden](https://github.com/prisma/prisma/issues/2722)
- [`prisma generate` throws exit code 0 in case of error caused by denied keywords](https://github.com/prisma/prisma/issues/2729)
- [.env not loaded when running `prisma migrate (save | up | down) --schema <file-path>`](https://github.com/prisma/prisma/issues/2735)
- [MySQL: Unreachable database host leads to unknown error](https://github.com/prisma/prisma/issues/2750)
- [Prisma format ignores newlines at the end of files](https://github.com/prisma/prisma/issues/2760)
- [Prisma introspection should add a trailing newline](https://github.com/prisma/prisma/issues/2768)
- [Introspection: Use env vars to override introspection binary with --url --print](https://github.com/prisma/prisma/issues/2773)
- [prisma/engine-core's package.json uses a github url for its version of undici](https://github.com/prisma/prisma/issues/2808)
- [Unify prisma introspect and prisma introspect --url wrt re-introspection](https://github.com/prisma/prisma/issues/2819)
- [Strange relation error message when running prisma generate ](https://github.com/prisma/prisma/issues/2832)
- [Support selections using basic aggregations](https://github.com/prisma/prisma/issues/2838)
- [Re-introspection error for renamed relations when there are multiple relations to the same table](https://github.com/prisma/prisma/issues/2844)
- [Introspection doesn't add or loses trailing new line of schema file](https://github.com/prisma/prisma/issues/2854)
- [UUID Cursor Pagination](https://github.com/prisma/prisma/issues/2855)
- [Schema validation: default(autoincrement()) on a String field should be rejected](https://github.com/prisma/prisma/issues/2865)
- [Switch to undici](https://github.com/prisma/prisma/issues/2890)
- [Introspect removes experimental features from schema](https://github.com/prisma/prisma/issues/2920)
- [Add new line checks to integration tests](https://github.com/prisma/prisma/issues/2926)
`prisma-client-js`
- [Add more integration tests for unhappy paths](https://github.com/prisma/prisma-client-js/issues/484)
- [Better error message when generated Client and local Prisma schema are out of sync](https://github.com/prisma/prisma-client-js/issues/586)
- [Multiple quick `count` requests result in `Invalid prisma.web_hooks.count invocation`](https://github.com/prisma/prisma-client-js/issues/670)
- [Wrong jsDocs annotations for `create` and `delete`](https://github.com/prisma/prisma-client-js/issues/726)
- [Raw API concerns](https://github.com/prisma/prisma-client-js/issues/727)
- [Improve sqlite error messages](https://github.com/prisma/prisma-client-js/issues/731)
- [JSON Filter does not work](https://github.com/prisma/prisma-client-js/issues/745)
- [Bulk Operations Naming Conflict ](https://github.com/prisma/prisma-client-js/issues/749)
- [Transaction API is not writing the transaction](https://github.com/prisma/prisma-client-js/issues/750)
- [Expose debug mode to trigger a panic for reproductions](https://github.com/prisma/prisma-client-js/issues/756)
`migrate`
- [`migrate up` tells me to read in `./migrations/MIGRATION_ID/README.md`](https://github.com/prisma/migrate/issues/172)
- [Create new SQL Database missing first char on name](https://github.com/prisma/migrate/issues/283)
- [`migrate save/up` hangs while creating database](https://github.com/prisma/migrate/issues/342)
- [`README.md` of migration folder includes `quaint` in SQL](https://github.com/prisma/migrate/issues/354)
- [Validate `default(now())` so that it only can be used in DateTime fields](https://github.com/prisma/migrate/issues/482)
`vscode`
- [Publish lsp server to npm](https://github.com/prisma/vscode/issues/112)
- [Quick Fix for fields with unknown types](https://github.com/prisma/vscode/issues/227)
- [Remove test cases that point to a four digit versioning scheme](https://github.com/prisma/vscode/issues/247)
- [Run integration tests on an extension release](https://github.com/prisma/vscode/issues/256)
- [Add instructions for each feature in README](https://github.com/prisma/vscode/issues/265)
- [Composite keys are not considered valid?](https://github.com/prisma/vscode/issues/266)
- [README on marketplace does not show Prisma Logo](https://github.com/prisma/vscode/issues/270)
- [Lerna bootstrap does not install all dependencies](https://github.com/prisma/vscode/issues/272)
- [Connection to server got closed. Server will restart.](https://github.com/prisma/vscode/issues/279)
- [Investigate `***` in GH action output](https://github.com/prisma/vscode/issues/288)
`studio`
- [Allow for column resizing](https://github.com/prisma/studio/issues/113)
- [Table scroll area should start underneath table header](https://github.com/prisma/studio/issues/195)
- [Select range of records when holding shift key](https://github.com/prisma/studio/issues/324)
- [Table's loading illustration may overlap with the table content](https://github.com/prisma/studio/issues/366)
- [Tooltips for table header columns](https://github.com/prisma/studio/issues/378)
- [Type to edit Enums and Booleans with autocomplete](https://github.com/prisma/studio/issues/383)
- [Copy & paste from a cell does not seem to work](https://github.com/prisma/studio/issues/417)
- [A better databrowser table](https://github.com/prisma/studio/issues/429)
- [In the "connect to X" view I would like to connect when clicking on a row](https://github.com/prisma/studio/issues/430)
- [Loading state shows unexpected data](https://github.com/prisma/studio/issues/432)
- [Scrolling down in relation accordion does not show entries](https://github.com/prisma/studio/issues/438)
- [After editing relation only the number of unsaved changes is shown in main table](https://github.com/prisma/studio/issues/439)
- [Styling of editing Int is different from editing String](https://github.com/prisma/studio/issues/440)
- [Loading state is not really indicated](https://github.com/prisma/studio/issues/447)
`prisma-engines`
- [Mask Datasource URLs in all artifacts generated by the Migration Engine](https://github.com/prisma/prisma-engines/issues/840)
- [Do not try setting database defaults for `default(dbgenerated())` fields.](https://github.com/prisma/prisma-engines/issues/844)
- [Multiple datasources in schema must be forbidden](https://github.com/prisma/prisma-engines/issues/869)