tk0miya / testing.postgresql

Apache License 2.0
290 stars 46 forks source link

postgresql bin path discovery #13

Closed ju2wheels closed 7 years ago

ju2wheels commented 7 years ago

Hi, im submitting a PR to add RHEL/CentOS path but opening an issue because I think it would be good to reconsider how this implemented.

Right now its searching a bunch of paths for the postgresql binaries, but as you are already seeing hard coding these paths is not a good idea because it can vary.

On top of the bin dir being in different places, if you take the approach of "lets search for the first bin dir we can find", then we as testers have no control over which postgresql version gets used.

Your current implementation kind of makes the assumption that theres only one postgresql version per system which is not always true. For example, im working in CentOS 7 and if I install postgresql from the standard RHEL repo its at 9.2. However, I need to use 9.5 for testing because it has newer features I need, so I add the postgresql yum repo and install 9.5 (this can be done along side 9.2 without having to uninstall it). Now if I have both installed, how do I tell testing.postgresql which to choose?

I have submitted the patch in the current style but I would recommend it be changed in the future to use os.environ['PATH'] instead so we can just put the path to the postgresql bin dir that we want into the beginning of our PATH and you dont have to search for the directory, you just always execute the version found first in PATH.

I havent read through all the code but if its not only the bin dir we need then maybe have it look for PG_HOME env var or something if you also need the other postgresql folders relative to this.