Skip to content

Commit 717ce60

Browse files
authored
Create a missing db in Postgres (#6)
1 parent fab4e23 commit 717ce60

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

mac

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,32 @@ brew "redis", restart_service: :changed
137137
tap "mongodb/brew"
138138
EOF
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+
140166
if ! brew list -1 | grep mongodb-community ; then
141167
brew install mongodb-community
142168
fi

0 commit comments

Comments
 (0)