Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
munxar opened this issue Apr 25, 2024 · 2 comments
Open

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

munxar opened this issue Apr 25, 2024 · 2 comments

Comments

@munxar
Copy link

munxar commented Apr 25, 2024

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.

@munxar munxar changed the title panic: user facing error: The table main.Post does not exist in the current database. env("DATABASE_URL") different in CLI and app Apr 25, 2024
@steebchen
Copy link
Owner

steebchen commented Apr 25, 2024

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
Copy link
Author

munxar commented Apr 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants