P
Prisma6mo ago
qb1t

Correct way to setup prisma + docker

(I am new to prisma this is my first project using it) Hi I am currently trying to dockerise one of my typescript apps (discord bot) which is using prisma with sqlite database. I am in the middle of writing the dockerfile This is it so far:
FROM node:18-alpine

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json to the working directory
COPY package.json package-lock.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application files
COPY . .

# Build the TypeScript code
RUN npm run build

# Prisma needs to generate the client
RUN npx prisma generate

# Run the bot using the built JavaScript file
CMD ["npm", "run", "start"]
FROM node:18-alpine

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json to the working directory
COPY package.json package-lock.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application files
COPY . .

# Build the TypeScript code
RUN npm run build

# Prisma needs to generate the client
RUN npx prisma generate

# Run the bot using the built JavaScript file
CMD ["npm", "run", "start"]
My question is what is the proper way to set up migrations or something so that when I push a new version of the scheme.prisma the database automatically gets updated without wiping current data. The sqlite database is persistent across the container builds.
4 Replies
Yetzederixx
Yetzederixx6mo ago
I use a boot.sh script
boot.sh

#! /bin/bash

npx prisma migrate deploy
npx prisma generate
npm start
boot.sh

#! /bin/bash

npx prisma migrate deploy
npx prisma generate
npm start
and then this in the docker file CMD [ "./boot.sh" ]
qb1t
qb1tOP6mo ago
so npx prisma migrate deploy is the command I am looking for? What about the first deployment?
Yetzederixx
Yetzederixx6mo ago
Like most I develop locally, before shoving out into staging/prod. I use npx prisma migrate dev --name migration_name to generate my migration files after a schema change, the first line applies those migrations on remote
Yetzederixx
Yetzederixx6mo ago
then my migrations folder looks like this
No description

Did you find this page helpful?