Created
September 25, 2024 13:37
-
-
Save arkadius/652d911ec4394e6b974bcbbae0dcc532 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
RESULT=$(psql -tc "SELECT 1 FROM pg_database WHERE datname = '$DB';") | |
if [ -z "$RESULT" ]; then | |
echo "Database $DB does not exist. Creating..." | |
psql -v ON_ERROR_STOP=1 <<-EOSQL | |
CREATE USER $USER WITH ENCRYPTED PASSWORD '$PASSWORD'; | |
CREATE DATABASE $DB; | |
ALTER DATABASE $DB OWNER TO $USER; | |
EOSQL | |
else | |
echo "Database $DB already exists." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment