Prisma not connecting to DB in amplify
Hey guys so i got the following schema
and in one of my api endpoints i am doing
this works perfectly locally and nothing goes wrong but then when i pushed it to prod i kept getting
Internal Server Error
I added a try catch block to see what the error is and it gave me {"error":{"clientVersion":"4.7.1"}}
I dont know what im doing wrong. any ideas?98 Replies
well, from the looks of the query, it either doesn't find a corresponding user or a corresponding model entries by the id you provide
im using the same exact post request just changed the url
it works locally (the db is connected to supabase)
but i see what you mean
not sure how it cant find a corresponding user
nor model
could you share your error handling code?
I'd also check your env variables for connections to make sure it all is connected properly
https://supabase.com/docs/guides/integrations/prisma#step-2-testing-the-connection
also i'd look in https://www.prisma.io/docs/guides/database/supabase
it is just a try and catch block
ill have a look at this
i do have a feeling its not connecting
yeah, probably
thanks gonna have a look i na second
wait so i cant have more than 1 connection to the db?
so i have to use pgbouncer ?
Could be, there's a section on it in the supabase's docs
yep
it looks like it
are you doing serverless?
yes
yeah, in that case you'll need either somehow close each connection (but it's not really optimal at all with prisma) after calling the functions, or use some sort of proxy pooling - https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/connection-pool
https://www.prisma.io/docs/guides/performance-and-optimization/connection-management#serverless-environments-faas
this looks promising
https://www.prisma.io/data-platform/proxy
it has a free tier
ok i see
i need to update my prisma to a version higher than 4.10
for the directUrl Feature
wonder if that would break anything
honestly might just use planetscale
well im using planetscale
and im still getting the same issue
so i think its just simply not connecting
Just update it, it shouldn't break anything
just did
still not working
prisma isnt connecting
to the db
now i have no clue why
i renamed the question
its building
the build process goes through
no errors at all
then when it comes to mutating
just errors
bump
??
how
im boughta just hardcode that value fuck env vars in AWS
bump
i already have it there
retry npx prisma generate
or double check for the variable and syntax (maybe try quotes or remove quotes if they are there)
so after i build i try npx prisma generate
or
before build
I do before build
cause from my understanding it does it in the build
in my scripts in package.json i have
"build": "prisma generate && next build",
sorry if not much help, as I never yet used Amplify
very much understandable thank you for atleast trying
aws is too confusing for me lol
π
vercel uses AWS
idk what they did to make this black magic work
yeah, and they very nicely abstract all of the dumb stuff
more like
bs stuff
i suppose having a lot of staff helps lol
maybe try adding a .env file ?
or you could do something like this in the build script for amplify
even maybe
but obv replace values for prisma
https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html#access-env-vars
ive done those as well
ok so when i did npx db-generate i got env errors
and i fixed those now
i wasnt getting them when building
but now its still not FUCKING recognizing the env var in runtime
dang it, roll back bro
to where
to when it didn't give errors with db-generate
There is no errors anymore
I fixed it
Let it be known im still getting env var not defined in runtime
But not build
try removing the query and console.log the env var somewhere?
what query
ill try and log it
ok i just console log the var
and its fucking there
ITS THERE
but in prisma ITS NOT
>?????
so there you go, it's prisma's fault, try adding to the node build script 'prisma generate', maybe somehow the client (prisma client) doesn't see the var
so i did some digging
prisma is trying to look for a .env file
but there is no .env file
even tho i specified it
you could possibly just make one?
can i?
or it's ignored by git or something
ofc its ignored
how do you get your files to amplify?
git
from git? then it doesn't pull it
yeah
git clones
then it uses the env vars i specificed in AWS
you need to make a '.env' file and set it's contents from your AWS env vars as part of your building script
like the 'toml' script or whatnot
thats what
- echo "DATABASE_URL=$DATABASE_URL" >> .env
is for no?or yaml
yeah
yeah
im doing that
try with one >
echo "DATABASE_URL=$DATABASE_URL" > .env
idk should do it
maybe put it befor npm run build
im doing it all at once π
what's your build step in the script?
what does the arrow mean?
put 'echo's return into the file
so put "DATABASE_URL=$DATABASE_URL" in the file
and what does your db-generate look like in your package.json?
it generates
just fine
pushes just fine
ok I think i got something, I think it's not sending it to the proper place? can you look through the files in prod?
like find where it generated this .env file?
im not sure i f i can do that
thats what im tryna figure out
cause it says
baseDirectory: apps/nextjs/.next
the db wouldnt generate nore push if the .env doesnt exist
so it is going through
but then after the build it doesnt
not sure, cause it has this with-env arg
let me see rq
try echo "DATABASE_URL=$DATABASE_URL" >> ../.env
i guess it's not getting the correct .env π¦ for prisma client
yeah :/
Or try echo ... >> ../../.env
thats what i just had
ill try it again
should i do it
before build
or after
Before I think
ok
nope
my sanity
im losing it
im losing it
Go take a breezer man
no
i need to fix this
It's important to stay
i was meant to deploy this last week
Do you have logs of building process? Could you find the place where it generates prisma client?
You could also try to eche into .env file inside prisma folder, where you have schema before build time
oh yeahh
i can try and echo the .env into the prisma couldnt i
Yeah it's a possibility
But need to find prisma
Looks like the build path is actually "/" so no need for ../.. before .env
how so
In your yaml file
Beforelast line
It's just some thoughts
where
what
SST
Configure AWS Amplify
We are going to use the information of our AWS resources to configure AWS Amplify in our React app. We'll call the Amplify.configure() method when our app first loads.
maybe i will admit defeat now
but one day
ill comeback to amplify
and try and do it
without sst
Bezos should burn lol
agreed
Sorry bro, as I said, I don't much use Amplify (not at all actually) and couldn't help out much
totally valid i dont blame u
We tried though
If you do manage to fix it, tell me, cause I'm intrigued lol
Or if you have more questions, I'll try to help as well
π π π π
forsure man
i will try my very best
might make a issue
in the prisma repo
guess what i just found
GitHub
turbo/examples/with-prisma at main Β· vercel/turbo
Incremental bundler and build system optimized for JavaScriptΒ and TypeScript, written in Rust β including Turbopack and Turborepo. - turbo/examples/with-prisma at main Β· vercel/turbo
Is it much different from yours?
no
thats the same file structure
im pushing
pray with me please
π
it didnt work
man
dfhskljsdhgfijnbsdgf njkosdfgh sdfhglkmn;sdfhgl;mkhdfg
Sorry chief
no need to say sorry its not ur fault
i opened a github issue at prisma
hopefully someone answers
https://github.com/prisma/prisma/discussions/20116
OKAYY I FIXED IT
LETS GOOO
GitHub
DATABASE_URL not found in Amplify Β· prisma prisma Β· Discussion #201...
I have the current Turborepo setup https://github.com/t3-oss/create-t3-turbo/tree/main I am trying to deploy to AWS Amplify but i am having issues with env vars specifically the DATABASE_URL. I fol...
Let's go! Good job, chief