I was reading this doc <https://www.prisma.io/docs...
# orm-help
a
I was reading this doc https://www.prisma.io/docs/concepts/components/prisma-migrate/prisma-migrate-limitations-issues . So the same schema and migration will not work in dev and qa. How to make sure that schema changes in the dev DB reflect in the qa DB. Should I run the npx prisma migrate command in the qa env as well?
r
After you have already created migrations in dev, you just need to run
prisma migrate deploy
in your QA environment to apply all the migrations.
a
okay. while working on the local I do the changes to the schema and would like to do the migration as well. In this case, should I run the migration command on dev and qa?
r
So the steps would be like this: 1. Create the migrations in dev where you add your mdoels, fields etc. via
prisma migrate dev
2. After this is done, you perform
prisma migrate deploy
on your QA to apply all the migrations that you create on dev. 3. This same process can be done when you are deploying on Prod.
💯 1
a
Thanks
👍 1
d
When I'm correct I need for that a local database? My production database runs in a kubernetes cluster and cannot eb acessed from outside
r
When I’m correct I need for that a local database? My production database runs in a kubernetes cluster and cannot eb acessed from outside
Which command?
a
@Ryan I ran the
migrate dev
on local machine and it worked fine. And on the cloud I ran the
migrate deploy
but it throwed an error
Copy code
3 migrations found in prisma/migrations
94
Error: P3009
r
Do you already have existing data and a migrations table on the cloud?
a
@Ryan This is I had done. The dev env is pointing to localhost DB. localhost machine------> localhost db------ran migrate dev command----> worked fine on local machine. dev env (hosted on cloud)-----> db on cloud----> ran `migrate deploy`command--> thrown the Error: P1001: Can't reach database server at `localhost`:`5432`
r
Seems that the env variable for the DB on cloud is incorrect and still pointing to
localhost
.
Can you check if the env variable is correct?
a
Yes,
.env
was checked into source code by mistake. Just removed it and ran it again. This time it didn't pickup the db URL from git hub actions secrets. We have separate github workflow actions YAML files for dev and qa. In that we have
env:
and a
run: gcloud run deploy
section which accepts env variables. How to make the
DATABASE_URL
in the below snippet to point to the dev URL in dev env and qa URL in qa env? Also should we setup the env
DATABASE_URL
in the docker file as well?
Copy code
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
r
Where are you running
migrate deploy
? In GitHub Actions directly or in the Dockerfile?
a
docker file
r
Are you passing the DB url as an environment variable in your Dockerfile?
a
No. only passing
ENV PATH /app/node_modules/.bin:$PATH
r
You would need to pass the our env variable as an
ARG
in this case:
Copy code
ARG DATABASE_URL
And then while building your image:
Copy code
docker build --build-args DATABASE_URL=${DATABASE_URL} -t image-name .
a
There is also a gcloud run command in the yaml file which also contains env variable as shown below. This is configured to pick up the DATABASE_URL from the github secrets.
Copy code
run: gcloud run deploy $SERVICE_NAME --project ${{ secrets.GCP_DEV_PROJECT_ID }} --set-env-vars DATABASE_URL=${{ secrets.DEV_DATABASE_URL }} --memory 2G --min-instances 1 --image $IMAGE_NAME --region us-west1 --allow-unauthenticated --platform managed
r
So could you echo the env in your Dockerfile and see if it’s available? If not, then it means that it’s not being passed.