Prisma: 4.3.0 Release

Release date:
August 30, 2022
Previous version:
4.2.1 (released August 10, 2022)
Magnitude:
6,890 Diff Delta
Contributors:
13 total committers
Data confidence:
Commits:

88 Commits in this Release

Ordered by the degree to which they evolved the repo in this version.

Authored August 17, 2022
Authored August 26, 2022
Authored August 11, 2022
Authored August 25, 2022
Authored August 26, 2022
Authored August 17, 2022
Authored August 17, 2022
Authored August 17, 2022
Authored August 19, 2022

Top Contributors in 4.3.0

SevInf
jkomyno
renovate-bot
Jolg42
danstarns
millsp
nikolasburk
mavilein
kt3k
prisma-bot

Directory Browser for 4.3.0

All files are compared to previous version, 4.2.1. Click here to browse diffs between other versions.

Loading File Browser...

Release Notes Published

🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟

Major improvements

Field reference support on query filters (Preview)

We're excited to announce Preview support for field references. You can enable it with the fieldReference Preview feature flag.

Field references will allow you to compare columns against other columns. For example, given the following schema:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["fieldReference"]
}

model Invoice {
  id     Int @id @default(autoincrement)
  paid   Int
  due    Int
}

You can now compare one column with another after running prisma generate, for example:

// Filter all invoices that haven't been paid yet
await prisma.invoice.findMany({
  where: {
    paid: {
      lt: prisma.invoice.fields.due // paid < due
    }
  }
})

Learn more about field references in our documentation. Try it out and let us know what you think in this GitHub issue.

Count by filtered relation (Preview)

In this release, we're adding support for the ability to count by a filtered relation. You can enable this feature by adding the filteredRelationCount Preview feature flag.

Given the following Prisma schema: ```prisma generator client { provider = "prisma-client-js" previewFeatures = ["filteredRelationCount"] }

model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] }

model Post { id Int @id @default(autoincrement()) title String content String? published Boolean @default(false)

author User? @relation(fields: [authorId], references: [id]) authorId Int? } ```

You can now express the following query with the Preview feature after re-generating Prisma Client: ts // Count all published user posts await prisma.user.findMany({ select: { _count: { posts: { where: { published: true } }, }, }, })

Learn more in our documentation and let us know what you think in this issue

Multi-schema support (Preview)

In this release, we're adding very early Preview support of multi-schema support for PostgreSQL and SQL Server behind the multiSchema Preview feature flag. With it, you can write a Prisma schema that accesses models across multiple schemas.

Read further in this GitHub issue. Try it out and let us know what you think in this GitHub issue.

Prisma CLI exit code fixes

We've made several improvements to the Prisma CLI:

  • prisma migrate dev previously returned a successful exit code (0) when prisma db seed was triggered but failed due to an error. We've fixed this and prisma migrate dev will now exit with an unsuccessful exit code (1) when seeding fails.

  • prisma migrate status previously returned a successful exit code (0) in unexpected cases. The command will now exit with an unsuccessful exit code (1) if:

    • An error occurs
    • There's a failed or unapplied migration
    • The migration history diverges from the local migration history (/prisma/migrations folder)
    • Prisma Migrate does not manage the database' migration history
  • The previous behavior when canceling a prompt by pressing <kbd>Ctrl</kbd> + <kbd>C</kbd> was returning a successful exit code (0). It now returns a non-successful, SIGINT, exit code (130).

  • In the rare event of a Rust panic from the Prisma engine, the CLI now asks you to submit an error report and exit the process with a non-successful exit code (1). Prisma previously ended the process with a successful exit code (0).

Improved precision for the tracing Preview feature

Before this release, you may have occasionally seen some traces that took 0μs working with the tracing Preview feature. In this release, we've increased the precision to ensure you get accurate traces.

Let us know if you run into any issues in this GitHub issue.

prisma format now uses a Wasm module

Initially, the prisma format command relied on logic from the Prisma engines in form of a native binary. In an ongoing effort to make prisma more portable and easier to maintain, we decided to shift to a Wasm module.

prisma format now uses the same Wasm module as the one the Prisma language server uses, i.e. @prisma/prisma-fmt-wasm, which is now visible in prisma version command's output.

Let us know what you think. In case you run into any issues, let us know by creating a GitHub issue.

MongoDB query fixes

⚠️ This may affect your query results if you relied on this buggy behavior in your application.

While implementing field reference support, we noticed a few correctness bugs in our MongoDB connector that we fixed along the way: 1. mode: insensitive alphanumeric comparisons (e.g. “a” > “Z”) didn’t work (GitHub issue) 2. mode: insensitive didn’t exclude undefined (GitHub issue) 3. isEmpty: false on lists types (e.g. String[]) returned true when a list is empty (GitHub issue) 4. hasEvery on list types wasn’t aligned with the SQL implementations (GitHub issue)

JSON filter query fixes

⚠️ This may affect your query results if you relied on this buggy behavior in your application. We also noticed a few correctness bugs in when filtering JSON values when used in combination with the NOT condition. For example:

await prisma.log.findMany({
  where: {
    NOT: {
      meta: {
        string_contains: "GET"
      }
    }
  }
})

<details>

<summary>Prisma schema</summary>

model Log {
  id      String @id @default(autoincrement())
  level   Level
  message String
  meta    Json
}

enum Level {
  Info
  Warn
  Error
}

</details>

If you used NOT with any of the following queries on a Json field, double-check your queries to ensure they're returning the correct data:

  • string_contains
  • string_starts_with
  • string_ends_with
  • array_contains
  • array_starts_with
  • array_ends_with
  • gt/gte/lt/lte

Prisma extension for VS Code improvements

The Prisma language server now provides Symbols in VS Code. This means you can now: - See the different blocks (datasource, generator, model, enum, and type) of your Prisma schema in the Outline view. This makes it easier to navigate to a block in 1 click A few things to note about the improvement are that: - <kbd>CMD</kbd> + hover on a field whose type is an enum will show the block in a popup - <kbd>CMD</kbd> + left click on a field whose type is a model or enum will take you to its definition.

<img alt="" src="https://user-images.githubusercontent.com/33921841/187421410-cd1f30cf-d0b4-4147-9467-70ca4da12321.png">

  • Enable Editor sticky scroll from version 1.70 of VS Code. This means you can have sticky blocks in your Prisma schema, improving your experience when working with big schema files

Make sure to update your VS Code application to 1.70, and the Prisma extension to 4.3.0.

We'd also like to give a big Thank you to @yume-chan for your contribution!

Prisma Studio improvements

We've made several improvements to the filter panel which includes: - Refined filter panel - Reducing the contrast of the panel in dark mode - Ability to toggle filters in the panel

  • Refined error handling for MongoDB m-n relations Prisma Studio prevents fatal errors when interacting with m-n relations by explicitly disabling creating, deleting, or editing records for m-n relations

  • Multi-row copying You can select multiple rows and copy them to your clipboard as JSON objects using <kbd>CMD</kbd> + <kbd>C</kbd> on MacOS or <kbd>Ctrl</kbd> + <kbd>C</kbd> on Windows/ Linux

Prisma Client Extensions: request for comments

For the last couple of months, we've been working on a specification for an upcoming feature — Prisma Client extensions. We're now ready to share our proposed design and we would appreciate your feedback.

Prisma Client Extensions aims to provide a type-safe way to extend your existing Prisma Client instance. With Prisma Client Extensions you can: - Define computed fields - Define methods for your models - Extend your queries - Exclude fields from a model ... and much more!

Here’s a glimpse at how that will look:

const prisma = new PrismaClient().$extend({
  $result: {
    User: {
      fullName: (user) => {
        return `${user.firstName} ${user.lastName}`
      },
    },
  },
  $model: {
    User: {
      signup: async ({ firstName, lastName, email, password }) => {
        // validate and create the user here
        return prisma.user.create({ 
          data: { firstName, lastName, email, password }
        })
      },
    },
  },
})

const user = await prisma.user.signup({
  firstName: "Alice", 
  lastName: "Lemon", 
  email: "[email protected]", 
  password: "pri$mar0ckz"
})
console.log(user.fullName) // Alice Lemon

For further details, refer to this GitHub issue. Have a read and let us know what you think!

Fixes and improvements

Prisma Client

Prisma

Prisma Migrate

Language tools (e.g. VS Code)

Credits

Huge thanks to @abenhamdine, @drzamich, @AndrewSouthpaw, @kt3k, @lodi-g, @Gnucki, @apriil15, @givensuman for helping!

Prisma Data Platform

We're working on the Prisma Data Platform — a collaborative environment for connecting apps to databases. It includes the: - Data Browser for navigating, editing, and querying data - Data Proxy for your database's persistent, reliable, and scalable connection pooling. - Query Console for experimenting with queries

Try it out and let us know what you think!

💼 We're hiring!

If you're interested in joining our growing team to help empower developers to build data-intensive applications, Prisma is the place for you.

We're looking for a Developer Advocate (Frontend / Fullstack) and Back-end Engineer: Prisma Data Platform.

Feel free to read the job descriptions and apply using the links provided.

📺 Join us for another "What's new in Prisma" livestream

Learn about the latest release and other news from the Prisma community by joining us for another "What's new in Prisma" livestream.

The stream takes place on YouTube on Thursday, August 11 at 5 pm Berlin | 8 am San Francisco.