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 PGHOST=/tmp
|
||||||
export DB_LOG=$PROJECT_ROOT_DIR/.db/log
|
export DB_LOG=$PROJECT_ROOT_DIR/.db/log
|
||||||
|
|
||||||
if [ ! -d "$PGDATA" ]; then
|
start_db() {
|
||||||
initdb "$PGDATA" --auth=trust
|
if [ ! -d "$PGDATA" ]; then
|
||||||
fi
|
initdb "$PGDATA" --auth=trust
|
||||||
|
fi
|
||||||
|
|
||||||
if ! pg_ctl status >/dev/null; then
|
if ! pg_ctl status >/dev/null; then
|
||||||
pg_ctl start -l "$DB_LOG" -o "-c unix_socket_directories=$PGHOST"
|
pg_ctl start -l "$DB_LOG" -o "-c unix_socket_directories=$PGHOST"
|
||||||
echo "starting your dev database..."
|
echo "starting your dev database..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
user_exists=$(psql --csv -t -d postgres -c "SELECT count(*) FROM pg_user WHERE usename='postgres'")
|
user_exists=$(psql --csv -t -d postgres -c "SELECT count(*) FROM pg_user WHERE usename='postgres'")
|
||||||
if [ "$user_exists" != "1" ]; then
|
if [ "$user_exists" != "1" ]; then
|
||||||
createuser -s -h "$PGHOST" postgres
|
createuser -s -h "$PGHOST" postgres
|
||||||
fi
|
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