You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/docs/config/config.md
-4Lines changed: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,6 @@ These database types are powered by their corresponding Prisma database provider
64
64
-`url`: The connection URL for your database
65
65
-`onConnect`: which takes a [`KeystoneContext`](../context/overview) object, and lets perform any actions you might need at startup, such as data seeding
66
66
-`enableLogging` (default: `false`): Enable logging from the Prisma client.
67
-
-`useMigrations` (default: `false`): Determines whether to use migrations or automatically force-update the database with the latest schema and potentially lose data.
68
67
-`idField` (default: `{ kind: "cuid" }`): The kind of id field to use, it can be one of: `cuid`, `uuid` or `autoincrement`.
69
68
This can also be customised at the list level `db.idField`.
70
69
If you are using `autoincrement`, you can also specify `type: 'BigInt'` on PostgreSQL and MySQL to use BigInts.
Note: the deploy script above assumes you are using migrations
77
+
Note: Depending on where you are deploying the `prisma migrate deploy` step might be better in the `build` or as a separate step altogether.
44
78
{% /hint %}
45
79
46
80
Read on below for more details about each command, and see [bringing it all together](#bringing-it-all-together) for more details (including some important caveats) about how that "deploy" command works.
@@ -57,12 +91,28 @@ This is the command you use to start Keystone for local development. It will:
57
91
- Generate and apply database migrations based on your Keystone Schema
58
92
- Start the local dev server, which hosts the GraphQL API and Admin UI
59
93
60
-
{% hint kind="warn" %}
61
-
Keystone does not currently watch your local files for changes. If you update the config, schema or any other files in your keystone project you'll need to restart the server.
62
-
{% /hint %}
94
+
{% if $nextRelease %}
95
+
### dev flags
96
+
97
+
-`--no-db-push` - Don't push any updates of your Prisma schema to your database
98
+
-`--no-prisma` - Don't build or validate the prisma schema
99
+
-`--no-server` - Don't start the express server, will still watch for changes and update the Admin UI and schema files
100
+
-`--no-ui` - Don't build and serve the AdminUI
101
+
{% /if %}
63
102
64
103
### About database migrations
65
104
105
+
{% if $nextRelease %}
106
+
When using `keystone dev` the default behaviour is for Keystone to update your database to match your schema using Prisma Migrate. This behaviour is great for the rapid iteration of a schema, but can be modified in the following ways:
107
+
108
+
- Running `keystone dev --no-db-push` - This will skip the dev migration step and not perform any checks on your database to ensure it matches your schema. This can be useful if you have an existing database or want to handle all migrations yourself. Be aware that this may lead to GraphQL runtime errors if a table or table column is unavailable.
109
+
110
+
See [`prisma` command](#prisma) below for more information on database migrations.
111
+
112
+
{% hint kind="tip" %}
113
+
Be careful of running `keystone dev` while pointing to a production database as this can cause data loss.
114
+
{% /hint %}
115
+
{% else /%}
66
116
In development, Keystone will migrate the structure of your database for you in one of two ways depending on how you have configured `db.useMigrations`:
67
117
68
118
- If `db.useMigrations` is `false` (the default), Keystone will use Prisma Migrate to update your database so that it matches your schema. It may lose data while updating your database so you should only use this mode in initial development.
@@ -75,6 +125,7 @@ Commit the migration files to source control, then when you are hosting your app
75
125
{% hint kind="tip" %}
76
126
We strongly recommend enabling migrations if you are going to run your app in production. Not doing so risks data loss.
77
127
{% /hint %}
128
+
{% /if %}
78
129
79
130
### Resetting the database
80
131
@@ -95,6 +146,11 @@ This is mainly useful early in a project's development lifecycle, when you want
95
146
```bash
96
147
$ keystone postinstall
97
148
```
149
+
{% if $nextRelease %}
150
+
{% hint kind="tip" %}
151
+
Note: `postinstall` is an alias for `keystone build --no-ui --frozen` we recommend switching to this `build` command
152
+
{% /hint %}
153
+
{% /if %}
98
154
99
155
Keystone generates several files that your app may depend on, including the Node.js API and TypeScript definitions.
100
156
@@ -109,6 +165,11 @@ While the recommended way to fix this problem is to start your app using `keysto
109
165
```bash
110
166
$ keystone postinstall --fix
111
167
```
168
+
{% if $nextRelease %}
169
+
{% hint kind="tip" %}
170
+
Note: `postinstall --fix` is an alias for `keystone build --no-ui` we recommend switching to this `build` command
171
+
{% /hint %}
172
+
{% /if %}
112
173
113
174
## build
114
175
@@ -118,7 +179,14 @@ $ keystone build
118
179
119
180
This command generates the files needed for Keystone to start in **production** mode. You should run it during the build phase of your production deployment.
120
181
121
-
It will also validate that the generated files you should have committed to source control are in sync with your Keystone Schema (see `postinstall` above).
182
+
It will also validate that the generated files you should have committed to source control are in sync with your Keystone Schema.
183
+
{% if $nextRelease %}
184
+
185
+
### build flags
186
+
-`--frozen` - Don't update the graphql or prisma schemas, only validate them, exits with error if the schemas don't match what keystone would generate.
187
+
-`--no-prisma` - Don't build or validate the prisma schema
188
+
-`--no-ui` - Don't build the AdminUI
189
+
{% /if %}
122
190
123
191
## start
124
192
@@ -129,6 +197,12 @@ $ keystone start
129
197
This command starts Keystone in **production** mode. It requires a build to have been generated (see `build` above).
130
198
131
199
It will not generate or apply any database migrations - these should be run during the **build** or **release** phase of your production deployment.
200
+
{% if $nextRelease %}
201
+
202
+
### start flags
203
+
-`--with-migrations` - Trigger prisma to run migrations as part of startup
204
+
-`--no-ui` - Don't serve the AdminUI
205
+
{% /if %}
132
206
133
207
## prisma
134
208
@@ -191,6 +265,11 @@ Start Keystone in production mode:
191
265
```bash
192
266
yarn keystone start
193
267
```
268
+
{% if $nextRelease %}
269
+
{% hint kind="tip" %}
270
+
Note: To run migrations before you start Keystone use `keystone start --with-migrations`
description: "Learn how to get your production database ready using Keystone's migration"
4
+
---
5
+
6
+
Before running `keystone start` with a production database, you will first need to ensure the database has all the tables and fields that keystone requires. To make this easier keystone can generate the required migration files to store alongside your code, and then run these migrations against your production database.
7
+
8
+
## Prisma Migrate
9
+
10
+
Keystone uses Prisma's built-in migration feature, this works by generating `.sql` files into a `./migrations` at the root of your project (ie beside your `keystone.ts` file) and then running those migration files against your production database. For detailed information on how Prisma Migrate works see the [Prisma Migrate docs](https://www.prisma.io/docs/concepts/components/prisma-migrate).
11
+
12
+
## Running `keystone dev`
13
+
14
+
By default running `keystone dev` will force push your schema to the database set using `db.url` in your `keystone.ts` file.
15
+
16
+
{% if $nextRelease %}
17
+
## Skipping dev DB push
18
+
19
+
If you want to look after all migrations, including in dev, yourself you can run `keystone dev --no-db-push` this will not perform the default force push in dev leaving you to perform migrations as you like.
20
+
21
+
{% hint kind="tip" %}
22
+
Running `keystone dev --no-db-push` will return GraphQL runtime errors if tables and/or columns that Keystone requires are not present in the database.
23
+
{% /hint %}
24
+
25
+
## Keystone Prisma Migrate CLI
26
+
27
+
Keystone offers the following three commonly used commands through Prisma to help manage your migrations.
28
+
-`keystone prisma migrate generate` - Generates the migration files to run to set up your production database - these files should be committed to source control and accessible by the `deploy` step. This command is helpful if you want to either leave `keystone dev` as the default behaviour for rapid schema iteration and generate the migrations once you are ready to submit a PR.
29
+
-`keystone prisma migrate deploy` - Runs the generated migrations - this command can only be run after a `build` step, and is generally run in the deploy step of your app or before running `keystone start`.
30
+
-`keystone start --with-migrations` - Runs the generated migrations then starts Keystone.
31
+
{% /if %}
32
+
## Prisma CLI
33
+
34
+
The primary reason you'll need to use the Prisma CLI in your Keystone project is to work with Prisma Migrate.
35
+
36
+
As you start working with more sophisticated migration scenarios, you'll probably also need to use the [`migrate resolve`](https://www.prisma.io/docs/reference/api-reference/command-reference/#migrate-resolve) and [`migrate status`](https://www.prisma.io/docs/reference/api-reference/command-reference/#migrate-status) commands.
37
+
38
+
While Keystone abstracts much of the Prisma workflow for you, we strongly recommend you familiarise yourself with the Prisma Migrate CLI commands when you are managing your application in production.
39
+
40
+
41
+
{% related-content %}
42
+
{% well
43
+
heading="Getting Started with create-keystone-app"
44
+
href="/docs/getting-started" %}
45
+
How to use Keystone's CLI app to standup a new local project with an Admin UI & the GraphQL Playground.
46
+
{% /well %}
47
+
{% well
48
+
heading="Command Line Guide"
49
+
href="/docs/guides/cli" %}
50
+
Learn how to use Keystone's command line interface (CLI) to develop, build, and deploy your Keystone projects.
0 commit comments