npm install prisma/client2.0.0-beta.1
npm install prisma/cli2.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:
diff
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`](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/data-model#mapping-column,-table-and-enum-names) 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](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/relation-queries#nested-writes).
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:
- The `prisma/prisma2` repository has been renamed to [`prisma/prisma`](https://github.com/prisma/prisma/)
- The `prisma/prisma` repository has been renamed to [`prisma/prisma1`](https://github.com/prisma/prisma1/)
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 |
| :------------- | :-------------- | :-------------- | :------------------- | :------------------- |