Skip to content

Latest commit

 

History

History
69 lines (37 loc) · 3.47 KB

prisma2-cli.md

File metadata and controls

69 lines (37 loc) · 3.47 KB

Prisma Framework CLI

Installation

The Prisma Framework CLI currently requires Node 8 (or higher).

Install with npm

npm install -g prisma2

Install with Yarn

yarn global add prisma2

The postinstall hook

When installing the Prisma Framework CLI, a postinstall hook is being executed. It downloads the Prisma Framework's query and migration engine binaries. The query engine contains the Prisma schema parser which is used by the prisma2 init and the prism2 generate commands. The migration engine is used by all prisma2 lift commands.

Using a HTTP proxy for the CLI

The Prisma Framework CLI supports custom HTTP proxies. This is particularly relevant when being behind a corporate firewall.

To activate the proxy, provide the environment variables HTTP_PROXY and/or HTTPS_PROXY. The behavior is very similar to how the npm CLI handles this.

The following environment variables can be provided:

  • HTTP_PROXY or http_proxy: Proxy URL for http traffic, for example http://localhost:8080
  • HTTPS_PROXY or https_proxy: Proxy URL for https traffic, for example https://localhost:8080

To get a local proxy, you can also use the proxy module:

Commands

Setup and development

prisma2 init

Sets up Prisma (i.e., Photon and/or Lift) via an interactive wizard. You can specify your database connection and/or create a new database to work with. For a list with currently supported databases, see the this page. The wizard also allows you to derive a Prisma schema file from your existing database.

prisma2 dev

Starts Prisma development mode. This starts a server that lets you interact with your database and defined models. Note that Prisma Studio relies on your Prisma schema file to provide a fully featured user-interface with CRUD (create / read / update / delete) functionality.

prisma2 generate

Invokes all generators defined in the Prisma schema file. For example, this creates the Photon client to interact with the underlying database. Read more about Photon and its capabilities here.

prisma2 introspect

Introspects the database and generates a data model from it. Basically, it analyzes your (already existing) database and automatically creates the Prisma schema file for you. This is useful, if you already have an existing application and want to start using the Prisma framework. Note that this command synchronizes your Prisma schema file according to your database structure; typically if you're not using Lift to migrate your database.

Lift (migrations)

prisma2 lift save

Creates a new migration based on changes on your data model. In this context it automatically documents all changes (i.e., a git diff). All changes are only applied locally and are not applied to the database.

prisma2 lift up

Runs all migrations that have not been applied to the database yet. This command effectively "replays" all local changes to the database.

prisma2 lift down

This command reverts a database migration. In turn, it creates a "compensation" migration that undoes previous changes.