From 1db2377fc70deef152421ffd6bdc2bcd5e1e552b Mon Sep 17 00:00:00 2001 From: ruheni Date: Wed, 26 Apr 2023 08:50:50 +0200 Subject: [PATCH 01/13] chore: remove `$` from prisma studio startup --- .../110-relational-databases/300-next-steps.mdx | 2 +- .../100-start-from-scratch/120-mongodb/300-next-steps.mdx | 2 +- .../110-relational-databases/300-next-steps.mdx | 2 +- .../200-add-to-existing-project/120-mongodb/300-next-steps.mdx | 2 +- content/200-concepts/100-components/06-prisma-studio.mdx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/300-next-steps.mdx b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/300-next-steps.mdx index df950b7818..6475f3dc87 100644 --- a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/300-next-steps.mdx +++ b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/300-next-steps.mdx @@ -71,7 +71,7 @@ const deletedUser = await prisma.user.delete({ ### Explore the data in Prisma Studio -Prisma Studio is a visual editor for the data in your database. Run `$ npx prisma studio` in your terminal. +Prisma Studio is a visual editor for the data in your database. Run `npx prisma studio` in your terminal. ### Try a Prisma example diff --git a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/300-next-steps.mdx b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/300-next-steps.mdx index 41467f1ed1..0333f41319 100644 --- a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/300-next-steps.mdx +++ b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/300-next-steps.mdx @@ -73,7 +73,7 @@ const deletedUser = await prisma.user.delete({ ### Explore the data in Prisma Studio -Prisma Studio is a visual editor for the data in your database. Run `$ npx prisma studio` in your terminal. +Prisma Studio is a visual editor for the data in your database. Run `npx prisma studio` in your terminal. ### Try a Prisma example diff --git a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/300-next-steps.mdx b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/300-next-steps.mdx index 68ad7e8fba..531c2f9065 100644 --- a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/300-next-steps.mdx +++ b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/300-next-steps.mdx @@ -74,7 +74,7 @@ const deletedUser = await prisma.user.delete({ ### Explore the data in Prisma Studio -Prisma Studio is a visual editor for the data in your database. Run `$ npx prisma studio` in your terminal. +Prisma Studio is a visual editor for the data in your database. Run `npx prisma studio` in your terminal. ### Change the database schema (e.g. add more tables) diff --git a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/120-mongodb/300-next-steps.mdx b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/120-mongodb/300-next-steps.mdx index 41467f1ed1..0333f41319 100644 --- a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/120-mongodb/300-next-steps.mdx +++ b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/120-mongodb/300-next-steps.mdx @@ -73,7 +73,7 @@ const deletedUser = await prisma.user.delete({ ### Explore the data in Prisma Studio -Prisma Studio is a visual editor for the data in your database. Run `$ npx prisma studio` in your terminal. +Prisma Studio is a visual editor for the data in your database. Run `npx prisma studio` in your terminal. ### Try a Prisma example diff --git a/content/200-concepts/100-components/06-prisma-studio.mdx b/content/200-concepts/100-components/06-prisma-studio.mdx index 1e0cb2db3f..630d20cbe2 100644 --- a/content/200-concepts/100-components/06-prisma-studio.mdx +++ b/content/200-concepts/100-components/06-prisma-studio.mdx @@ -9,7 +9,7 @@ experimental: false Prisma Studio is a visual editor for the data in your database. Note that Prisma Studio is not open source but you can still create issues in the [`prisma/studio`](https://github.com/prisma/studio) repo. -Run `$ npx prisma studio` in your terminal. +Run `npx prisma studio` in your terminal. From 96397e5be3339fc209eeb2edfbb0833c372e36cd Mon Sep 17 00:00:00 2001 From: ruheni Date: Wed, 26 Apr 2023 09:10:31 +0200 Subject: [PATCH 02/13] chore: link to more info on Prisma schema and Client #2674 --- .../110-relational-databases/150-using-prisma-migrate.mdx | 2 +- .../110-relational-databases/250-querying-the-database.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/150-using-prisma-migrate.mdx b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/150-using-prisma-migrate.mdx index 23fb31c15b..ef7b85ea9b 100644 --- a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/150-using-prisma-migrate.mdx +++ b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/150-using-prisma-migrate.mdx @@ -11,7 +11,7 @@ toc: false -In this guide, you'll use [Prisma Migrate](/concepts/components/prisma-migrate) to create the tables in your database. Add the following Prisma data model to your Prisma schema in `prisma/schema.prisma`: +In this guide, you'll use [Prisma Migrate](/concepts/components/prisma-migrate) to create the tables in your database. Add the following Prisma data model to your [Prisma schema](/concepts/components/prisma-schema) in `prisma/schema.prisma`: ```prisma file=prisma/schema.prisma copy model Post { diff --git a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/250-querying-the-database.mdx b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/250-querying-the-database.mdx index 9b66c934ae..f32ae22764 100644 --- a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/250-querying-the-database.mdx +++ b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/250-querying-the-database.mdx @@ -9,7 +9,7 @@ toc: false ## Write your first query with Prisma Client -Now that you have generated Prisma Client, you can start writing queries to read and write data in your database. For the purpose of this guide, you'll use a plain Node.js script to explore some basic features of Prisma Client. +Now that you have generated [Prisma Client](/concepts/components/prisma-client), you can start writing queries to read and write data in your database. For the purpose of this guide, you'll use a plain Node.js script to explore some basic features of Prisma Client. From d036780bf09c0918e40e58f0d742f20d7adb755f Mon Sep 17 00:00:00 2001 From: ruheni Date: Wed, 26 Apr 2023 09:40:06 +0200 Subject: [PATCH 03/13] chore: remove $connect, higlight code snippets, update output Closes #2820 --- .../250-querying-the-database.mdx | 11 ++++++----- .../120-mongodb/250-querying-the-database.mdx | 18 +++--------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/250-querying-the-database.mdx b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/250-querying-the-database.mdx index f32ae22764..04c81e9823 100644 --- a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/250-querying-the-database.mdx +++ b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/250-querying-the-database.mdx @@ -129,7 +129,7 @@ Adjust the `main` function to send a `create` query to the database: -```ts file=index.ts copy +```ts file=index.ts highlight=2-21;add copy async function main() { await prisma.user.create({ data: { @@ -158,7 +158,7 @@ async function main() { -```js file=index.js copy +```js file=index.js highlight=2-21;add copy async function main() { await prisma.user.create({ data: { @@ -219,6 +219,7 @@ The output should look similar to this: { content: null, createdAt: 2020-03-21T16:45:01.246Z, + updatedAt: 2020-03-21T16:45:01.246Z, id: 1, published: false, title: 'Hello World', @@ -264,9 +265,9 @@ The query added new records to the `User` and the `Post` tables: **Post** -| **id** | **createdAt** | **title** | **content** | **published** | **authorId** | -| :----- | :------------------------- | :-------------- | :---------- | :------------ | :----------- | -| `1` | `2020-03-21T16:45:01.246Z` | `"Hello World"` | `null` | `false` | `1` | +| **id** | **createdAt** | **updatedAt** | **title** | **content** | **published** | **authorId** | +| :----- | :------------------------- | :------------------------: | :-------------- | :---------- | :------------ | :----------- | +| `1` | `2020-03-21T16:45:01.246Z` | `2020-03-21T16:45:01.246Z` | `"Hello World"` | `null` | `false` | `1` | **Profile** diff --git a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/250-querying-the-database.mdx b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/250-querying-the-database.mdx index e51882d0db..19e20efffc 100644 --- a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/250-querying-the-database.mdx +++ b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/250-querying-the-database.mdx @@ -21,8 +21,6 @@ import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient() async function main() { - // Connect the client - await prisma.$connect() // ... you will write your Prisma Client queries here } @@ -49,8 +47,6 @@ const { PrismaClient } = require('@prisma/client') const prisma = new PrismaClient() async function main() { - // Connect the client - await prisma.$connect() // ... you will write your Prisma Client queries here } @@ -82,8 +78,6 @@ Inside the `main` function, add the following query to read all `User` records f ```ts file=index.ts async function main() { - // Connect the client - await prisma.$connect() // ... you will write your Prisma Client queries here + const allUsers = await prisma.user.findMany() + console.log(allUsers) @@ -96,9 +90,7 @@ async function main() { ```js file=index.js async function main() { - // Connect the client - await prisma.$connect() -- // ... you will write your Prisma Client queries here + // ... you will write your Prisma Client queries here + const allUsers = await prisma.user.findMany() + console.log(allUsers) } @@ -138,10 +130,8 @@ Adjust the `main` function to send a `create` query to the database: -```ts file=index.ts copy +```ts file=index.ts highlight=2-21;add copy async function main() { - await prisma.$connect() - await prisma.user.create({ data: { name: 'Rich', @@ -169,10 +159,8 @@ async function main() { -```js file=index.js copy +```js file=index.js highlight=2-21;add copy async function main() { - await prisma.$connect() - await prisma.user.create({ data: { name: 'Rich', From 2df5cfad0e435fd1d06b6ad41c0196cba418e29e Mon Sep 17 00:00:00 2001 From: ruheni Date: Wed, 26 Apr 2023 09:47:27 +0200 Subject: [PATCH 04/13] chore: add mention of query parameter --- .../110-relational-databases/100-connect-your-database.mdx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database.mdx b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database.mdx index 5f1bcaab59..8fc060f6c4 100644 --- a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database.mdx +++ b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database.mdx @@ -169,6 +169,12 @@ DATABASE_URL="mysql://myusername:mypassword@server.us-east-2.psdb.cloud/mydb?ssl The connection URL for a given database branch can be found from your PlanetScale account by going to the overview page for the branch and selecting the 'Connect' dropdown. In the 'Passwords' section, generate a new password and select 'Prisma' to get the Prisma format for the connection URL. + + +Ensure your connection string contains the `sslaccept=strict` query parameter. + + +
Alternative method: connecting using the PlanetScale CLI Alternatively, you can connect to your PlanetScale database server using the [PlanetScale CLI](https://docs.planetscale.com/reference/planetscale-environment-setup), and use a local connection URL. In this case the connection URL will look like this: From 5031138d7ff1ef96f4b067135e6e14cb29562b97 Mon Sep 17 00:00:00 2001 From: ruheni Date: Thu, 27 Apr 2023 09:36:03 +0200 Subject: [PATCH 05/13] rename TEST_DATABASE_URL to DATABASE_URL --- .../110-relational-databases/150-introspection.mdx | 2 +- .../01-prisma-schema/10-postgresql-extensions.mdx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx index 773004f349..74f4ef12f1 100644 --- a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx +++ b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx @@ -916,7 +916,7 @@ generator client { datasource db { provider = "cockroachdb" - url = "env(TEST_DATABASE_URL)" + url = env("DATABASE_URL") } model Post { diff --git a/content/200-concepts/100-components/01-prisma-schema/10-postgresql-extensions.mdx b/content/200-concepts/100-components/01-prisma-schema/10-postgresql-extensions.mdx index 029b363369..1477c4c37f 100644 --- a/content/200-concepts/100-components/01-prisma-schema/10-postgresql-extensions.mdx +++ b/content/200-concepts/100-components/01-prisma-schema/10-postgresql-extensions.mdx @@ -56,7 +56,7 @@ To represent PostgreSQL extensions in your Prisma schema, add the `extensions` f ```prisma file=schema.prisma datasource db { provider = "postgresql" - url = env("TEST_DATABASE_URL") + url = env("DATABASE_URL") extensions = [hstore(schema: "myHstoreSchema"), pg_trgm, postgis(version: "2.1")] } ``` @@ -74,7 +74,7 @@ The `map` argument is useful when the PostgreSQL extension that you want to acti ```prisma file=schema.prisma datasource db { provider = "postgresql" - url = env("TEST_DATABASE_URL") + url = env("DATABASE_URL") extensions = [uuidOssp(map: "uuid-ossp")] } ``` From a1c89f02701a2829bf29c53721173dee7ef3e815 Mon Sep 17 00:00:00 2001 From: ruheni Date: Thu, 27 Apr 2023 11:13:10 +0200 Subject: [PATCH 06/13] chore: update prisma schema --- .../150-introspection.mdx | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx index 74f4ef12f1..480a548f14 100644 --- a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx +++ b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx @@ -910,17 +910,8 @@ After the introspection is complete, your Prisma schema file was updated: The data model now looks similar to this: ```prisma file=prisma/schema.prisma -generator client { - provider = "prisma-client-js" -} - -datasource db { - provider = "cockroachdb" - url = env("DATABASE_URL") -} - model Post { - id BigInt @id @default(sequence()) + id BigInt @id @default(autoincrement()) title String @unique @db.String(255) createdAt DateTime @default(now()) @db.Timestamp(6) content String? @@ -930,14 +921,14 @@ model Post { } model Profile { - id BigInt @id @default(sequence()) + id BigInt @id @default(autoincrement()) bio String? userId BigInt @unique User User @relation(fields: [userId], references: [id], onDelete: NoAction, onUpdate: NoAction) } model User { - id BigInt @id @default(sequence()) + id BigInt @id @default(autoincrement()) name String? @db.String(255) email String @unique @db.String(255) Post Post[] @@ -959,7 +950,7 @@ Because [relation fields](/concepts/components/prisma-schema/relations#relation- ```prisma file=prisma/schema.prisma highlight=8,15,22,23;edit model Post { - id BigInt @id @default(sequence()) + id BigInt @id @default(autoincrement()) title String @unique @db.String(255) createdAt DateTime @default(now()) @db.Timestamp(6) content String? @@ -969,14 +960,14 @@ model Post { } model Profile { - id BigInt @id @default(sequence()) + id BigInt @id @default(autoincrement()) bio String? userId BigInt @unique user User @relation(fields: [userId], references: [id], onDelete: NoAction, onUpdate: NoAction) } model User { - id BigInt @id @default(sequence()) + id BigInt @id @default(autoincrement()) name String? @db.String(255) email String @unique @db.String(255) posts Post[] From fc02448dbcddb55b30927ab15c2f33fa9804687d Mon Sep 17 00:00:00 2001 From: ruheni Date: Thu, 27 Apr 2023 11:22:35 +0200 Subject: [PATCH 07/13] chore: update postgres schemas based on sql --- .../110-relational-databases/150-introspection.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx index 480a548f14..e2f6b6f6e3 100644 --- a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx +++ b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx @@ -365,14 +365,14 @@ model Post { content String? published Boolean @default(false) authorId Int - User User @relation(fields: [authorId], references: [id]) + User User @relation(fields: [authorId], references: [id], onDelete: NoAction, onUpdate: NoAction) } model Profile { id Int @id @default(autoincrement()) bio String? userId Int @unique - User User @relation(fields: [userId], references: [id]) + User User @relation(fields: [userId], references: [id], onDelete: NoAction, onUpdate: NoAction) } model User { @@ -396,28 +396,28 @@ These changes are relevant for the generated Prisma Client API where using lower Because [relation fields](/concepts/components/prisma-schema/relations#relation-fields) are _virtual_ (i.e. they _do not directly manifest in the database_), you can manually rename them in your Prisma schema without touching the database: -```prisma file=prisma/schema.prisma highlight=7,14,22,23;edit +```prisma file=prisma/schema.prisma highlight=7,15,22,23;edit model Post { id Int @id @default(autoincrement()) title String @db.VarChar(255) createdAt DateTime @default(now()) @db.Timestamp(6) content String? published Boolean @default(false) - author User @relation(fields: [authorId], references: [id]) authorId Int + author User @relation(fields: [authorId], references: [id], onDelete: NoAction, onUpdate: NoAction) } model Profile { id Int @id @default(autoincrement()) bio String? - user User @relation(fields: [userId], references: [id]) userId Int @unique + user User @relation(fields: [userId], references: [id], onDelete: NoAction, onUpdate: NoAction) } model User { id Int @id @default(autoincrement()) - email String @unique @db.VarChar(255) name String? @db.VarChar(255) + email String @unique @db.VarChar(255) posts Post[] profile Profile? } From d31f7a8ff4472de1092201e19ae0484be942bc02 Mon Sep 17 00:00:00 2001 From: ruheni Date: Thu, 27 Apr 2023 11:29:08 +0200 Subject: [PATCH 08/13] chore: update mysql Prisma schema snippets --- .../150-introspection.mdx | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx index e2f6b6f6e3..7c630e4474 100644 --- a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx +++ b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx @@ -497,24 +497,26 @@ The data model now looks similar to this (note that the fields on the models hav model Post { id Int @id @default(autoincrement()) title String @db.VarChar(255) - createdAt DateTime @default(now()) @db.Timestamp(6) - content String? + createdAt DateTime @default(now()) @db.Timestamp(0) + content String? @db.Text published Boolean @default(false) authorId Int - User User @relation(fields: [authorId], references: [id]) + User User @relation(fields: [authorId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "Post_ibfk_1") + + @@index([authorId], map: "authorId") } model Profile { id Int @id @default(autoincrement()) - bio String? - userId Int @unique - User User @relation(fields: [userId], references: [id]) + bio String? @db.Text + userId Int @unique(map: "userId") + User User @relation(fields: [userId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "Profile_ibfk_1") } model User { id Int @id @default(autoincrement()) name String? @db.VarChar(255) - email String @unique @db.VarChar(255) + email String @unique(map: "email") @db.VarChar(255) Post Post[] Profile Profile? } @@ -532,28 +534,30 @@ These changes are relevant for the generated Prisma Client API where using lower Because [relation fields](/concepts/components/prisma-schema/relations#relation-fields) are _virtual_ (i.e. they _do not directly manifest in the database_), you can manually rename them in your Prisma schema without touching the database: -```prisma file=prisma/schema.prisma highlight=7,14,22,23;edit +```prisma file=prisma/schema.prisma highlight=8,17,24,25;edit model Post { id Int @id @default(autoincrement()) title String @db.VarChar(255) - createdAt DateTime @default(now()) @db.Timestamp(6) - content String? + createdAt DateTime @default(now()) @db.Timestamp(0) + content String? @db.Text published Boolean @default(false) - author User @relation(fields: [authorId], references: [id]) authorId Int + author User @relation(fields: [authorId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "Post_ibfk_1") + + @@index([authorId], map: "authorId") } model Profile { id Int @id @default(autoincrement()) - bio String? - user User @relation(fields: [userId], references: [id]) - userId Int @unique + bio String? @db.Text + userId Int @unique(map: "userId") + user User @relation(fields: [userId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "Profile_ibfk_1") } model User { id Int @id @default(autoincrement()) - email String @unique @db.VarChar(255) name String? @db.VarChar(255) + email String @unique(map: "email") @db.VarChar(255) posts Post[] profile Profile? } From f9839432ec4b521286a496b52bcbedb499d58ed6 Mon Sep 17 00:00:00 2001 From: ruheni Date: Thu, 27 Apr 2023 11:55:31 +0200 Subject: [PATCH 09/13] Removes unneccessary admonition --- .../110-relational-databases/100-connect-your-database.mdx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database.mdx b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database.mdx index 8fc060f6c4..5f1bcaab59 100644 --- a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database.mdx +++ b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database.mdx @@ -169,12 +169,6 @@ DATABASE_URL="mysql://myusername:mypassword@server.us-east-2.psdb.cloud/mydb?ssl The connection URL for a given database branch can be found from your PlanetScale account by going to the overview page for the branch and selecting the 'Connect' dropdown. In the 'Passwords' section, generate a new password and select 'Prisma' to get the Prisma format for the connection URL. - - -Ensure your connection string contains the `sslaccept=strict` query parameter. - - -
Alternative method: connecting using the PlanetScale CLI Alternatively, you can connect to your PlanetScale database server using the [PlanetScale CLI](https://docs.planetscale.com/reference/planetscale-environment-setup), and use a local connection URL. In this case the connection URL will look like this: From 1911520601c0d8b25e0eae4a53a98230f788b3d5 Mon Sep 17 00:00:00 2001 From: ruheni Date: Thu, 27 Apr 2023 14:59:13 +0200 Subject: [PATCH 10/13] chore: move content into details tag Getting Started guide improvements (all guides) #2747 --- .../150-introspection.mdx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx index 7c630e4474..87a665e6e3 100644 --- a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx +++ b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx @@ -425,6 +425,9 @@ model User { In this example, the database schema did follow the [naming conventions](/reference/api-reference/prisma-schema-reference#naming-conventions) for Prisma models (only the virtual relation fields that were generated from introspection did not adhere to them and needed adjustment). This optimizes the ergonomics of the generated Prisma Client API. +
+ Using custom model and field names + Sometimes though, you may want to make additional changes to the names of the columns and tables that are exposed in the Prisma Client API. A common example is to translate _snake_case_ notation which is often used in database schemas into _PascalCase_ and _camelCase_ notations which feel more natural for JavaScript/TypeScript developers. Assume you obtained the following model from introspection that's based on _snake_case_ notation: @@ -473,6 +476,8 @@ const user = await prisma.myUser.create({ Learn more about this on the [Configuring your Prisma Client API](/concepts/components/prisma-client/working-with-prismaclient/use-custom-model-and-field-names) page. +
+ @@ -701,6 +706,9 @@ model User { In this example, the database schema did follow the [naming conventions](/reference/api-reference/prisma-schema-reference#naming-conventions) for Prisma models (only the virtual relation fields that were generated from introspection did not adhere to them and needed adjustment). This optimizes the ergonomics of the generated Prisma Client API. +
+ Using custom model and field names + Sometimes though, you may want to make additional changes to the names of the columns and tables that are exposed in the Prisma Client API. A common example is to translate _snake_case_ notation which is often used in database schemas into _PascalCase_ and _camelCase_ notations which feel more natural for JavaScript/TypeScript developers. Assume you obtained the following model from introspection that's based on _snake_case_ notation: @@ -749,6 +757,8 @@ const user = await prisma.myUser.create({ Learn more about this on the [Configuring your Prisma Client API](/concepts/components/prisma-client/working-with-prismaclient/use-custom-model-and-field-names) page. +
+
@@ -845,6 +855,9 @@ Because relation fields are _virtual_ (i.e. they _do not directly manifest in th In this example, the database schema follows the [naming conventions](/reference/api-reference/prisma-schema-reference#naming-conventions) for Prisma models. This optimizes the ergonomics of the generated Prisma Client API. +
+ Using custom model and field names + Sometimes though, you may want to make additional changes to the names of the columns and tables that are exposed in the Prisma Client API. A common example is to translate _snake_case_ notation which is often used in database schemas into _PascalCase_ and _camelCase_ notations which feel more natural for JavaScript/TypeScript developers. Assume you obtained the following model from introspection that's based on _snake_case_ notation: @@ -893,6 +906,8 @@ const user = await prisma.myUser.create({ Learn more about this on the [Configuring your Prisma Client API](/concepts/components/prisma-client/working-with-prismaclient/use-custom-model-and-field-names) page. +
+
@@ -981,6 +996,9 @@ model User { In this example, the database schema did follow the [naming conventions](/reference/api-reference/prisma-schema-reference#naming-conventions) for Prisma models (only the virtual relation fields that were generated from introspection did not adhere to them and needed adjustment). This optimizes the ergonomics of the generated Prisma Client API. +
+ Using custom model and field names + Sometimes though, you may want to make additional changes to the names of the columns and tables that are exposed in the Prisma Client API. A common example is to translate _snake_case_ notation which is often used in database schemas into _PascalCase_ and _camelCase_ notations which feel more natural for JavaScript/TypeScript developers. Assume you obtained the following model from introspection that's based on _snake_case_ notation: @@ -1029,6 +1047,8 @@ const user = await prisma.myUser.create({ Learn more about this on the [Configuring your Prisma Client API](/concepts/components/prisma-client/working-with-prismaclient/use-custom-model-and-field-names) page. +
+
From fd62b46df191017d91a69c4115299789cb292af8 Mon Sep 17 00:00:00 2001 From: Alex Ruheni <33921841+ruheni@users.noreply.github.com> Date: Mon, 8 May 2023 11:31:03 +0100 Subject: [PATCH 11/13] Update content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/250-querying-the-database.mdx Co-authored-by: Jan Piotrowski --- .../120-mongodb/250-querying-the-database.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/250-querying-the-database.mdx b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/250-querying-the-database.mdx index 19e20efffc..d1cfa88d88 100644 --- a/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/250-querying-the-database.mdx +++ b/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/250-querying-the-database.mdx @@ -90,7 +90,7 @@ async function main() { ```js file=index.js async function main() { - // ... you will write your Prisma Client queries here +- // ... you will write your Prisma Client queries here + const allUsers = await prisma.user.findMany() + console.log(allUsers) } From ad50af9e5135c29ac073a28cb200a2e4d342e6dc Mon Sep 17 00:00:00 2001 From: ruheni Date: Mon, 8 May 2023 15:27:52 +0200 Subject: [PATCH 12/13] chore: add admonition for schema attributes --- .../110-relational-databases/150-introspection.mdx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx index 87a665e6e3..a1bd264c46 100644 --- a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx +++ b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/150-introspection.mdx @@ -527,6 +527,12 @@ model User { } ``` + + +Refer to the [Prisma schema reference](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference) for detailed information about the schema definition. + + + Prisma's data model is a declarative representation of your database schema and serves as the foundation for the generated Prisma Client library. Your Prisma Client instance will expose queries that are _tailored_ to these models. Right now, there's a few minor "issues" with the data model: @@ -807,6 +813,12 @@ model User { } ``` + + +Refer to the [Prisma schema reference](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference) for detailed information about the schema definition. + + + Prisma's data model is a declarative representation of your database schema and serves as the foundation for the generated Prisma Client library. Your Prisma Client instance will expose queries that are _tailored_ to these models. You will then need to add in any missing relations between your data using [relation fields](/concepts/components/prisma-schema/relations#relation-fields): From a57d1b1d4403172b55b567ec5f5ffa47df293b30 Mon Sep 17 00:00:00 2001 From: ruheni Date: Mon, 8 May 2023 22:23:50 +0200 Subject: [PATCH 13/13] chore: update mysql baseline sql --- .../170-baseline-your-database.mdx | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/170-baseline-your-database.mdx b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/170-baseline-your-database.mdx index b3325029b9..e19cd39085 100644 --- a/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/170-baseline-your-database.mdx +++ b/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/170-baseline-your-database.mdx @@ -92,28 +92,44 @@ ALTER TABLE "Profile" ADD CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId" ```sql file=prisma/migrations/0_init/migration.sql -CREATE TABLE User ( - id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL, - name VARCHAR(255), - email VARCHAR(255) UNIQUE NOT NULL -); +-- CreateTable +CREATE TABLE `Post` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `title` VARCHAR(255) NOT NULL, + `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), + `content` TEXT NULL, + `published` BOOLEAN NOT NULL DEFAULT false, + `authorId` INTEGER NOT NULL, + + INDEX `authorId`(`authorId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -CREATE TABLE Post ( - id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL, - title VARCHAR(255) NOT NULL, - createdAt TIMESTAMP NOT NULL DEFAULT now(), - content TEXT, - published BOOLEAN NOT NULL DEFAULT false, - authorId INTEGER NOT NULL, - FOREIGN KEY (authorId) REFERENCES User(id) -); +-- CreateTable +CREATE TABLE `Profile` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `bio` TEXT NULL, + `userId` INTEGER NOT NULL, -CREATE TABLE Profile ( - id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL, - bio TEXT, - userId INTEGER UNIQUE NOT NULL, - FOREIGN KEY (userId) REFERENCES User(id) -); + UNIQUE INDEX `userId`(`userId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `User` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NULL, + `email` VARCHAR(255) NOT NULL, + + UNIQUE INDEX `email`(`email`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `Post` ADD CONSTRAINT `Post_ibfk_1` FOREIGN KEY (`authorId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT; + +-- AddForeignKey +ALTER TABLE `Profile` ADD CONSTRAINT `Profile_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT; ```