Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
APACHE-2.0 License
Published by timsuchanek over 4 years ago
Published by timsuchanek over 4 years ago
Published by timsuchanek almost 5 years ago
Published by nikolasburk almost 5 years ago
Today, we are issuing the twentieth Preview release: 2.0.0-preview020
(short: preview020
).
This release has a number of major and breaking changes, be sure to read the notes below before upgrading!
The most important changes are:
migrate
(formerly lift
) subcommands behind an --experimental
flagprisma2 dev
commandprisma2 init
wizardonDelete
has been removed from the @relation
attributeTo see how the changes affect an application, check out the updated examples.
⚠️ If you're using Prisma together with GraphQL Nexus and nexus-prisma
, check out the additional release notes of nexus-prisma
: https://github.com/prisma-labs/nexus-prisma/releases/tag/0.7.0
Aside from the renaming throughout all our content resources, this change is breaking the generator
definition in your Prisma schema. Instead of using photonjs
as the provider
of your generator, you now need to use prisma-client-js
:
generator client {
- provider = "photonjs"
+ provider = "prisma-client-js"
}
The Prisma Client's npm package has also been renamed. Instead of installing @prisma/photon
, you're now using @prisma/client
:
- npm install @prisma/photon
+ npm install @prisma/client
Finally, the way how you import Prisma Client in your code and instantiate it needs to be adjusted too:
- import { Photon } from '@prisma/photon'
+ import { PrismaClient } from '@prisma/client'
+ // const { PrismaClient } = require('@prisma/client')
- const photon = new Photon
+ const prisma = new PrismaClient()
Note that the former photonjs
repo is now called prisma-client-js
. We also removed the former Photon.js website on https://photonjs.prisma.io
and are redirecting it to these release notes.
We renamed Photon.js in an effort to make Prisma simpler. Instead of using abstract names for the Prisma tools, we've decided to use descriptive names for the different parts of Prisma to make it easier for newcomers to understand what each of our tools does.
--experimental
flagPrisma's lift
subcommand has been renamed to migrate
:
- prisma2 lift save
- prisma2 lift up
+ prisma2 migrate save
+ prisma2 migrate up
The initial launch of Prisma 2 in February will include only Prisma Client, but not yet Prisma's migration tooling. To anticipate this split, all migration-related functionality of the prisma2
CLI now requires an explicit opt-in via an --experimental
flag:
prisma2 migrate save --experimental
prisma2 migrate up --experimental
Note that the former lift
repo is now called migrate
. We also removed the former Lift website on https://lift.prisma.io
and are redirecting it to these release notes.
We renamed Lift in an effort to make Prisma simpler. Instead of using abstract names for the Prisma tools, we've decided to use descriptive names for the different parts of Prisma to make it easier for newcomers to understand what each of our tools does.
prisma2 dev
The prisma2 dev
command has been removed from the Prisma 2 CLI. If you want to automatically re-generate Prisma Client upon a schema change, you can now add the --watch
flag on the generate
command:
prisma2 generate --watch
The prisma2 dev
command was removed because it was using Prisma's migration functionality under the hood. Since migrations are considered experimental as of this release, we wanted to make sure that the main Prisma worfklows are not using them any more. Note that in the future we will provide an even better experience for developers who liked the quick turnaround time of prisma2 dev
.
prisma2 init
wizardThe prisma2 init
command has been simplified. It now only outputs a basic schema.prisma
file with some helpful comments that explain potential next steps. A typical "getting started" flow now looks as follows:
prisma2 init
to create an empty Prisma schema file.url
of the datasource
block inside the Prisma schema.prisma2 introspect
to test the connection and obtain your data model.prisma2 generate
to generate Prisma Client.You can then start using Prisma Client in your application:
import { PrismaClient } from 'prisma-client-js'
// or const { PrismaClient } = require('prisma-client-js')
const prisma = new PrismaClient()
Learn more in the updated "Getting Started"-guide.
If you want to get started with a new project instead of using an existing database, check out the available examples.
The interactive prisma2 init
wizard was a very ambitious command to support developers in setting up their Prisma-based projects. While it helped some developers get started with an initial setup, it also showed to be very complex, confusing and difficult to maintain.
We therefore decided to remove the wizard and opted for a simpler version of prisma2 init
that just sets up an initial Prisma schema file for you.
To improve the Prisma tools, we've created a new telemetry endpoint. This endpoint is pinged by the prisma2
CLI upon the invokation of any command. Note that after the endpoint got pinged once, the pinging is paused for 48 hours before the next ping is sent from a command invokation. Learn more about the new telemetry server and the data it's sending in the docs.
You can opt-out of this behavior by setting the CHECKPOINT_DISABLE
environment variable to 1
, e.g.:
export CHECKPOINT_DISABLE=1
onDelete
has been removed from the @relation
attributeWhile not causing an error, the onDelete
argument on the @relation
attribute didn't have any effect (i.e., it hadn't been implemented yet). To make the API surface simpler, we removed it from the Prisma schema for now.
We also decided to rename the Prisma Framework to Prisma 2 (or just "Prisma") again. The main reason for this is that many developers got confused about the term "framework" and misinterpreted it as a "web application framework" when it was supposed to refer to a "database framework". To prevent this confusion in the future, we decided to remove the "Framework"-part from its name.
As of now, we're still mainly referring to it as Prisma 2. After the initial launch in February, Prisma 2 will be referred to as just "Prisma".
prisma2
init
, Introspection: Tells me that schema is not empty, does not even exist thoughinit
: Starter Kit flows only show empty databasesinit
: Input is not disabled while connecting to databaseprisma2 generate
keeps downloading query engine (or at least tells me it does)init
: Back button is not workingprisma2 init
, first step is labeled "Languages for starter kits"init
: Wrong "Back" detailBlank project
-> ... -> Demo script
optionprisma2 init
navigation infinite loopprisma2 generate
tries to install @prisma/photon
even in folder without package.json
not found
page--url
?
is not accepted as character in column name(
is not accepted as character in column name-
is not accepted as character in column name/
is not accepted as character in column nameinit
dev
npm add
--help
to print help in prisma2 init
prisma-client-js
new Photon
in the lambda function context stops the engineorderBy: null
many query*GetSelectPayload
and *GetIncludePayload
utility typesmigrate
--help
argument to print help on prisma2 dev
prisma-engine
Published by nikolasburk almost 5 years ago
Today, we are issuing the nineteenth Preview release: 2.0.0-preview019
(short: preview019
). In case you've missed it, you can read about the current state of Prisma 2 on our blog.
This release has a number of breaking changes, be sure to read the notes below before upgrading!
You can find a full upgrade guide here.
Note that we recently adjusted the versioning schema in order to fully comply to the semver spec (the first release with the new version schema was 2.0.0-preview014
).
Prisma's scalar list support for MySQL and SQLite is removed in this version. For PostgreSQL, Prisma is now mapping scalar lists in the Prisma schema to PostgreSQL arrays.
Here is an example of a native scalar list (of type boolean
) in the Prisma schema:
model User {
id Int @id
name String @default("")
coinflips Boolean[]
}
You can find the workflows for upgrading Prisma for your database here.
Int
and String
consistentPreviously, the way how Prisma handled IDs was a bit inconsistent. For example, this was allowed:
model User {
id Int @id
}
But this wasn't:
model User {
id String @id
}
There was a difference in how Prisma handled IDs of type String
and type Int
.
In the first case, Prisma added the behaviour of auto-incrementing IDs (i.e. IDs received a default value), so it wasn't required to provide an id
value when new User
records were created via the generated Photon.js API.
The same User
model with id
field of type Int
now will not receive any default, auto-incrementing values for id
any more. Instead id
values must be explicitly provided when creating new User
records via Photon.js:
// Before, this was possible
const user = await photon.users.create()
// Now you need to provide an `id`
const user = await photon.users.create({
data: {
id: 42
}
})
In most cases, you'll want to retain the previous functionality though. To get this functionality, you need to add the @default(autoincrement())
to the id
field:
model User {
id Int @id @default(autoincrement())
}
@id
and @unique
on the same fieldPreviously it was possible to add @unique
attribute to a field that was already annotated with @id
:
model User {
id Int @id @unique
}
This is now forbidden since uniqueness is already implied by @id
:
model User {
id Int @id
}
This release contains a breaking change to the way how Lift stores the migration history. In order to use Lift with the newest version, you have to:
migrations
folder from the file system_Migrations
table, e.g. using TRUNCATE _Migration;
prisma2
lift up
not applying migrations to fresh database, whilst prisma2 dev
does?prisma2
commands could fail more gracefully when query and migration engine are not presentphotonjs
ctx.photon.posts.create()
invocationlift
prisma-engine
Published by timsuchanek almost 5 years ago
ctx.photon.posts.create()
invocationPublished by timsuchanek almost 5 years ago
Published by nikolasburk almost 5 years ago
Today, we are issuing the eighteenth Preview release: 2.0.0-preview018
(short: preview018
).
Note that we recently adjusted the versioning schema in order to fully comply to the semver spec (the first release with the new version schema was 2.0.0-preview014
).
We removed the prisma2 convert
command from the Prisma Framework CLI. If you're upgrading from Prisma 1 to the Prisma Framework, you can use introspection to generate your initial Prisma schema.
prisma2
prisma2 lift save
creates two new .db
files for SQLitephotonjs
lift
prisma-engine
Published by timsuchanek almost 5 years ago
Published by timsuchanek almost 5 years ago
As the last preview release Preview 17 introduced a lot of change with a lot of potential side effects, also a few small bugs got introduced.
These bugs are fixed by this patch.
The issues that got tackled by this patch:
Published by nikolasburk almost 5 years ago
Today, we are issuing the seventeenth Preview release: 2.0.0-preview017
(short: preview017
). Note that this release includes a major breaking change with respect to where Photon.js is being generated and how it's imported into your code. Read more below!
Note that we recently adjusted the versioning schema in order to fully comply to the semver spec (the first release with the new version schema was 2.0.0-preview014
).
With this release, we're implementing the facade package @prisma/photon
for Photon.js. This means, instead of generating Photon.js into node_modules/@generated/photon
, it is now being generated into node_modules/@prisma/photon
.
Furthermore, you now must add the @prisma/photon
package to your project dependencies:
npm install @prisma/photon
Consequently, the Photon
constructor is now imported from @prisma/photon
into your code:
- import { Photon } from '@generated/photon'
+ import { Photon } from '@prisma/photon'
Also note that the versions of @prisma/photon
and your prisma2
CLI installation must be the same! It is therefore recommended to add prisma2
as a development dependency to you project. Global installations of prisma2
are discouraged because it's more difficult to keep them in sync with individual projects.
You can add prisma2
as a development dependeency as follows:
npm install prisma2 --save-dev
You can now invoke this local prisma2
installation using npx
:
npx prisma2
If you're using the platforms
field on your Photon.js generator to explicitly specify a build target for the binaries that are used by Photon.js, you might need to update the naming of the binaries. Here's how the names have changed:
Before | After |
---|---|
windows |
windows |
darwin |
darwin |
linux-glibc-libssl1.0.1 |
debian-openssl-1.0.x |
linux-glibc-libssl1.0.2 |
debian-openssl-1.0.x |
linux-glibc-libssl1.1.0 |
debian-openssl-1.1.x |
linux-glibc-libssl1.1.1 |
debian-openssl-1.1.x |
If you're using a RHEL-based systems (Fedora, Centos, etc.), replace debian
with rhel
, e.g. rhel-openssl-1.1.x
.
You can learn more about this in the spec.
prisma2
postinstall
script of the prisma2
npm packagephotonjs
lift
prisma-engine
getDatabaseMetadata
and listDatabases
Published by timsuchanek almost 5 years ago
Published by timsuchanek almost 5 years ago
This release fixes a regression introduced in https://github.com/prisma/prisma2/releases/tag/2.0.0-preview016
Published by nikolasburk almost 5 years ago
Today, we are issuing the sixteenth Preview release: 2.0.0-preview016
(short: preview016
).
Note that we recently adjusted the versioning schema in order to fully comply to the semver spec (the first release with the new version schema was 2.0.0-preview014
).
Also a huge shoutout to @williamluke4 for his work on this PR: fix(Engine Commands) Pass JSON File to Query Engine 🙌
This release contains major improvements to Photon's query engine. The biggest improvement here is that we're lifting the limitation that the query engine is only able to process one request at a time. In practice, this means that the query engine request throughput vastly increases. We see this as a major step towards making Photon.js production-ready! 🎉
Due to a major refactoring in Lift's migration engine, your migrations are likely going to break if you upgrade to preview016
with an error similar to this: Error parsing the migration steps: Error("unknown field 'name', expected 'model'", line: 1, column: 59)
.
To get rid of this error, you'll need to manually delete the generated migrations
folder from your file system and drop the _Migration
table in your database.
prisma2
prisma2 init hello-prisma
on macOS mojaveprisma2 init
with a Starter Kitphotonjs
null
relationships is not possiblewhere
prisma-engine
Published by timsuchanek about 5 years ago
Today, we are issuing the fifteenth Preview release: 2.0.0-preview015
(short: preview015
).
Note that we recently adjusted the versioning schema in order to fully comply to the semver spec (the first release with the new version schema was 2.0.0-preview014
).
Lift now features an explicit UI that warns about destructive changes before performing a schema migration: (Right now column and table dropping are recognized)
DateTime
from the Prisma schema to Date
in JavaScriptAssume you have the following Prisma model:
model Post {
id String @default(cuid()) @id @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
}
The Photon.js generator now sets the types of the createdAt
and updatedAt
fields to Date
instead of string
:
export declare type Post = {
id: string;
createdAt: Date;
updatedAt: Date;
title: string;
}
findOne
doesn't throw any more but has optional return typeBased on this issue, we decided to adjust the Photon.js API for findOne
calls. Instead of throwing an exception when there is no record that meets the specified where
condition for a findOne
call, it now returns null
.
Assume again the same Prisma model as before:
model Post {
id String @default(cuid()) @id @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
}
So, in your application code you might want to adjust the catch
calls to explicit checks for null
:
Before
try {
const post = await photon.posts.findOne({
where: { id }
})
// ... do something with `post`
} catch(e) {
console.log(`Did not find record with ID: ${id}`)
}
After
const post = await photon.posts.findOne({
where: { id }
})
if (post === null) {
console.log(`Did not find record with ID: ${id}`)
return
}
// ... do something with `post`
prisma2
alpha.241
init
flow doesn't show instruction to navigate into new directoryprisma2 dev
: Asks to save changes into a migration file by running prisma2 lift save
but gives Everything up-to-date
in terminalprisma2 init
fails with Error: Can't find Python executable "python", you can set the PYTHON env variable.
photonjs
.count()
returns null
for empty tablesafter
argument in findMany method (Postgres)Field does not exist on enclosing type.
When using most filters (some, etc)lift
prisma-engine
Published by timsuchanek about 5 years ago
.count()
returns null
for empty tablesPublished by timsuchanek about 5 years ago
This patch release fixes a bug when using the native
binaryTarget
https://github.com/prisma/prisma2/issues/750
Published by nikolasburk about 5 years ago
Today, we are issuing the fourteenth Preview release: 2.0.0-preview014
(short: preview014
).
Note that we adjusted the versioning schema (from 2.0.0-preview-14
to 2.0.0-preview014
) in order to fully comply to the semver spec.
nexus-prisma
generator from the Prisma schemaIn version 2.0.0-preview014
, the nexus-prisma
generator is not available any more. When using nexus-prisma
, you can install it as an npm dependency, just like you do with other libraries. Find an updated example of how to using nexus-prisma
to build a GraphQL API here.
@relation
attributeIn previous releases, this used to be a valid schema:
model User {
id String @id @default(cuid())
marriedTo User?
spouseOf User?
}
In previous versions, it was inferred that both relation fields, marriedTo
and spouseOf
, would belong to the same relation, i.e. it was interpreted as follows:
model User {
id String @id @default(cuid())
marriedTo User? @relation("MarriedUsers")
spouseOf User? @relation("MarriedUsers")
}
From this release onwards, adding the @relation
attribute is required in order to disambiguate this relation.
platforms
field of generators in the schema has been renamed to binaryTargets
generator photon {
provider = "photonjs"
platforms = ["darwin"]
}
now becomes
generator photon {
provider = "photonjs"
binaryTargets = ["darwin"]
}
pinnedPlatform
is now an env varIf you want to specify the concrete binary target or a binary path for the query engine, you can use the PRISMA_QUERY_ENGINE_BINARY
env var. Just pass it in to the process running Photon.js and it will be picked up.
In order to also customize the Lift engine path, you can run the prisma2
cli while providing PRISMA_MIGRATION_ENGINE_BINARY
.
For this release, we have invested a lot into fixing bugs across the stack. Try it out yourself:
npm install -g prisma2
prisma2 init hello-world
Please share your feedback and report any issues you might encounter!
prisma2
2.0.0-preview-12
in package.json
prisma2 init
does not find ts-node
when using starter kit "GraphQL API (+ Auth)"photonjs
lift
studio
prisma-engine
Published by timsuchanek about 5 years ago
We changed the versioning scheme from 2.0.0-preview-xx.y
to 2.0.0-previewxx.y
, as otherwise commands like yarn upgrade
don't recognize the new versions, as semver couldn't parse our old version scheme.
Published by timsuchanek about 5 years ago