Skip to content

Instantly share code, notes, and snippets.

@pbdeuchler
Created April 22, 2020 00:34
Show Gist options
  • Save pbdeuchler/79efb5ebc053f891ac6c67051dc6620e to your computer and use it in GitHub Desktop.
Save pbdeuchler/79efb5ebc053f891ac6c67051dc6620e to your computer and use it in GitHub Desktop.
Bootstraps a postgres server with a database and read/write user
#!/bin/bash -eu
# Run command: PROJECT_NAME=test RW_PASSWORD=test HOSTNAME=127.0.0.1 ./psql_bootstrap
psql -h $HOSTNAME --username=postgres -c 'DROP DATABASE IF EXISTS '"${PROJECT_NAME}"';'
psql -h $HOSTNAME --username=postgres -c 'DROP USER IF EXISTS '"${PROJECT_NAME}"'_rw;'
psql -h $HOSTNAME --username=postgres -c 'CREATE DATABASE '"${PROJECT_NAME}"';'
psql -h $HOSTNAME --username=postgres -c 'CREATE USER '"${PROJECT_NAME}"'_rw WITH PASSWORD '"'${RW_PASSWORD}'"';'
psql -h $HOSTNAME --username=postgres -c 'GRANT ALL PRIVILEGES ON DATABASE '"${PROJECT_NAME}"' TO '"${PROJECT_NAME}"'_rw;'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment