This example demonstrates how to use Prisma with Postgres.
The prisma
cli is the core component of your development workflow. prisma
should be installed as a global dependency, you can install this with npm install -g prisma
Clone the Prisma monorepo and navigate to this directory or download only this example with the following command:
curl https://codeload.github.com/graphcool/prisma/tar.gz/master | tar -xz --strip=2 prisma-master/examples/postgres
Next, navigate into the downloaded folder and install the NPM dependencies:
cd postgres
yarn install
You can now deploy the Prisma service (note that this requires you to have Docker installed on your machine - if that's not the case, follow the collapsed instructions below the code block):
# Ensure docker is running the server's dependencies
docker-compose up
# Deploy the server
cd prisma
prisma deploy
I don't have Docker installed on my machine
To deploy your service to a demo server (rather than locally with Docker), please follow this link.
Running the command docker ps
will show you an image running for Postgres running at port 5432 and an image running the Prisma which connects to this external Postgres running at port 5432.
Let us take a look at the Postgres specific parts of the docker-compose.yml
file in this example.
This part of the configuration declares the service for postgres database which runs on its default port 5432.
postgres:
image: postgres
restart: always
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
This part of configurations declares the environment for Prisma server to connect to the external Postgres database running at the port 5432.
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
databases:
default:
connector: postgres
host: postgres
port: 5432
user: prisma
password: prisma
migrations: true