nix: improve prymn_db script, adding a 'shell' command
This commit is contained in:
parent
818b20f775
commit
62c40358a2
1 changed files with 25 additions and 11 deletions
|
@ -15,19 +15,33 @@
|
|||
export PGHOST=/tmp
|
||||
export DB_LOG=$PROJECT_ROOT_DIR/.db/log
|
||||
|
||||
if [ ! -d "$PGDATA" ]; then
|
||||
initdb "$PGDATA" --auth=trust
|
||||
fi
|
||||
start_db() {
|
||||
if [ ! -d "$PGDATA" ]; then
|
||||
initdb "$PGDATA" --auth=trust
|
||||
fi
|
||||
|
||||
if ! pg_ctl status >/dev/null; then
|
||||
pg_ctl start -l "$DB_LOG" -o "-c unix_socket_directories=$PGHOST"
|
||||
echo "starting your dev database..."
|
||||
fi
|
||||
if ! pg_ctl status >/dev/null; then
|
||||
pg_ctl start -l "$DB_LOG" -o "-c unix_socket_directories=$PGHOST"
|
||||
echo "starting your dev database..."
|
||||
fi
|
||||
|
||||
user_exists=$(psql --csv -t -d postgres -c "SELECT count(*) FROM pg_user WHERE usename='postgres'")
|
||||
if [ "$user_exists" != "1" ]; then
|
||||
createuser -s -h "$PGHOST" postgres
|
||||
fi
|
||||
user_exists=$(psql --csv -t -d postgres -c "SELECT count(*) FROM pg_user WHERE usename='postgres'")
|
||||
if [ "$user_exists" != "1" ]; then
|
||||
createuser -s -h "$PGHOST" postgres
|
||||
fi
|
||||
}
|
||||
|
||||
command="''${1-default}"
|
||||
case $command in
|
||||
shell)
|
||||
psql -U postgres
|
||||
exit 0
|
||||
;;
|
||||
start | default | *)
|
||||
start_db
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue