theseus-rs / postgresql-embedded

Embed PostgreSQL database
Apache License 2.0
34 stars 5 forks source link

Database management commands fail if PGDATABASE set in environment #75

Closed fiadliel closed 3 weeks ago

fiadliel commented 3 weeks ago

I'm not sure if you want to ascribe this as "fix your environment", but if PGDATABASE is set in the environment (to anything other than postgres), the database creation commands fail, as psql connects to a database that doesn't exist.

Error: Command error: stdout=; stderr=psql: error: connection to server at "localhost" (::1), port 58453 failed: FATAL:  database "xxx" does not exist

One option might be to explicitly set the database to postgres when running database management commands.

brianheineman commented 3 weeks ago

Hello @fiadliel, thank you for reporting this issue. While PostgreSQL is running in another process, the aim of this project is to try to provide an "embedded-like" experience for users. I made some changes in #76 that should address this problem and added a regression test to try to reproduce/verify the fix.

brianheineman commented 3 weeks ago

The changes for #76 have been released in 0.10.2

fiadliel commented 3 weeks ago

Fixed in my test! (the scenario was that PGDATABASE was used when running programs interactively, but I was investigating using this library to set up some integration tests). Very quick fix, thanks a lot :)