Integration with Prisma/Docker
An easier way to integrate these tools into our project.
Let's begin by automatically integrating Prisma and Docker with Nest. We shall first install this schematic by Marc Stammerjohann, which allows for exactly that, and then add it to our project.
Choose the following options:
Datasource Provider - Postgresql
Dockerize - Yes
And then create the DatabaseModule
, to configure Prisma...
...and add the following to its imports
so that Prisma is available globally.
And finally, some more steps...
Adjust .env file and create .env.example
Remember that the TypeORM database is using the port 5432, and the test database uses port 5433. You may then wish to use another port such as 5434.
Add .env to .gitignore
In package.json, in the prisma scripts, replace
npx
withyarn
In the Dockerfile, adjust to use yarn
In docker-compose.yml, use the environment variables and clean up the file a bit
If necessary, change the names of containers/volumes in Docker Desktop to avoid duplicity
Turn on the database container
We'll also change the migration scripts, so that their usage becomes simpler. So, in package.json, let's alter the following scripts:
Change
migrate:dev
tomigrate:run
Change
migrate:dev:create
tomigrate:create
and add a-n
at the end
Remember to have the Prisma extension installed.
Commit - Prisma and docker setup
Last updated