Skip to content

Commit

Permalink
add info about --output for migrate diff (#5805)
Browse files Browse the repository at this point in the history
* add info about --output for migrate diff

* Update content/200-orm/500-reference/200-prisma-cli-reference.mdx

Co-authored-by: Alberto Schiabel <[email protected]>

* Update content/200-orm/050-overview/500-databases/950-cloudflare-d1.mdx

Co-authored-by: Jan Piotrowski <[email protected]>

---------

Co-authored-by: Alberto Schiabel <[email protected]>
Co-authored-by: Jan Piotrowski <[email protected]>
  • Loading branch information
3 people authored Apr 4, 2024
1 parent e17642d commit c37bc05
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
11 changes: 6 additions & 5 deletions content/200-orm/050-overview/500-databases/950-cloudflare-d1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Prisma ORM support for Cloudflare D1 is currently in [Preview](/orm/more/release

## What is Cloudflare D1?

D1 is Cloudflare's native serverless database and was initially [launched in 2022](https://blog.cloudflare.com/introducing-d1). It's based on SQLite and can be used when deploying applications with Cloudflare.
D1 is Cloudflare's native serverless database and was initially [launched in 2022](https://blog.cloudflare.com/introducing-d1). It's based on SQLite and can be used when deploying applications with Cloudflare.

Following Cloudflare's principles of geographic distribution and bringing compute and data closer to application users, D1 supports automatic read-replication. It dynamically manages the number of database instances and locations of read-only replicas based on how many queries a database is getting, and from where.

Expand Down Expand Up @@ -98,15 +98,16 @@ For the initial migration, you can use the special `--from-empty` option though:
npx prisma migrate diff \
--from-empty \
--to-schema-datamodel ./prisma/schema.prisma \
--script > migrations/0001_create_user_table.sql
--script \
--output migrations/0001_create_user_table.sql
```

The command above uses the following options:

- `--from-empty`: The source for the SQL statement is an empty schema.
- `--to-schema-datamodel ./prisma/schema.prisma`: The target for the SQL statement is the data model in `./prisma/schema.prisma`.
- `--script`: Output the result as SQL. If you omit this option, the "migration steps" will be generated in plain English.
- `> migrations/0001_create_user_table.sql`: Store the result in `migrations/0001_create_user_table.sql`.
- `--output migrations/0001_create_user_table.sql`: Store the result in `migrations/0001_create_user_table.sql`.

After running this command, `migrations/0001_create_user_table.sql` will have the following contents:

Expand Down Expand Up @@ -204,7 +205,7 @@ As explained above, you now need to use `--from-local-d1` instead of `--from-emp
npx prisma migrate diff \
--from-local-d1 \
--to-schema-datamodel ./prisma/schema.prisma \
--script > migrations/0002_create_post_table.sql
--output migrations/0002_create_post_table.sql
```
<!-- ```terminal
Expand All @@ -221,7 +222,7 @@ The command above uses the following options:
- `--from-local-d1`: The source for the SQL statement is the local D1 database file.
- `--to-schema-datamodel ./prisma/schema.prisma`: The target for the SQL statement is the data model in `./prisma/schema.prisma`.
- `--script`: Output the result as SQL. If you omit this option, the "migration steps" will be generated in plain English.
- `> migrations/0002_create_post_table.sql`: Store the result in `migrations/0002_create_post_table.sql`.
- `--output migrations/0002_create_post_table.sql`: Store the result in `migrations/0002_create_post_table.sql`.
After running this command, `migrations/0002_create_post_table.sql` will have the following contents:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ Replace `__YOUR_D1_DATABASE_NAME__` with the name of your database again and, wh
You can now generate the required SQL statement for creating a `User` table that can be mapped to the `User` model in your the Prisma schema as follows:

```terminal
npx prisma migrate diff --from-empty --to-schema-datamodel ./prisma/schema.prisma --script > migrations/0001_create_user_table.sql
npx prisma migrate diff --from-empty --to-schema-datamodel ./prisma/schema.prisma --script --output migrations/0001_create_user_table.sql
```

Note that the resulting SQL statement is stored in a file in the `migrations` directory called `0001_create_user_table.sql` which looks as follows:
Expand Down
31 changes: 17 additions & 14 deletions content/200-orm/500-reference/200-prisma-cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1295,30 +1295,33 @@ datasource db {

One of the following `--from-...` options is required:

| Options | Description | Notes |
| :------------------------- | :-------------------------------------------------------------------------------- | :----------------------- |
| `--from-url` | A data source URL | |
| `--from-migrations` | Path to the Prisma Migrate migrations directory | Not supported in MongoDB |
| `--from-schema-datamodel` | Path to a Prisma schema file, uses the data model for the diff | |
| `--from-schema-datasource` | Path to a Prisma schema file, uses the URL in the `datasource` block for the diff | |
| `--from-empty` | Assume that you the data model you are migrating from is empty | |
| Options | Description | Notes |
| :------------------------- | :---------------------------------------------------------------------------------------------------- | :----------------------- |
| `--from-url` | A data source URL | |
| `--from-migrations` | Path to the Prisma Migrate migrations directory | Not supported in MongoDB |
| `--from-schema-datamodel` | Path to a Prisma schema file, uses the data model for the diff | |
| `--from-schema-datasource` | Path to a Prisma schema file, uses the URL in the `datasource` block for the diff | |
| `--from-empty` | Assume that you the data model you are migrating from is empty | |
| `--from-local-d1` | Path to a local D1 instance ([learn more](/orm/overview/databases/cloudflare-d1#migration-workflows)) | |

One of the following `--to-...` options is required:

| Options | Description | Notes |
| :----------------------- | :-------------------------------------------------------------------------------- | :----------------------- |
| `--to-url` | A data source URL | |
| `--to-migrations` | Path to the Prisma Migrate migrations directory | Not supported in MongoDB |
| `--to-schema-datamodel` | Path to a Prisma schema file, uses the data model for the diff | |
| `--to-schema-datasource` | Path to a Prisma schema file, uses the URL in the `datasource` block for the diff | |
| `--to-empty` | Assume that you the data model you are migrating to is empty | |
| Options | Description | Notes |
| :----------------------- | :---------------------------------------------------------------------------------------------------- | :----------------------- |
| `--to-url` | A data source URL | |
| `--to-migrations` | Path to the Prisma Migrate migrations directory | Not supported in MongoDB |
| `--to-schema-datamodel` | Path to a Prisma schema file, uses the data model for the diff | |
| `--to-schema-datasource` | Path to a Prisma schema file, uses the URL in the `datasource` block for the diff | |
| `--to-empty` | Assume that you the data model you are migrating to is empty | |
| `--to-local-d1` | Path to a local D1 instance ([learn more](/orm/overview/databases/cloudflare-d1#migration-workflows)) | |

Other options:

| Options | Required | Description | Notes |
| :---------------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------- |
| `--shadow-database-url` | No | URL for the shadow database | Only required if using `--to-migrations` or `--from-migrations` |
| `--script` | No | Outputs a SQL script instead of the default human-readable summary | Not supported in MongoDB |
| `-o`, `--output` | No | Writes to a file instead of stdout | |
| `--exit-code` | No | Change the exit code behavior to signal if the diff is empty or not (Empty: 0, Error: 1, Not empty: 2). Default behavior is Success: 0, Error: 1. | |
| `--help` | No | Displays the help message. | |

Expand Down

0 comments on commit c37bc05

Please sign in to comment.