Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs for multi-file Prisma schema and clean up #6059

Merged
merged 18 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/100-getting-started/01-quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Finally, set up Prisma ORM with the `init` command of the Prisma CLI:
npx prisma init --datasource-provider sqlite
```

This creates a new `prisma` directory with your Prisma schema file and configures SQLite as your database. You're now ready to model your data and create your database with some tables.
This creates a new `prisma` directory with a `prisma.schema` file and configures SQLite as your database. You're now ready to model your data and create your database with some tables.

## 2. Model your data in the Prisma schema

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ npx prisma db pull

This command reads the environment variable used to define the `url` in your `schema.prisma`, `DATABASE_URL`, that in our case is set in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a Prisma data model.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ npx prisma db pull

This command reads the `DATABASE_URL` environment variable that's defined in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a Prisma data model.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ npx prisma db pull

This command reads the `DATABASE_URL` environment variable that's defined in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a Prisma data model.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ npx prisma db pull

This command reads the `DATABASE_URL` environment variable that's defined in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a data model in your Prisma schema.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database with Prisma ORM](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ npx prisma db pull

This command reads the `DATABASE_URL` environment variable that's defined in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a Prisma data model.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ npx prisma db pull

This command reads the environment variable used to define the `url` in your `schema.prisma`, `DATABASE_URL`, that in our case is set in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a Prisma data model.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ npx prisma db pull

This command reads the `DATABASE_URL` environment variable that's defined in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a Prisma data model.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ npx prisma db pull

This command reads the `DATABASE_URL` environment variable that's defined in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a Prisma data model.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ npx prisma db pull

This command reads the `DATABASE_URL` environment variable that's defined in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a data model in your Prisma schema.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database with Prisma ORM](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ npx prisma db pull

This command reads the `DATABASE_URL` environment variable that's defined in `.env` and connects to your database. Once the connection is established, it introspects the database (i.e. it _reads the database schema_). It then translates the database schema from SQL into a Prisma data model.

After the introspection is complete, your Prisma schema file was updated:
After the introspection is complete, your Prisma schema is updated:

![Introspect your database](/img/getting-started/prisma-db-pull-generate-schema.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Prisma Client can be used in _any_ Node.js (supported versions) or TypeScript ba

### The Prisma schema

Every project that uses a tool from the Prisma ORM toolkit starts with a [Prisma schema file](/orm/prisma-schema). The Prisma schema allows developers to define their _application models_ in an intuitive data modeling language. It also contains the connection to a database and defines a _generator_:
Every project that uses a tool from the Prisma ORM toolkit starts with a [Prisma schema](/orm/prisma-schema). The Prisma schema allows developers to define their _application models_ in an intuitive data modeling language. It also contains the connection to a database and defines a _generator_:

<TabbedContent code>
<TabItem value="Relational databases">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Prisma ORM is a **next-generation ORM** that makes working with databases easy f

> **Note:** Since Prisma Client is the most prominent tool, we often refer to it as simply Prisma.

The three tools use the [Prisma schema](/orm/prisma-schema) as a single source of truth for the database schema, your application's object schema, and the mapping between the two. It's defined by you and is your main configuration file for Prisma ORM.
The three tools use the [Prisma schema](/orm/prisma-schema) as a single source of truth for the database schema, your application's object schema, and the mapping between the two. It's defined by you and is your main way of configuring Prisma ORM.
jharrell marked this conversation as resolved.
Show resolved Hide resolved

Prisma ORM makes you productive and confident in the software you're building with features such as _type safety_, rich auto-completion, and a natural API for fetching relations.

Expand Down Expand Up @@ -440,7 +440,7 @@ In summary, Prisma ORM is a new kind of Data Mapper ORM that differs from tradit

Unlike traditional ORMs, with Prisma ORM, you define the Prisma schema – a declarative single source of truth for the database schema and application models. All queries in Prisma Client return plain JavaScript objects which makes the process of interacting with the database a lot more natural as well as more predictable.

Prisma ORM supports two main workflows for starting new projects and adopting in an existing project. For both workflows, the Prisma schema is the main configuration file.
Prisma ORM supports two main workflows for starting new projects and adopting in an existing project. For both workflows, your main avenue for configuration is via the Prisma schema.

Like all abstractions, both Prisma ORM and other ORMs hide away some of the underlying details of the database with different assumptions.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ By default, the PostgreSQL connector contains a database driver responsible for

## Example

To connect to a PostgreSQL database server, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema file](/orm/prisma-schema):
To connect to a PostgreSQL database server, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema](/orm/prisma-schema):

```prisma file=schema.prisma showLineNumbers
datasource db {
Expand Down
2 changes: 1 addition & 1 deletion content/200-orm/050-overview/500-databases/400-mysql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ By default, the MySQL connector contains a database driver responsible for conne

## Example

To connect to a MySQL database server, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema file](/orm/prisma-schema):
To connect to a MySQL database server, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema](/orm/prisma-schema):

```prisma file=schema.prisma showLineNumbers
datasource db {
Expand Down
2 changes: 1 addition & 1 deletion content/200-orm/050-overview/500-databases/500-sqlite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ By default, the SQLite connector contains a database driver responsible for conn

## Example

To connect to a SQLite database file, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [schema file](/orm/prisma-schema):
To connect to a SQLite database file, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema](/orm/prisma-schema):

```prisma file=schema.prisma showLineNumbers
datasource db {
Expand Down
10 changes: 5 additions & 5 deletions content/200-orm/050-overview/500-databases/600-mongodb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Some aspects of using Prisma ORM with MongoDB are the same as when using Prisma
- connect to your database, using the [`mongodb` database connector](/orm/overview/databases)
- use [Introspection](/orm/prisma-schema/introspection) for existing projects if you already have a MongoDB database
- use [`db push`](/orm/prisma-migrate/workflows/prototyping-your-schema) to push changes in your schema to the database
- use [Prisma Client](/orm/prisma-client) in your application to query your database in a type safe way based on your Prisma Schema
- use [Prisma Client](/orm/prisma-client) in your application to query your database in a type safe way based on your Prisma schema
jharrell marked this conversation as resolved.
Show resolved Hide resolved

## Differences to consider

MongoDB's document-based structure and flexible schemas means that using Prisma ORM with MongoDB differs from using it with a relational database in a number of ways. These are some areas where there are differences that you need to be aware of:
MongoDB's document-based structure and flexible schema means that using Prisma ORM with MongoDB differs from using it with a relational database in a number of ways. These are some areas where there are differences that you need to be aware of:

- **Defining IDs**: MongoDB documents have an `_id` field (that often contains an [ObjectID](https://www.mongodb.com/docs/manual/reference/bson-types/#std-label-objectid)). Prisma ORM does not support fields starting with `_`, so this needs to be mapped to a Prisma ORM field using the `@map` attribute. For more information, see [Defining IDs in MongoDB](/orm/prisma-schema/data-model/models#defining-ids-in-mongodb).

Expand All @@ -55,7 +55,7 @@ This section provides instructions for how to carry out tasks that require steps

### How to migrate existing data to match your Prisma schema

Migrating your database over time is an important part of the development cycle. During development, you will need to update your Prisma schema file (for example, to add new fields), then update the data in your development environment’s database, and eventually push both the updated schema and the new data to the production database.
Migrating your database over time is an important part of the development cycle. During development, you will need to update your Prisma schema (for example, to add new fields), then update the data in your development environment’s database, and eventually push both the updated schema and the new data to the production database.

<Admonition type="info">

Expand Down Expand Up @@ -127,7 +127,7 @@ As an example, take a MongoDB database with two collections, `User` and `Post`.
- `title` field with a type of `string`
- `userId` with a type of `objectID`

On introspection with `db pull`, this is pulled in to the Prisma schema file as follows:
On introspection with `db pull`, this is pulled in to the Prisma schema as follows:
janpio marked this conversation as resolved.
Show resolved Hide resolved

```prisma file=prisma/schema.prisma showLineNumbers
model Post {
Expand Down Expand Up @@ -356,7 +356,7 @@ For more information on how to set up and manage a MongoDB database, see the [Pr

## Example

To connect to a MongoDB server, configure the [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema file](/orm/prisma-schema):
To connect to a MongoDB server, configure the [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema](/orm/prisma-schema):
janpio marked this conversation as resolved.
Show resolved Hide resolved

```prisma file=schema.prisma showLineNumbers
datasource db {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The Microsoft SQL Server data source connector connects Prisma ORM to a [Microso

## Example

To connect to a Microsoft SQL Server database, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema file](/orm/prisma-schema):
To connect to a Microsoft SQL Server database, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema](/orm/prisma-schema):

```prisma file=schema.prisma showLineNumbers
datasource db {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CockroachDB is largely compatible with PostgreSQL, and can mostly be used with P
- connect to your database, using Prisma ORM's [`cockroachdb` database connector](/orm/overview/databases/cockroachdb)
- use [Introspection](/orm/prisma-schema/introspection) for existing projects if you already have a CockroachDB database
- use [Prisma Migrate](/orm/prisma-migrate) to migrate your database schema to a new version
- use [Prisma Client](/orm/prisma-client) in your application to query your database in a type safe way based on your Prisma Schema
- use [Prisma Client](/orm/prisma-client) in your application to query your database in a type safe way based on your Prisma schema
jharrell marked this conversation as resolved.
Show resolved Hide resolved

## Differences to consider

Expand Down Expand Up @@ -62,7 +62,7 @@ CREATE TABLE public."Post" (
);
```

After introspecting your database with `npx prisma db pull`, you will have a new `Post` model in your `schema.prisma` file:
After introspecting your database with `npx prisma db pull`, you will have a new `Post` model in your Prisma schema:
jharrell marked this conversation as resolved.
Show resolved Hide resolved

```prisma file=schema.prisma showLineNumbers
model Post {
Expand Down Expand Up @@ -94,7 +94,7 @@ For more information on generating database keys, see CockroachDB's [Primary key

## Example

To connect to a CockroachDB database server, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema file](/orm/prisma-schema):
To connect to a CockroachDB database server, you need to configure a [`datasource`](/orm/prisma-schema/overview/data-sources) block in your [Prisma schema](/orm/prisma-schema):

```prisma file=schema.prisma showLineNumbers
datasource db {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The following is a list of community created generators. If you want to create y
- [`typegraphql-prisma-nestjs`](https://github.com/EndyKaufman/typegraphql-prisma-nestjs#readme): Fork of [`typegraphql-prisma`](https://github.com/MichalLytek/typegraphql-prisma), which also generates CRUD resolvers for Prisma models but for NestJS
- [`prisma-typegraphql-types-gen`](https://github.com/YassinEldeeb/prisma-tgql-types-gen): Generates [TypeGraphQL](https://typegraphql.com/) class types and enums from your prisma type definitions, the generated output can be edited without being overwritten by the next gen and has the ability to correct you when you mess up the types with your edits.
- [`nexus-prisma`](https://github.com/prisma/nexus-prisma/): Allows to project Prisma models to GraphQL via [GraphQL Nexus](https://nexusjs.org/docs/)
- [`prisma-nestjs-graphql`](https://github.com/unlight/prisma-nestjs-graphql): Generates object types, inputs, args, etc. from the Prisma schema file for usage with `@nestjs/graphql` module
- [`prisma-nestjs-graphql`](https://github.com/unlight/prisma-nestjs-graphql): Generates object types, inputs, args, etc. from the Prisma schema for usage with `@nestjs/graphql` module
jharrell marked this conversation as resolved.
Show resolved Hide resolved
- [`prisma-appsync`](https://github.com/maoosi/prisma-appsync): Generates a full-blown GraphQL API for [AWS AppSync](https://aws.amazon.com/appsync/)
- [`prisma-kysely`](https://github.com/valtyr/prisma-kysely): Generates type definitions for Kysely, a TypeScript SQL query builder. This can be useful to perform queries against your database from an edge runtime, or to write more complex SQL queries not possible in Prisma without dropping type safety.
- [`prisma-generator-nestjs-dto`](https://github.com/vegardit/prisma-generator-nestjs-dto): Generates DTO and Entity classes with relation `connect` and `create` options for use with [NestJS Resources](https://docs.nestjs.com/recipes/crud-generator) and [@nestjs/swagger](https://www.npmjs.com/package/@nestjs/swagger)
Expand Down
Loading
Loading