Hi guys,can i host prisma in digital ocean(dokku)....
# orm-help
a
Hi guys,can i host prisma in digital ocean(dokku).If i can,how ? There isn't any tutorial
r
@alisalimli 👋 I don’t think there’s any tutorial for Dokku and I haven’t worked with it but if it’s simply creating a Docker image of the application, then you could do that and it should work out of the box 🙂
a
i'm doing,but prisma doesn't apply tables to database.Do you wanna check out my source code ?
r
Yeah sure
a
when i run docker image locally,prisma works.But when i deploy it gives me the following error :
The table
public.user
does not exist in the current database
i don't know why prisma doesn't apply it when i deploy
r
Is your development and production database different? If so, then you need to run
prisma migrate deploy
in your
Dockerfile
so that the changes are applied on the production database.
a
yeah,they are different
should i copy "prisma/migrations"
r
Yes. Copy the entire
prisma
folder and then run
prisma migrate deploy
Make sure the environment variable points to your production database.
a
yeah,i have .env.prod
for creating "prisma/migrations" should i use "prisma migrate dev"
and that will create migrations for me,finally i copy it and push to database by running prisma migrate deploy
is it right ?
r
Yes 💯
a
and i one more thing,should i use prisma generate after prisma migrate deploy or before ?
r
prisma migrate deploy
automatically runs generate if I’m not wrong. You can check that out and if it doesn’t, you can add it after deploy.
a
i tried without
prisma generate
but it gived me error : run prisma generate.Now i am trying with prisma generate
👍 1
i did everything you told,i run
npx prisma migrate dev
and it worked in locally.Then i add 'npx prisma migrate deploy and npx prisma generate' to Dockerfile.Actually migrates applied successfully,when i access the production database,i saw tables are created.Then i deployed app,i run a the following graphql query:
query { allUsers { id } }
It gives me the following error again -> The table
public.user
does not exist in the current database.
if you want you can also try here : http://164.90.169.15/graphql
r
Check if the database URL is the same on which you ran
prisma migrate deploy
.
a
it's same
i created a new database
and there wasn't any tables,then i build docker image.It run "npx prisma migrate deploy" and "npx prisma generate" stuffs,then i checked the database again and see that tables created successfully.
but when i deploy my code to dokku,it's giving me same error ->The table
public.user
does not exist in the current database
but when i test my production database in locally,it did not give me that error
what you think ?
r
I’m not sure. The only thing that comes to mind is an incorrect env variable, maybe pointing to another database. I would need to check your setup.
a
i console.log the env variables and all of them is correct
in production
btw i tried new database,,but it's giving same error
oh man
you were right
i am totally stupid
know it's working
r
What was the issue?
a
i am using dokku,first i created database in dokku.But then i realized dokku's postgres only work in my virtual machine(digital ocean).Then i switch to Azure.But i wasn't remove the DATABASE_URL variable which dokku set.I log the env and see it's not azure one
💯 1
You were right,it was related to env variable
thank you again
🙌 1
in typeorm you can run migrations in your code
can i do something similar in prisma ?
because i can only access postgres database in virtual machine
so i can apply migrations in there
r
You cannot run migrations in code directly as of now. We do have a feature request here so it would be great if you could add a 👍 so that we can know the priority. As a workaround, you can use
exec
to achieve the same:
Copy code
const util = require('util')
const exec = util.promisify(require('child_process').exec)

await exec('npx prisma migrate deploy')
❤️ 1
👍🏼 1