Created
February 17, 2017 01:51
-
-
Save digi9ten/65d07a42233502114aa7757be6e602bb to your computer and use it in GitHub Desktop.
For Kong users, on Postgres. Checks if the postgres DB exists, then creates it if need be. Creates a pgpass file for the ec2-user, just in case.
This file contains 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
function setup_database_if_needed { | |
## | |
## Since Kong does not actually create the DB automatically, we need to do that here... | |
## | |
if [ ! -f ~/.pgpass ]; then | |
echo "*:*:*:${KONG_RDS_USER}:${KONG_RDS_PASS}" | tee -a ~/.pgpass | |
chmod 0600 ~/.pgpass | |
fi | |
does_db_exist=$(psql -lqt -h ${KONG_RDS_ENDPOINT} -U ${KONG_RDS_USER} | cut -d \| -f 1 | grep -c ${KONG_RDS_DB_NAME}) | |
if [ 0 -eq $does_db_exist ]; then | |
createdb -h ${KONG_RDS_ENDPOINT} -U ${KONG_RDS_USER} ${KONG_RDS_DB_NAME} | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment