Created
March 17, 2021 05:59
-
-
Save kumaraswins/186e9c7dd9ff4c9f326cb1d8eeb0c9e9 to your computer and use it in GitHub Desktop.
Bash for psql
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 | |
| echo "Please enter the database name" | |
| read DB_NAME | |
| echo "Please enter the database password" | |
| read DB_PASSWORD | |
| sudo su postgres <<EOF | |
| psql -c 'CREATE DATABASE ${DB_NAME};' | |
| psql -c "CREATE ROLE ${DB_NAME} WITH LOGIN PASSWORD 'password';" | |
| psql -c 'GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_NAME};' | |
| psql -c 'ALTER ROLE ${DB_NAME} CREATEDB;' | |
| psql -c 'ALTER ROLE ${DB_NAME} WITH LOGIN;' | |
| EOF | |
| echo "Created database $DB_NAME and user $DB_NAME" | |
| echo "------------- Creating environment -----------" | |
| echo -e "DEBUG=on\nDJANGO_DEBUG=True\[email protected]\nSECRET_KEY=WLPxHX7XqSnutd8JpLvwhaEu86294Qp5HDxaYA2smkqDqAyOuwpjLMJjf6fKJCHU\nDATABASE_HOST=localhost\nDB_NAME=$DB_NAME\nDB_USER=$DB_NAME\nDB_PASSWORD=$DB_PASSWORD" >> local.env | |
| echo END | |
| echo -------------------------------------------------- | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment