github prisma/prisma 2.12.0

latest releases: 5.13.0, 5.12.1, 5.12.0...
3 years ago

Today, we are excited to share the 2.12.0 stable release 🎉

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

Major improvements

Standalone Prisma Studio app for macOS

We have repackaged Prisma Studio to work also as a standalone macOS application. This should help you run Studio with just a double click and without opening your terminal, just in case you quickly want to browse or edit your data.

Download the installation files from the Studio release page. Support for more platforms (Windows and Linux) will come soon. Let us know if which one you would want first!

Prisma codemods help upgrading your codebase

With today's release, we took the opportunity to cleanup some rough edges in the Prisma Client API which partially results in breaking changes. To help you with upgrading your codebase to 2.12.0, we're introducing @prisma/codemods.

The @prisma/codemods package provides a powerful CLI that scans your codebase and automatically updates the code to the new API calls from the provided version.

The upgrade workflow looks like this:

cd my-app
npm install @prisma/cli @prisma/client
npx @prisma/codemods update-2.12 ./

Microsoft SQL Server now supports native database types (Preview)

Hot off the presses: You can now use database native types with Microsoft SQL Server! You'll need to specify both previewFeatures = ["microsoftSqlServer", "nativeTypes"] to get started:

generator js {
  provider        = "prisma-client-js"
  previewFeatures = ["microsoftSqlServer", "nativeTypes"]
}

datasource ms {
  provider = "sqlserver"
  url      = env("DATABASE_URL")
}

model User {
  id   BigInt  @id @default(autoincrement()) @ms.BigInt
  name String? @ms.VarChar(255)
}

model Post {
  id        BigInt @id @default(autoincrement()) @ms.BigInt
  title     String @ms.VarChar(100)
  views     BigInt @default(0) @ms.BigInt
  wordCount Int    @default(0) @ms.SmallInt
}

Note that Prisma Migrate does not yet work with Microsoft SQL Server, nor does Prisma Client Go.

Upcoming Prisma Migrate Preview Release

We’ve got a Preview release of Prisma Migrate nearing up with a large set of changes. You can test it in Early Access, see the upcoming changes, and provide feedback! Get started with the Early Access version here.

To join the conversation, join the #product-feedback channel on our Slack.

Breaking changes

As mentioned before, we're cleaning up the Prisma Client API which partially results in breaking changes. You can upgrade to the latest version using the new @prisma/codemods package as explained above.

Remove non-$ methods

A few months back, we began prefixing our top-level Prisma methods with $. For example, prisma.transaction became prisma.$transaction. We did this to avoid clashes with your application's model names.

The non-$ methods were deprecated but continued to work until this release. In this release, we removed the deprecated methods.

This means if you are still using calls like prisma.transaction or prisma.disconnect instead of prisma.$transaction or prisma.$disconnect in your code, your app is going to break after upgrading to 2.12.0.

The @prisma/codemods workflow describe above will automatically fix any remaining non-$ methods in your codebase.

You can read more about this change in on Github.

1-1-relations must now have an optional side

In this version, we're adding a new requirement for 1-1-relations that you define in your Prisma schema. In previous versions, it used to be allowed to have both sides of the relation required. As of this release, the virtual side of the relation (i.e. the side that does not store the foreign key in the underlying database) must be optional.

Before

model User {
  id      Int      @id @default(autoincrement())
  name    String?
  profile Profile  // ❌ this is not allowed as of 2.12.0
}

model Profile {
  id     Int    @id @default(autoincrement())
  user   User   @relation(fields: [userId], references: [id])
  userId Int
}

After

model User {
  id      Int      @id @default(autoincrement())
  profile Profile? // ✅ the virtual side of the relation needs to be optional
}

model Profile {
  id     Int    @id @default(autoincrement())
  user   User   @relation(fields: [userId], references: [id])
  userId Int
}

The easiest way to adjust your schema to these new requirements is by running the introspect command which will automatically make the virtual relation fields optional on 1-1-relations:

npx prisma introspect

Fix how data for Json[] fields is stored

We fixed how the Json[] type is stored in 2.12.0. Previously, we were storing JSON arrays as a string inside a your database's JSON column. Now, we properly encode JSON arrays as JSON in the database. This fix will allow us to add database native JSON operations down the line.

If you are using the Json[] type in your schema, you'll need to migrate your data. We anticipate this breaking change will only affect a handful of folks. Please reach out to us in this issue and we'll help you with the migration.

Here is an overview of how the behaviour changes in 2.12.0:

Given 2.11.0 2.12.0
[] [[]] []
[{test:"test"}] ["{\"test\":\"test\"}"] [{"test":"test"}]
[{ test: "test" }, { test: "test2" }] ["[{\"test\": \"test\"}, {\"test\": \"test2\"}]"] [{"test": "test"},{"test": "test2"}]
[3] 3 [3]

Deprecations

Rename findOne to findUnique

This release renames findOne to findUnique and deprecates findOne.

We made this change to reduce confusion. Many people expected findOne to be more loose, e.g: "Find the first record that matches my conditions.".

The @prisma/codemods workflow describe above will automatically rename findOne to findUnique across your codebase.

Move most types under the Prisma namespace

We moved most of the generated types under a new Prisma namespace and are deprecating the top-level exports. This change also resolves some existing namespace clashes.

Before

import { PrismaClient, User, UserCreateInput } from '@prisma/client'

async function createUser(input: UserCreateInput): Promise<User> {
  return prisma.user.create(input)
}

After

import { PrismaClient, User, Prisma } from '@prisma/client'

async function createUser(input: Prisma.UserCreateInput): Promise<User> {
  return prisma.user.create(input)
}

This means that with this release, there are exactly three kinds of exports in @prisma/client:

  1. PrismaClient is the constructor your Prisma Client instance
  2. Model types, e.g. User and Post
  3. Prisma as the new namespace under which you can now access the remaining generarted types

The @prisma/codemods workflow describe above will automatically fix the type names in your code!

With this change, we've greatly reduced the number of reserved words that could clash with your application's names. Go forth and add models with names like Transaction or Aggregate!

Fixes and improvements

prisma

prisma-client-js

migrate

language-tools

studio

prisma-engines

Credits

Huge thanks to @matt-eric, @muxahuk for helping!

Don't miss a new prisma release

NewReleases is sending notifications on new releases.