Command Line

Keystone provides a command line interface (CLI) for running your Keystone system. The command keystone-next lets you control how you build and run your system, and how your migrate and seed the data in your database.

Usage
$ keystone-next [command]
Commands
Run
prototype (default) start the project in prototyping mode
dev start the project in development mode
start start the project in production mode
Build
build build the project (must be done before using start)
Migrate (Prisma only)
reset reset the database (this will drop all data!)
generate generate a migration
deploy deploy all migrations

The CLI supports commands in three categories; Run, Build and Migrate.

Run

The run commands are used to prepare and then start your Keystone server. Keystone can be run in three different modes; prototyping, dev and production. These different modes support different phases of your project life-cycle. The different modes differ in how they interact with your database and with your Admin UI application.

Note: All the run commands expect to find a module called keystone.ts with a default export which returns a system configuration config() from @keystone-next/keystone/schema. See the System Configuration API for details on how to configure a Keystone system.

keystone-next prototype (default)

In prototyping mode, Keystone will try its hardest to put your database into a state which is consistent with your schema. This might require Keystone to delete data in your database. This mode of operation should only be used when you are first getting started with Keystone and are not yet working with real data. In prototyping mode you can quickly change your schema and immediately see the changes reflected in your database and Admin UI when you restart.

keystone-next dev

Dev mode is identical to prototyping mode when using the knex of mongoose adapters. When using the prisma adapter, Keystone will use Prisma's migration framework to generate and locally apply migrations when you start your system. If you are using prisma and your database already includes migrations then you must use dev mode, and not prototyping mode.

keystone-next start

In production mode Keystone will not apply or generate any database migrations. It will use the pre-built version of the Admin UI Next.js application, and a pre-built Prisma client. If database migrations have not been applied, the Prisma client is outdated or missing, or the Admin UI has not been built, then the server will not start.

Note: Database migrations are only handled when using the prisma adapter.

Build

keystone-next build

The build command is used to generate a built version of Admin UI Next.js application and the Prisma client (if using the prisma adapter) which can be used when running the system in production mode (keystone-next start).

Migrate (Prisma only)

keystone-next reset

This command invokes prisma migrate reset to reset your local database to a state consistent with the migrations directory. Use this command before running keystone-next generate to ensure that a valid migration is created.

keystone-next generate

This command will generate a migration schema based on the current state of your database and your Keystone schema. This command should be run after running keystone-next reset and the generated migration artefact should be added to your repository so that it can be shared with other developers and deployed in production.

keystone-next deploy

This command will apply any migrations in the migrations directory. It should be used in production to apply migrations before starting the server.