Prisma

Latest version: v0.15.0

Safety actively analyzes 687918 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 25 of 44

2.1.2

Today, we are issuing the `2.1.2` patch release.

Fixes and improvements

Studio
- New table grid component

Prisma Client
- [Transaction API is not writing the transaction 750](https://github.com/prisma/prisma-client-js/issues/750)
- [JSON Filter does not work 745](https://github.com/prisma/prisma-client-js/issues/745)

2.1.1

Today, we are issuing the `2.1.1` patch release.

Fixes and improvements

`prisma migrate `

- [Mask datasource URLs in migration files to avoid leaking credentials](https://github.com/prisma/prisma-engines/issues/840)
- [Migrate migration writes credentials out in the readme file](https://github.com/prisma/migrate/issues/310)

2.1.0

Today, we are issuing the `2.1.0` stable release.

Major improvements

Next to a lot of bug fixes, this version includes a number of new features.

Basic filtering on `Json` data in Prisma Client

When querying data, you can now perform basic filtering with `Json` fields using `equal` and `not`:

ts
const jsonData = [
{
array1key: 'array1value',
},
]

// `equal` filter. Return all posts with this particular `jsonData`
const result = await prisma.post.findMany({
where: {
jsonData
},
})


// `not` filter. Return all posts, which don't have this `jsonData`
const result = await prisma.post.findMany({
where: {
jsonData: { not: jsonData }
},
})


📚 **Documentation**: [Working with `Json` fields](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/working-with-json#filter-on-a-json-field)

<details><summary>Expand to view a Prisma schema for this example</summary>

A sample Prisma schema for the example above could look like this:

prisma
model Post {
id Int id default(autoincrement())
title String
content String?
jsonData Json
}


</details>

Hide the Prisma CLI update message

You can now hide the Prisma CLI update notifier message by setting the environment variable `PRISMA_HIDE_UPDATE_MESSAGE` (e.g. to `"1"`, `"true"` or `"asd"`).

bash
export PRISMA_HIDE_UPDATE_MESSAGE="1"


Prepared statement caching for PostgreSQL

Under the hood, we enabled _prepared statement caching_ for PostgreSQL. This way Prisma Client's [query engine](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/query-engine) does not repeatedly prepare the same statement but can reuse an existing one which reduces database CPU usage and query latency.

Many bug fixes for Prisma VSCode Extension

The [Prisma VSCode extension](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma) received an extraordinary number of tiny fixes this release, which will make using it much more pleasant. [Give it a try!](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma)

Experimental features

With the GA release of Prisma 2.0, you can expect much more stable releases in the future. At the same time, we of course want to be able to release new features that are fresh from our developers for you to try out. This is the best way we can get them stable enough to be generally available.

We are doing this with **experimental features**.

> 🚨 The following features are not part of our official and stable API and may be changed or removed completely in a future release.

Enabling experimental features in Prisma Client

With this release, we introduce [**feature flags**](https://en.wikipedia.org/wiki/Feature_toggle) for Prisma Client. Similar to the `--experimental` flag in the CLI (for `prisma studio` and `prisma migrate`), this enables us to hide functionality from the _default_ API that _all_ users get when installing Prisma and Prisma Client. Instead, users can _explicitly_ opt-in to certain features by enabling them via the new `experimentalFeatures` field on the Prisma Client [`generator`](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/generators/) definition in their [Prisma schema](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema).

The `experimentalFeatures` field can be set like this:

prisma
generator client {
provider = "prisma-client-js"
experimentalFeatures = ["connectOrCreate", "transactionApi"]
}


Read more below to learn about the [`connectOrCreate`](https://github.com/prisma/prisma-client-js/issues/336) and [`transactionApi`](https://github.com/prisma/prisma-client-js/issues/667) experimental features.

`connectOrCreate`
When updating or creating a record, we now provide a new operation as a nested mutation: `connectOrCreate`.
You can connect (if exists) or create (if it doesn't exist) to a related row.

📚 **Documentation**: [Relation queries: `connectOrCreate`](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/relation-queries#update-an-existing-user-record-by-connect-it-to-two-existing-post-records-or-creating-two-new-post-records)

Example

In this example, we create a new post and _connect_ it to an author with the email address `alicehey.com`. If that author doesn't exist yet, create it with the name `"Alice"`.

ts
await prisma.post.create({
data: {
title: 'Prisma 2.1.0',
author: {
connectOrCreate: {
where: {
email: "alicehey.com"
},
create: {
name: "Alice",
email: "alicehey.com"
}
}
}
}
})


Feature flag

To enable `connectOrCreate`, you can use the feature flag `connectOrCreate` in your Prisma schema file:

prisma
generator client {
provider = "prisma-client-js"
experimentalFeatures = ["connectOrCreate"]
}


Please [share your feedback](https://github.com/prisma/prisma-client-js/issues/336) 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-client-js/issues/new/choose)).

`transactionApi`

While Prisma already ships transactions within [nested writes](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/relation-queries#nested-writes), there are many use cases, where you might want to perform multiple _unrelated_ write operations in a transaction and rollback, if one of them fails. By wrapping your write operations in the new `transaction()` function, you can achieve exactly this!

(Note, that these transactions are not long-running and are executed directly after each other. This is an explicit design decision of Prisma. In case this does not cover your use case yet, please chime in on [GitHub](https://github.com/prisma/prisma-client-js/issues/742)).

Example

ts
//run inside `async` function
await prisma.transaction([
prisma.user.create({
data: {
email: "aliceprisma.io",
},
}),
prisma.user.create({
data: {
email: "bobprisma.io",
},
}),
])



Alternatively, you can store the unresolved promises in variables and pass these to the new `transaction` function:

ts
const userOperation1 = prisma.user.create({
data: {
email: "aliceprisma.io",
},
})

const userOperation2 = prisma.user.create({
data: {
email: "bobprisma.io",
},
})


//run inside `async` function
await prisma.transaction([userOperation1, userOperation2])



Feature flag

To enable the experimental transaction api, you can use the feature flag `transactionApi` in your Prisma schema file:

prisma
generator client {
provider = "prisma-client-js"
experimentalFeatures = ["transactionApi"]
}


Please leave feedback on how this feature works for you https://github.com/prisma/prisma-client-js/issues/667. We are interested in both positive and negative feedback, so we know if this feature is already ready for production. (If there are problems you can also open a new issue [here](https://github.com/prisma/prisma/issues/new/choose)).

Enabling experimental features in the Prisma CLI

In the Prisma CLI, we are using dedicated _experimental flags_ that can be added to any command.

Re-Introspection

One common problem when using Prisma is that manual changes to your Prisma schema are overwritten the next time you run `prisma introspect`. This version adds an experimental mode for this functionality where we try to keep some of these changes:

- [Custom names for relation fields](https://github.com/prisma/prisma/issues/2503)
- [`map` on models and enums](https://github.com/prisma/prisma/issues/2545)
- [`map` on fields and enum values](https://github.com/prisma/prisma/issues/2545)

You enable this by supplying the `--experimental-reintrospection` flag to `prisma introspect`:


npx prisma introspect --experimental-reintrospection


Please leave feedback on how this feature works for you https://github.com/prisma/prisma/issues/2829. We are interested in both positive and negative feedback, so we know if this feature is already ready for production. (If there are problems you can also open a new issue at [here](https://github.com/prisma/prisma/issues/new/choose)).


Fixes and improvements

`prisma`

- [Panic on a table that only has an ID, "called `Option::unwrap()` on a `None` value"](https://github.com/prisma/prisma/issues/1793)
- [.raw errors on date params w/ Postgres](https://github.com/prisma/prisma/issues/2533)
- [Improve error handling for incorrect raw parameters](https://github.com/prisma/prisma/issues/2561)
- [Parameter for `prisma init` to supply connection string to be used in `datasource`](https://github.com/prisma/prisma/issues/2577)
- [Configuration to disable update check and message](https://github.com/prisma/prisma/issues/2595)
- [queryRaw Error when calling SP or Function](https://github.com/prisma/prisma/issues/2679)
- [ENV var is required to execute `generate`/`validate`](https://github.com/prisma/prisma/issues/2686)
- [Tighten Version Check for P1 and P1.1 further](https://github.com/prisma/prisma/issues/2688)
- [Getting dbgenerated() for defaults on enums in Postgres](https://github.com/prisma/prisma/issues/2689)
- [`Environment variables loaded from` uses wrong directory separator (slashes) on Windows](https://github.com/prisma/prisma/issues/2699)
- [ENOENT when running prisma with pkg](https://github.com/prisma/prisma/issues/2717)
- [Statement caching for PostgreSQL](https://github.com/prisma/prisma/issues/2720)
- [CI Pipeline: Release stable release from chosen dev instead from current master state](https://github.com/prisma/prisma/issues/2724)
- [mixing uuid's with strings](https://github.com/prisma/prisma/issues/2784)
- [`prisma/debug` logs in tests](https://github.com/prisma/prisma/issues/2787)
- [Clean up `datasources` in Prisma Client constructor parameters](https://github.com/prisma/prisma/issues/2801)


`prisma-client-js`

- [create OR connect on nested writes (upsert)](https://github.com/prisma/prisma-client-js/issues/336)
- [Query batching & transactions support](https://github.com/prisma/prisma-client-js/issues/667)
- [Deeply nested creation never completes](https://github.com/prisma/prisma-client-js/issues/686)
- [Prisma DMMF `JsonFilter` input has no fields](https://github.com/prisma/prisma-client-js/issues/689)
- [Client, Engine version incorrect when overriding binary with Prisma client constructor](https://github.com/prisma/prisma-client-js/issues/696)
- [Adapt a more conflict resistant naming for Prisma client's types](https://github.com/prisma/prisma-client-js/issues/707)
- [JSON type throws error on certain types of valid JSON on `create` and `update`](https://github.com/prisma/prisma-client-js/issues/716)
- [Remove `__internal` from types](https://github.com/prisma/prisma-client-js/issues/729)


`vscode`

- [[Publishing] Send message to Slack channel on publish (success or failure)](https://github.com/prisma/vscode/issues/76)
- [Different README for unstable extension version](https://github.com/prisma/vscode/issues/119)
- [Notify Slack channel on extension publish](https://github.com/prisma/vscode/issues/160)
- [Trigger CI tests after bumping the version and before publishing](https://github.com/prisma/vscode/issues/197)
- [Remove `type_alias` from auto-completion ](https://github.com/prisma/vscode/issues/225)
- [Add auto-completion for env()](https://github.com/prisma/vscode/issues/226)
- [Cursor should stay inside [] for auto-completion](https://github.com/prisma/vscode/issues/228)
- [Autocompletion suggests block types after enum definition ](https://github.com/prisma/vscode/issues/231)
- [Auto-completion does not suggest block types when typing](https://github.com/prisma/vscode/issues/241)
- [Clean build before publish](https://github.com/prisma/vscode/issues/252)
- [Run integration tests on multiple platforms](https://github.com/prisma/vscode/issues/255)
- [Document "format on save" in READMEs](https://github.com/prisma/vscode/issues/259)
- [Add Prisma Version and Insider Version to Slack Notification Message](https://github.com/prisma/vscode/issues/260)


`studio`

- [Studio startup doesn't work (ENOENT)](https://github.com/prisma/studio/issues/415)


`prisma-engines`

- [Clarify CURRENT_TIMESTAMP support across MySQL versions](https://github.com/prisma/prisma-engines/issues/710)
- [Avoid relying on JSON database migrations backwards compatibility](https://github.com/prisma/prisma-engines/issues/741)
- [Introduce debugging mode to trigger panics in query engine](https://github.com/prisma/prisma-engines/issues/764)
- [Nested cursor-based pagination doesn't work as intended](https://github.com/prisma/prisma-engines/issues/768)
- [Move Windows build to GitHub Actions](https://github.com/prisma/prisma-engines/issues/811)

2.0.1

Today we release the first patch release `2.0.1`.
This is the first time that we run our new patch process! And it looks like everything went well 🤗.

Improvements
- The database detection in `prisma introspect` got improved so there are fewer false positives that tell users their database is Prisma 1.

2.0

| 1.X | `prisma` | `prisma1` | `prisma` | `prisma1` |

New syntax for defining relations

The Beta release introduces a new relation syntax which makes the **[`relation`](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/relations#the-relation-attribute) attribute required in each relation in the Prisma schema**. Note that it often is enough to only declare the attribute only on the side of the relation (the side that stores the _foreign key_ in the underlying database).

Additionally, for **one-to-one and one-to-many relations, you need add a [relation scalar field](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/relations#annotated-relation-fields-and-relation-scalar-fields) to the model which is used in the `relation` attribute.** This relation scalar field directly maps to the foreign key in the underlying database. Note that the foreign key is read-only in the Prisma Client API, to modify a relation you can keep using [nested write queries](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/relation-queries#nested-writes) as before.

Here's an overview for how relations need to be updated.

One-to-one

During the Preview period, a 1-1-relation could be defined as follows:

prisma
model User {
id Int id default(autoincrement())
profile Profile
}

model Profile {
id Int id default(autoincrement())
user User
}


With the new Beta, you now _must_ determine which side should store the foreign key. You can do so by adding the `relation` attribute with its corresponding relation scalar field to the model:

diff
model User {
id Int id default(autoincrement())
profile Profile
}

model Profile {
id Int id default(autoincrement())
+ user User relation(fields: [userId], references: [id])
+ userId Int // relation scalar field (used in the `relation` attribute above)
}


This Prisma schema is represented as follows in SQL (the foreign key is stored on `Profile`):

sql
CREATE TABLE "User" (
id SERIAL PRIMARY KEY
);
CREATE TABLE "Profile" (
id SERIAL PRIMARY KEY,
"userId" INTEGER NOT NULL UNIQUE,
FOREIGN KEY ("userId") REFERENCES "User"(id)
);


One-to-many

During the Preview period, a 1-n-relation could be defined as follows:

prisma
model User {
id Int id default(autoincrement())
posts Post[]
}

model Post {
id Int id default(autoincrement())
author User
}


With the new Beta, you now _must_ add the `relation` attribute and its corresponding relation scalar field to the non-list field of the relation:

diff
model User {
id Int id default(autoincrement())
posts Post[]
}

model Post {
id Int id default(autoincrement())
+ author User relation(fields: [authorId], references: [id])
+ authorId Int
}


This Prisma schema is represented as follows in SQL:

sql
CREATE TABLE "User" (
id SERIAL PRIMARY KEY
);
CREATE TABLE "Post" (
id SERIAL PRIMARY KEY,
"authorId" integer NOT NULL,
FOREIGN KEY ("authorId") REFERENCES "User"(id)
);


Many-to-many (implicit)

During the Preview period, a m-n-relation could be defined as follows:

prisma
model Post {
id Int id default(autoincrement())
categories Category[]
}

model Category {
id Int id default(autoincrement())
posts Post[]
}


With the new Beta, you now _must_ add the `relation` attribute to both sides of the relation:

diff
model Post {
id Int id default(autoincrement())
+ categories Category[] relation(references: [id])
}

model Category {
id Int id default(autoincrement())
+ posts Post[] relation(references: [id])
}


Prisma will maintain the relation with the following [relation table](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/relations#relation-tables):

sql
CREATE TABLE "Category" (
id SERIAL PRIMARY KEY
);
CREATE TABLE "Post" (
id SERIAL PRIMARY KEY
);
-- Relation table + indexes -------------------------------------------------------
CREATE TABLE "_CategoryToPost" (
"A" integer NOT NULL REFERENCES "Category"(id),
"B" integer NOT NULL REFERENCES "Post"(id)
);
CREATE UNIQUE INDEX "_CategoryToPost_AB_unique" ON "_CategoryToPost"("A" int4_ops,"B" int4_ops);
CREATE INDEX "_CategoryToPost_B_index" ON "_CategoryToPost"("B" int4_ops);


Why this change was introduced

The changes in the relation syntax were needed to enable more complex relation configurations, e.g. when using [multi-field IDs](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/data-model#ids).

Note that [we aim to simplify the current syntax](https://github.com/prisma/prisma2/issues/2018) in the future again ("take one step backward, to be able to move two steps forward").

The `prisma2` npm package is deprecated

The `prisma2` npm package is now deprecated, the Prisma 2.0 CLI can now be installed via the `prisma/cli` npm package, e.g.:


npm prisma/cli --save-dev
npx prisma


To prevent confusions during installation, it now outputs the following when you try to install it:


┌─────────────────────────────────────────────────────────────┐
│ │
│ The package prisma2 has been renamed to prisma/cli. │
│ │
│ Please uninstall prisma2 from your project or globally. │
│ Then install prisma/cli to continue using Prisma 2.0: │
│ │
│ Uninstall old CLI │
│ npm uninstall prisma2 │
│ │
│ Install new CLI │
│ npm install prisma/cli --save-dev │
│ │
│ Invoke via npx │
│ npx prisma --help │
│ │
│ Learn more here: https://pris.ly/preview025 │
│ │
└─────────────────────────────────────────────────────────────┘

2.0.0

🎉 Today, we are launching Prisma 2.0 for **General Availability**! Read the [announcement](https://www.prisma.io/blog/announcing-prisma-2-n0v98rzc8br1) to learn more.

---

Page 25 of 44

Links

Releases

Has known vulnerabilities

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.