yarn @prisma/client 2.0.0-preview022

latest releases: 5.23.0-dev.16, 5.23.0-dev.15, 5.23.0-dev.14...
4 years ago

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

This release contains breaking changes, be sure to read the notes below before upgrading!

Major improvements

  • Send raw SQL queries using prisma.raw(sql) (read the API docs)
  • Stopped shipping TypeScript with Prisma Client JS
  • Various introspection improvements
  • prisma2 init now uses environment variables and creates a .env file

Breaking changes

Remove pluralization of virtual back-relation fields

The following change is only breaking if you're using introspection and are currently using Prisma Client API calls that are referencing a virtual back-relation field. Read on to learn more.

When introspecting a table with a foreign key, Prisma automatically creates a "virtual back-relation" field on the respective Prisma model. Consider the following SQL schema:

CREATE TABLE User (
	user_id SERIAL PRIMARY KEY NOT NULL,
	name VARCHAR(256),
);

CREATE TABLE Post (
	post_id SERIAL PRIMARY KEY NOT NULL,
	title VARCHAR(256) NOT NULL,
	author_id INTEGER,
	FOREIGN KEY (author_id) REFERENCES User(user_id) 
);

In previous Prisma 2 preview versions, the resulting Prisma data model after introspection used to be:

model User {
	user_id Int     @id @default(autoincrement())
	posts   Post[]  // before `preview022`
}

model Post {
	post_id Int     @id @default(autoincrement())
	title   String
	author  User?
}

Notice the posts field which has been added by Prisma. This field does not exist as a column on the database-level, but is a "virtual back-relation" field in the Prisma schema.

With preview022, the pluralization of the virtual back-relation field has been removed. The new introspection result would be:

model User {
	user_id Int     @id @default(autoincrement())
	post    Post[]  // after `preview022`
}

model Post {
	post_id Int     @id @default(autoincrement())
	title   String
	author  User?
}

Path for default .env file changed

As explained in this issue, the path to the default .env file is changed in this Preview version. Before, the Prisma CLI automatically loaded the environment variables from a .env file in the current working directory. This now changes and it only loads them from the directory that contains the schema.prisma file.

Enums are now handled natively (Prisma Migrate)

Enums in the Prisma schema are now mapped to enums in the underlying database (previously they were represented as strings). This means enum support for SQLite is completely removed since SQLite doesn't support enums.

Fixes and improvements per Prisma 2 repository

prisma2

prisma-client-js

migrate

prisma-engines

Don't miss a new client release

NewReleases is sending notifications on new releases.