Skip to content

Releases: prisma/prisma

2.0.0-beta.9

08 Jun 15:23
Compare
Choose a tag to compare
2.0.0-beta.9 Pre-release
Pre-release

Today, we are issuing the ninth Beta release: 2.0.0-beta.9 (short: beta.9).

Enforcing arrays in OR

We used to allow this syntax:

  const orIncorrect = await prisma.post.findMany({
    orderBy: {
      id: 'asc'
    },
    where: {
      OR: {
        title: {
          equals: "Prisma makes databases easy"
        },
        authorId: {
          equals: 2
        }
      }
    }
  });

However, the thing that we want is this:

const orCorrect = await prisma.post.findMany({
   orderBy: {
     id: 'asc'
   },
   where: {
     OR: [{
       title: {
         equals: "Prisma makes databases easy"
       },
     }, {
       authorId: {
         equals: 2
       }
     }]
   }
 })

So only the array syntax makes sense, therefore we also only allow that from now on.

Fixes and improvements

prisma

prisma-client-js

vscode

prisma-engines

Credits

Huge thanks to @Sytten for helping!

2.0.0-beta.8

04 Jun 10:17
Compare
Choose a tag to compare
2.0.0-beta.8 Pre-release
Pre-release

Today, we are issuing the eighth Beta release: 2.0.0-beta.8 (short: beta.8).

Breaking change: Splitting .raw into .queryRaw and .executeRaw

When dealing with raw SQL queries, there are two things we care about - the "return payload", which is being calculated by the SELECT statement we use and the number of affected rows - if we for example do an UPDATE query.

Until now, Prisma Client decided under the hood with a heuristic, when to return the number of affected rows and when to return the result data.
This heuristic broke if you wanted the opposite of what the heuristic returned.
That means that the decision has to be made by the developer using Prisma Client instead.
Therefore, we remove the raw command and replace it with executeRaw and queryRaw.

So what does return what?

  • executeRaw returns the number of affected rows
  • queryRaw returns the result data

The heuristic used to return the data for SELECT statements. So if you upgrade to Beta 8, you need to use queryRaw for your SELECT statements and executeRaw for all SQL queries, which mutate data.

The rule of thumb is: Do not use executeRaw for queries that return rows.
In Postgres, it will work to use executeRaw('SELECT 1), however, SQLite will not allow that.

Fixes and improvements

prisma

prisma-client-js

Credits

Huge thanks to @Sytten, @merelinguist for helping!

2.0.0-beta.7

29 May 16:32
Compare
Choose a tag to compare
2.0.0-beta.7 Pre-release
Pre-release

Today, we are issuing the seventh Beta release: 2.0.0-beta.7 (short: beta.7).

New Pagination

Prisma Client's pagination has been simplified a lot!

  • Removed first, last, before, after arguments.
  • Added cursor and take arguments.
  • skip argument unchanged.

The take argument replaces first and last.

Examples

first

prisma.user.findMany({
  first: 10
})

// becomes
prisma.user.findMany({
  take: 10
})

last

prisma.user.findMany({
  last: 10
})

// becomes
prisma.user.findMany({
  take: -10
})

before

prisma.user.findMany({
  before: "someid"
  first: 10
})

// becomes
prisma.user.findMany({
  cursor: "someid"
  take: -10
  skip: 1
})

after

prisma.user.findMany({
  after: "someid"
  first: 10
})

// becomes
prisma.user.findMany({
  cursor: "someid"
  take: 10
  skip: 1
})

The record specified with cursor is now included in the results, making skip: 1 necessary if you want to preserve the previous before / after semantics.

This diagram illustrates how the pagination works:

             cursor: 5                              
             skip: 0 or undefined                   
                       │                            
                       │                            
                       │                            
                       ▼                            
 ┌───┐┌───┐┌───┐┏━━━┓┏━━━┓┌───┐┌───┐┌───┐┌───┐┌───┐ 
 │ 1 ││ 2 ││ 3 │┃ 4 ┃┃ 5 ┃│ 6 ││ 7 ││ 8 ││ 9 ││10 │ 
 └───┘└───┘└───┘┗━━━┛┗━━━┛└───┘└───┘└───┘└───┘└───┘ 
                ◀────────                           
                 take: -2                           
                                                    
                                                    
                                                    
                    cursor: 5                       
                     skip: 1                        
                        │                           
                        │                           
                        │                           
                        ▼                           
  ┌───┐┌───┐┏━━━┓┏━━━┓┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐
  │ 1 ││ 2 │┃ 3 ┃┃ 4 ┃│ 5 ││ 6 ││ 7 ││ 8 ││ 9 ││10 │
  └───┘└───┘┗━━━┛┗━━━┛└───┘└───┘└───┘└───┘└───┘└───┘
                 ◀────────                          
                  take: -2                          
                                                    
                                                    
                                                    
                    cursor: 5                       
                     skip: 2                        
                        │                           
                        │                           
                        │                           
                        ▼                           
  ┌───┐┏━━━┓┏━━━┓┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐
  │ 1 │┃ 2 ┃┃ 3 ┃│ 4 ││ 5 ││ 6 ││ 7 ││ 8 ││ 9 ││10 │
  └───┘┗━━━┛┗━━━┛└───┘└───┘└───┘└───┘└───┘└───┘└───┘
                 ◀────────                          
                  take: -2                          
                                                    
                                                    
            cursor: 5                               
            skip: 0 or undefined                    
                      │                             
                      │                             
                      │                             
                      ▼                             
┌───┐┌───┐┌───┐┌───┐┏━━━┓┏━━━┓┏━━━┓┌───┐┌───┐┌───┐  
│ 1 ││ 2 ││ 3 ││ 4 │┃ 5 ┃┃ 6 ┃┃ 7 ┃│ 8 ││ 9 ││10 │  
└───┘└───┘└───┘└───┘┗━━━┛┗━━━┛┗━━━┛└───┘└───┘└───┘  
                      ──────────▶                   
                        take: 3                     
                                                    
                                                    
                  cursor: 5                         
                  skip: 1                           
                      │                             
                      │                             
                      │                             
                      ▼                             
┌───┐┌───┐┌───┐┌───┐┌───┐┏━━━┓┏━━━┓┏━━━┓┌───┐┌───┐  
│ 1 ││ 2 ││ 3 ││ 4 ││ 5 │┃ 6 ┃┃ 7 ┃┃ 8 ┃│ 9 ││10 │  
└───┘└───┘└───┘└───┘└───┘┗━━━┛┗━━━┛┗━━━┛└───┘└───┘  
                      ──────────▶                   
                        take: 3                     
                                                    
                                                    
                  cursor: 5                         
                  skip: 2                           
                      │                             
                      │                             
                      │                             
                      ▼                             
┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐┏━━━┓┏━━━┓┏━━━┓┌───┐  
│ 1 ││ 2 ││ 3 ││ 4 ││ 5 ││ 6 │┃ 7 ┃┃ 8 ┃┃ 9 ┃│10 │  
└───┘└───┘└───┘└───┘└───┘└───┘┗━━━┛┗━━━┛┗━━━┛└───┘  
                      ──────────▶                   
                        take: 3                     

Auto restart on panic

The Query Engine now automatically restarts with an exponential backoff with jitter, if it exits for some reason, for example in the case of a panic. That helps a lot to make Prisma Client more resilient in production!
#2100

Introspection now recognizes @default(cuid / uuid)

If you introspect a Prisma 1 schema, the introspection now correctly recognizes cuid or uuid usage
#2499

Fixes and improvements

prisma

prisma-client-js

vscode

prisma-engines

Credits

Huge thanks to @Sytten, @thankwsx, @zachasme for helping!

2.0.0-beta.6

26 May 10:21
Compare
Choose a tag to compare
2.0.0-beta.6 Pre-release
Pre-release

Today, we are issuing the sixth Beta release: 2.0.0-beta.6 (short: beta.6).

More powerful raw queries with Prisma Client

Thanks to @zachasme and @Sytten, the prisma.raw command became more powerful in #2311. There are two changes we introduce for raw:

Expose sql-template-tag helpers

Prisma Client's raw mode utilizes the sql-template-tag library. In order to construct raw SQL queries programmatically, Prisma Client now exposes a few helper functions:

import { sql, empty, join, raw, PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

const rawQueryTemplateFromSqlTemplate = await prisma.raw(
  sql`
    SELECT ${join([raw('email'), raw('id'), raw('name')])}
    FROM ${raw('User')}
    ${sql`WHERE name = ${'Alice'}`}
    ${empty}
  `
)

Allowing programmatic positional parameters

Sometimes, a static template string is not enough. Then constructing a string dynamically is the right choice. For this situation, we added support for arbitrary positional parameters:

const result = await prisma.raw(
  'SELECT * FROM User WHERE id = $1 OR email = $2;',
  1,
  'e@ma.il'
)

Other improvements

  • You can now enable pgBouncer in your connection URL by adding the ?pgbouncer=true parameter (forceTransactions from the PrismaClient is now deprecated and will be removed in an upcoming release)
  • Improved handling of comments in prisma format
  • Various improvements to Prisma's VS Code extension (e.g. better error messages and debug information)

Fixes and improvements

prisma

prisma-client-js

vscode

prisma-engines

Credits

Huge thanks to @Sytten, @thankwsx, @zachasme for helping!

2.0.0-beta.5

12 May 09:42
Compare
Choose a tag to compare
2.0.0-beta.5 Pre-release
Pre-release

Today, we are issuing the fifth Beta release: 2.0.0-beta.5 (short: beta.5).

Major improvements

Support for Alpine Linux

From now on, you don't need to build your own binaries for Alpine Linux and all musl-based distros anymore. They're shipped by default with the Prisma CLI and Prisma Client.

Support for Node v14

The new Node v14 is from now on fully supported with the Prisma CLI and Prisma Client.

Fixed issues with JSON support in Prisma Client

You can now use the new Json type that was introduced in the last release also in Prisma Client.

Fixes and improvements

prisma

prisma-client-js

migrate

vscode

prisma-engines

Credits

Huge thanks to @Sytten for helping!

2.0.0-beta.4

30 Apr 14:38
Compare
Choose a tag to compare
2.0.0-beta.4 Pre-release
Pre-release

Today, we are issuing the fourth Beta release: 2.0.0-beta.4 (short: beta.4).

Major improvements

Support for JSON types in PostgreSQL and MySQL

Prisma now supports working with JSON data with the new Json type in the Prisma data model.

Here's an overview of how it works with different Prisma tools/workflows:

Introspection

The prisma introspect command maps the following column types to Json:

  • Postgres: JSON and JSONB
  • MySQL: JSON

Prisma Migrate

prisma migrate uses the following data type when creating a column for a field of type Json:

  • Postgres: JSONB
  • MySQL: JSON

Prisma Client

Fields of type Json will be exposed as plain JavaScript objects in the Prisma Client API.

Introducing prisma format

From now on, you can run prisma format in your project, to make your schema.prisma pretty without the VSCode extension 💅

Support for Yarn workspaces

Prisma now supports Yarn workspaces 🎉

Making Prisma Client generation more robust with .prisma folder

The generation of Prisma Client into node_modules sometimes caused problems with package managers (e.g. Yarn) which would occasionally delete the generated code.

In order to make the generation more robust, Prisma Client is now generated into a folder called node_modules/.prisma. Because of the leading dot in the folder name, package managers do not touch the folder any more. This results in the following folder structure:

node_modules/
 ↪ .prisma
   ↪ client
     ↪ schema.prisma
     ↪ index.js
     ↪ index.d.ts
     ↪ query-engine-darwin
 ↪ @prisma/client (imports the generated code from `.prisma`)

Note that the generated Prisma Client code in .prisma is now imported into @prisma/client which means there is no change for how you import and use Prisma Client in your code! You can still import Prisma Client as before with:

import { PrismaClient } from '@prisma/client'

Open Prisma Studio in specific browser

The prisma studio --experimental command now accepts a --browser option to let you choose your preferred browser for Prisma Studio, e.g.:

prisma studio --browser "Google Chrome" --experimental

Here's an overview of the browser names you can use per platform (note that double quotes are required when the browser name contains space and the right capitalization is required too):

OS Browser Argument for --browser
Mac OS Chrome "Google Chrome"
Firefox "Firefox"
Firefox (Developer) "Firefox Developer Edition"
Safari "Safari"
Windows Chrome "Google Chrome"
Firefox "Firefox"
Firefox (Developer) "Firefox Developer Edition"
Brave "Brave"
Linux Chrome "google-chrome"
Firefox "firefox"
Firefox (Developer) "firefox-developer-edition"
Brave "brave"

Fixes and improvements

prisma

prisma-client-js

migrate

vscode

Credits

Huge thanks to @Sytten for helping!

2.0.0-beta.3

21 Apr 14:40
8d00f9f
Compare
Choose a tag to compare
2.0.0-beta.3 Pre-release
Pre-release

Today, we are issuing the third Beta release: 2.0.0-beta.3 (short: beta.3).

Major changes

  • Enums are now disallowed for SQLite
  • Required 1-1 self relations are forbidden now
  • The prisma2 command is now deprecated in favor of prisma

Fixes and improvements

prisma

prisma-client-js

migrate

vscode

2.0.0-beta.2

08 Apr 15:54
852d4aa
Compare
Choose a tag to compare
2.0.0-beta.2 Pre-release
Pre-release

Today, we are issuing the second Beta release: 2.0.0-beta.2 (short: beta.2).

We want to give a huge shoutout to @Sytten who helped us fix some issues in the Rust codebase 🎊

Major improvements

Parametrized count queries in Prisma Client

In previous versions of Prisma Client, it was not possible to provide any filter arguments when using .count. With this release, you can provide the same filter arguments from findMany:

const numberOfUsersCalledBob = await prisma.user.count({ where: { name: 'Bob' }})

Lots of bug fixes and improvements

With this release, we were able to fix a lot of nasty bugs like some schema validation issues in VS Code (#1989 and #1970) as well as a Prisma Migrate bug with 1-n self-relations.

Fixes and improvements per Prisma 2.0 repository

prisma

prisma-client-js

prisma-engines

migrate

2.0.0-beta.1

31 Mar 10:08
Compare
Choose a tag to compare
2.0.0-beta.1 Pre-release
Pre-release

We are extremely excited to launch the first official Beta of Prisma 2.0 today! 🎉 Along with this release, we have also published a new website and an updated Prisma 2.0 documentation. This makes Prisma 2.0 the default for developers who are getting started with Prisma.

Upgrading to the new relation syntax

If you have been using Prisma Migrate before to create your models and their relations, the new relation syntax can seem a bit counterintuitive at first. Here's a quick overview of the most important things to consider when upgrading.

Note that this only covers one-to-one and one-to-many relations. Prisma's implicit many-to-many relations are adjusted by manually adding the @relation attribute with a single field reference to both sides of the relation (most often this looks as follows: @relation(references: [id])).

Consider this sample schema from preview025:

model User {
  id      Int      @id @default(autoincrement())
  profile Profile?
  posts   Post[]
}

model Profile {
  id   Int  @id @default(autoincrement())
  user User // backed up by a foreign key called `user` in the DB   
}

model Post {
  id     Int  @id @default(autoincrement())
  author User // backed up by a foreign key called `author` in the DB   
}
Expand for the corresponding SQL
CREATE TABLE "User" (
    id integer PRIMARY KEY,
    name text NOT NULL DEFAULT ''::text
);

CREATE TABLE "Profile" (
    bio text NOT NULL DEFAULT ''::text,
    id integer PRIMARY KEY,
    user integer NOT NULL,
    FOREIGN KEY ("user") REFERENCES "User"(id)
);

CREATE TABLE "Post" (
    id integer PRIMARY KEY,
    title text NOT NULL
    author integer NOT NULL,
    FOREIGN KEY ("author") REFERENCES "User"(id)
);

Note that in this case, the foreign keys in the underlying database are located on the Profile and Post tables. The User table does not have any foreign keys (which means the profile and posts relation fields on the User model are virtually maintained by Prisma).

The new syntax requires you to make the foreign key explicit in the Prisma schema (so you need to add another field in addition to the already existing relation field). This new field is your relation scalar field and directly represents the foreign key in the underlying database.

Assume you're now upgrading to 2.0.0-beta.1:

npm install @prisma/client@2.0.0-beta.1
npm install @prisma/cli@2.0.0-beta.1 --save-dev

Without touching the database, one way to adjust your Prisma schema to adhere to the new syntax would be as follows:

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     @map("user") // relation scalar field (used in the `@relation` attribute above)
}

model Post {
  id         Int         @id @default(autoincrement())
  author     User        @relation(fields: [authorId], references: [id])
+ authorId   Int         @map("author") // relation scalar field  (used in the `@relation` attribute above)
}

In this code, you introduced the userId and authorId fields on Profile and Post. These fields are your relation scalar fields and represent the foreign key in your database. But because the current foreign keys in the database are called user and author and therefore don't map directly to the model fields, you need to annotate the fields with @map to "map" them to a differently named database column.

You can then re-generate Prisma Client. Note that the prisma2 command has been renamed to prisma in 2.0.0-beta.1, so you need to invoke the generate command as follows:

npx prisma generate

Note that the new relation scalar field is currently read-only in the generated Prisma Client API. To modify the connections in youe database, you can keep using Prisma Client's nested write queries.

Breaking changes

No more Preview releases

With this release the Preview period for Prisma 2.0 ends. This means that releases will not be tagged preview any more, but with beta. Today's release is called: 2.0.0-beta.1.

Restructuring GitHub repositories

Since its initial release, the main repository for Prisma 2.0 has been called prisma2.

Because Prisma 2.0 is now the default for developers getting started with Prisma, the Prisma repositories have been renamed as follows:

Renaming the prisma2 CLI

During the Preview period, the CLI for Prisma 2.0 was invoked using the prisma2 command. With Prisma 2.0 being the default for new developers getting started with Prisma, the command is changed to just prisma. The exising prisma command of Prisma 1 is renamed to prisma1.

Also note that the installation of the npm packages changes:

Prisma version Old CLI command New CLI command Old npm package name New npm package name
2.0 prisma2 prisma prisma2 @prisma/cli
1.X prisma prisma1 prisma prisma1

New syntax for defining relations

The Beta release introduces a new relation syntax which makes the @relation 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 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 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:

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:

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):

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:

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:

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:

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:

Read more

2.0.0-preview025

27 Mar 12:36
d2741f4
Compare
Choose a tag to compare
2.0.0-preview025 Pre-release
Pre-release

Today, we are issuing the twenty-fifth Preview release: 2.0.0-preview025 (short: preview025).

Breaking changes

Renaming the prisma2 npm package

With this release, we're renaming the Prisma 2 CLI npm package from prisma2 to @prisma/cli. Note that you can still invoke the CLI using the prisma2 command!

To upgrade, you first should uninstall the current prisma2 version and then install the @prisma/cli package.

Local installation (recommended)

The local installation is generally preferred since it prevents conflicting versions of the same package.

# Uninstall current `prisma2` CLI (`preview024` or earlier)
npm uninstall prisma2

# Install new `prisma2` CLI via `@prisma/cli` npm package
npm install @prisma/cli --save-dev

# Invoke the CLI via `npx`
npx prisma2

Global installation

# Uninstall current `prisma2` CLI (`preview024` or earlier)
npm uninstall -g prisma2

# Install new `prisma2` CLI via `@prisma/cli` npm package
npm install -g @prisma/cli

# Invoke the CLI via `npx`
npx prisma2

Other

  • The prisma2 --version output changed
  • Virtual relation fields (aka “back-relation fields”) follow the same name as the model they relate to during introspection
  • The default for errorFormat in the PrismaClient constructor now is colorless

Fixes and improvements per Prisma 2 repository

prisma2

prisma-client-js

prisma-engines

Read more