summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--README.md20
-rw-r--r--temp-postgres.120
-rwxr-xr-xtemp-postgres.sh17
4 files changed, 44 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e06782a..c39b236 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ The format is based on [Keep A Changelog][] and this project adheres to [Semanti
### Added
* Added option to execute a given command when PostgreSQL server is ready
+* Added `--symlink` option to enable static client configuration
* Added minimal `--help` option
* Added changelog
* Added experimental Nix flake
diff --git a/README.md b/README.md
index 92990f5..51ccdc8 100644
--- a/README.md
+++ b/README.md
@@ -13,12 +13,6 @@ Create and serve a temporary database:
temp-postgres
```
-Specify a database name, and PostgreSQL user name:
-
-```sh
-temp-postgres --dbname myproject --username alex
-```
-
Wrap the `psql` command to connect to the temporary database once the server is ready:
```sh
@@ -44,6 +38,20 @@ platform = { host = 'cfg(unix)' }
run-wrapper = 'temp-postgres'
```
+Set up a symlink to enable static client configuration:
+
+```sh
+temp-postgres --symlink ./db
+psql --host "$(realpath ./db)"
+```
+
+Specify a database name, and PostgreSQL user name:
+
+```sh
+temp-postgres --dbname myproject --username alex
+```
+
+
See the manual page for details.
## Dependencies
diff --git a/temp-postgres.1 b/temp-postgres.1
index 324a2f1..94f13cd 100644
--- a/temp-postgres.1
+++ b/temp-postgres.1
@@ -69,19 +69,25 @@ and the
.Sh EXAMPLES
Create and serve a temporary database:
.Bd -literal -offset indent
-$ temp-postgres
-.Ed
-.Pp
-Specify a database name, and PostgreSQL user name:
-.Bd -literal -offset indent
-$ temp-postgres --dbname myproject --username alex
+temp-postgres
.Ed
.Pp
Wrap the
.Xr psql 1
command to connect to the temporary database once the server is ready:
.Bd -literal -offset indent
-$ temp-postgres -- psql
+temp-postgres -- psql
+.Ed
+.Pp
+Set up a symlink to enable static client configuration:
+.Bd -literal -offset indent
+temp-postgres --symlink ./db
+psql --host "$(realpath ./db)"
+.Ed
+.Pp
+Specify a database name, and PostgreSQL user name:
+.Bd -literal -offset indent
+temp-postgres --dbname myproject --username alex
.Ed
.Sh SEE ALSO
.Xr postgres 1 ,
diff --git a/temp-postgres.sh b/temp-postgres.sh
index 8504257..96f90d2 100755
--- a/temp-postgres.sh
+++ b/temp-postgres.sh
@@ -26,6 +26,10 @@ quit() {
( >&2 printf "temp-postgres: failed to remove temporary directory: %s\\n" "${tmpdir}" )
[ "${code}" -ne 0 ] || code=1
}
+ [ -z "${symlink:-}" ] || ! [ -L "$symlink" ] || unlink "$symlink" || {
+ ( >&2 printf "temp-postgres: failed to unlink %s\\n" "$symlink" )
+ [ "${code}" -ne 0 ] || code=1
+ }
exit "${code}"
}
@@ -35,7 +39,7 @@ username="$( id -un )"
while [ $# -gt 0 ] ; do
case "$1" in
-h|--help)
- echo "Usage: temp-postgres [-h|--help] [-d|--dbname <dbname>] [-u|--username <username>] [--] [<command>]"
+ echo "Usage: temp-postgres [-h|--help] [-d|--dbname <dbname>] [-u|--username <username>] [--symlink <path>] [--] [<command>]"
exit
;;
-d|--dbname)
@@ -46,6 +50,10 @@ while [ $# -gt 0 ] ; do
username="$2"
shift 2
;;
+ --symlink)
+ symlink="$2"
+ shift 2
+ ;;
--)
shift
break
@@ -89,6 +97,13 @@ createdb --host="${tmpdir}" --username="${username}" --no-password "${dbname}" |
quit 1
}
+if [ -n "${symlink:-}" ] ; then
+ ln -sf "${tmpdir}" "$symlink" || {
+ ( >&2 printf "temp-postgres: failed to create symlink %s\\n" "$symlink" )
+ quit 1
+ }
+fi
+
printf '
Connect with the following command:
Generated by cgit. See skreutz.com for my tech blog and contact information.