This example demonstrates how to use Prisma with Postgres.
Note:
prismais listed as a development dependency and script in this project'spackage.json. This means you can invoke the Prisma CLI without having it globally installed on your machine (by prefixing it withyarn), e.g.yarn prisma deployoryarn prisma playground. If you have the Prisma CLI installed globally (which you can do withnpm install -g prisma), you can omit theyarnprefix.
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/postgresNext, navigate into the downloaded folder and install the NPM dependencies:
cd postgres
yarn installYou 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):
yarn prisma deployI 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/dataThis 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