i setup a simple docker-compose file for just a pr...
# orm-help
m
i setup a simple docker-compose file for just a prisma2 project, when i run it in the logs I get:
Copy code
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
when i run
dk exec <c_name> npx prisma generate
it says it's ready to use, then I attempt to
dk exec <c_name> npx prisma introspect
and I get
Copy code
`Can't reach database server at `postgres`:`5432
I can confirm the db is working and that without docker the introspection works, ive a volume setup which connects the docker container app folder and the local one, when I change the
prisma/.env
url string to something else and
cat
to ensure it has changed it works but when I run
introspect
in the container again it says that it cannot connect with the default
5432
port even though I changed it
j
Is this the full output you get from
introspect
?
What is you db connection string?
(inside docker)
m
Copy code
DATABASE_URL="<postgresql://user@localhost:5432/db>"

---

# docker exec <c_name> npx prisma introspect

Environment variables loaded from ./prisma/.env

Introspecting based on datasource defined in prisma/schema.prisma …
Error: P1001

Can't reach database server at `postgres`:`5432`

Please make sure your database server is running at `postgres`:`5432`.
I am able to connect to the postgres db through tableplus as well as the same project when running locally without docker
(postgres is dockerized too)
it makes no sense to me that running
introspect
in the container after changing the port in
prisma/.env
results in the same error with the same port even though it's changed which leads me to believe it may be prisma's fault
j
That part was used quite a lot of times already, so I would be surprised šŸ™‚
Give me a min to check sth
Hm, the Postgres error message indeed only includes the host and port - not the full connection string.
But editing the port also changes it in my error message.
m
it does not for me, let me try once again to make sure
Copy code
āÆ dkex back cat prisma/.env
DATABASE_URL="<postgresql://user:secret@localhost:2000/db>"
āÆ dkex back npx prisma introspect
Can't reach database server at `postgres`:`5432`
not quite sure why im getting the initial error on first start of the containers too in my op
j
Is that the full output?
There should be more, like in the snippet above.
m
it is the same as above
1:1
j
Ok, so you copied a modified version here?
Strange - as if it reads the file directly in the command, there is really no way how it could get the wrong information really.
Can you check if
DATABASE_URL
is set manually somehow maybe? (not that it should influence that)
m
šŸ˜…
I had an environment variable in my docker-compose file with a wrong password
DATABASE_URL
it was taking it from there
j
Ha!
šŸš€
m
thank you so much for the help and im sorry for wasting ur time lmao, ur a gem
ā¤ļø 1
j
Still strange that it was using that one, although it said it used the file...
m
yea i was a bit naive to not question that
j
I would have expected the local file to overwrite the value set in the environment.
m
same!
i dont want to say how long I spent trying to figure this out
šŸ˜…
by the way to clarify something related, if I set the db_url in the
.env
which is in the root of my project managed by
dotenv
dep. which would take precedence (could I omit the
prisma/.env
file entirely in that scenario)
j
But I can confirm that behavior and will open a bug issue.
m
much appreciated!
j
Yes,
prisma/.env
is just a default location we read by convention.
You can create the env var whatever way you want.
m
šŸ‘
m
I think a bit more verbose errors would be quite nice when unable to connect to the database because I just ran into the same exact issue, however, this time I'm quite certain that the env var is not being overwritten by anything as it recognizes the changes
and yet I am getting the same exact error despite both containers being on the same network, can connect to each other, url string is correct etc. and its likely something simple im missing again hah
j
Hm, but what could a better error message be?
r
@Max what you can do for the
.env
file is use your general one in your root, put the DB connection string in there and then:
Copy code
cd prisma
ln -s ../.env
That will create a link
prisma/.env
which links to your project
.env
m
@Richard Ward good thinking, thanks!