@@ -137,6 +137,32 @@ brew "redis", restart_service: :changed
137137tap "mongodb/brew"
138138EOF
139139
140+ if ! command -v psql > /dev/null ; then
141+ fancy_echo " psql command does not exist, making it available in this session ...\n"
142+
143+ echo " To persist the changes, add these commands to your .zshrc:"
144+ echo " export PATH=\"\$ HOMEBREW_PREFIX/opt/postgresql@18/bin:\$ PATH\" "
145+ echo " export PATH=\"\$ HOMEBREW_PREFIX/bin:\$ PATH\" "
146+
147+ export PATH=" $HOMEBREW_PREFIX /opt/postgresql@18/bin:$PATH " # Adds psql, initdb, createdb, etc. to PATH
148+ export PATH=" $HOMEBREW_PREFIX /bin:$PATH " # Adds psql-18, initdb-18, createdb-18, etc. to PATH
149+ # FYI: /opt/homebrew/bin/psql-18 (symlink) -> /opt/homebrew/Cellar/postgresql@18/18.1_1/bin/psql
150+ fi
151+
152+ # https://stackoverflow.com/questions/17633422/psql-fatal-database-user-does-not-exist/17936043#17936043
153+ # psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "$USER" does not exist
154+ #
155+ # Check to see whether 'psql' succeeds
156+ if ! psql -c " SELECT 1;" > /dev/null 2>&1 ; then
157+ fancy_echo " Creating a missing '$USER ' db in Postgres ..."
158+
159+ createdb # Creates a db w/ a name & owner equal to "$USER"
160+ psql -l # Displays available databases
161+
162+ fancy_echo " Checking to see whether 'psql' succeeds now ..."
163+ psql -c " SELECT 1;" > /dev/null 2>&1 && echo " yes" || echo " no"
164+ fi
165+
140166if ! brew list -1 | grep mongodb-community ; then
141167 brew install mongodb-community
142168fi
0 commit comments