Add script to create PostgreSQL user/database.
This commit is contained in:
parent
14b484dd37
commit
b27a553dfb
1 changed files with 24 additions and 0 deletions
24
psql-create-db-user.sh
Executable file
24
psql-create-db-user.sh
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash
|
||||
|
||||
read -rp "Database: " database
|
||||
|
||||
read -rp "User: " user
|
||||
|
||||
read -srp "Password: " password
|
||||
|
||||
echo ""
|
||||
read -rp "Create database $database & user $user? [Y/n]: " answer
|
||||
|
||||
if ! [[ $answer =~ ^(Y|y)?$ ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
stmts=(
|
||||
"CREATE USER $user PASSWORD '$password'"
|
||||
"CREATE DATABASE $database WITH OWNER = $user"
|
||||
"GRANT ALL ON DATABASE $database TO $user"
|
||||
)
|
||||
|
||||
for stmt in "${stmts[@]}"; do
|
||||
docker exec postgres psql -c "$stmt"
|
||||
done
|
Loading…
Reference in a new issue