steebchen / prisma-client-go

Prisma Client Go is an auto-generated and fully type-safe database client
https://goprisma.org
Apache License 2.0
2.09k stars 94 forks source link

env("DATABASE_URL") different in CLI and app #1254

Open munxar opened 4 months ago

munxar commented 4 months ago

Hello

I tried to follow the quickstart at https://goprisma.org/docs/getting-started/quickstart (manual setup). If I follow all the steps like written, it works as described. Now I changed the datasource in the prisma/schema.prisma to use the env variable like

datasource db {
  provider = "sqlite"
  //url = "file:data.sqlite"
  url      = env("DATABASE_URL")
}
...

I have a .env file in the project root with the content:

DATABASE_URL="file:data.sqlite"

then run the usual command to regen the client go run github.com/steebchen/prisma-client-go db push (no error)

note: it creates the sqlite file in prisma/data.sqlite.

Now when I run the app with go run . I get a panic with

panic: user facing error: The table `main.Post` does not exist in the current database.

Note: It creates a sqlite file at project root data.sqlite that is fresh and not migrated. When I set the env variable with DATABASE_URL=prisma/file:data.sqlite go run .

it works as expected, but is a different path than set in .env.

How can I make this work, so that the prisma cli and my app use the same path? I'd love to use the .env file in my main go with something like (github.com/joho/godotenv) but if the path is different, I'll have a hard time.

AFAIK the js implementation always makes the path relative to the schema.prisma.

Thank you.

steebchen commented 4 months ago

Thanks for the info, hmm this should have been fixed via #1059... I'm assuming you are running the latest Go client version? Then I'll have to look into it again

munxar commented 4 months ago

here are the versions: go version go1.22.1 darwin/arm64 and github.com/steebchen/prisma-client-go v0.36.0