Move to directory when running postgresql queries
This commit is contained in:
parent
4ca61f2aac
commit
bca1e90808
|
@ -87,6 +87,7 @@ function install_postgresql {
|
|||
function add_postgresql_user {
|
||||
postgresql_username=$1
|
||||
postgresql_password=$2
|
||||
cd /etc/postgresql
|
||||
if [[ "$3" != 'encrypt'* ]]; then
|
||||
sudo -u postgres psql -c "create user $postgresql_username password '$postgresql_password';"
|
||||
else
|
||||
|
@ -97,28 +98,33 @@ function add_postgresql_user {
|
|||
|
||||
function remove_postgresql_user {
|
||||
postgresql_username=$1
|
||||
cd /etc/postgresql
|
||||
sudo -u postgres psql -c "drop user $postgresql_username"
|
||||
}
|
||||
|
||||
function drop_database_postgresql {
|
||||
database_name="$1"
|
||||
cd /etc/postgresql
|
||||
sudo -u postgres psql -c "drop database $database_name"
|
||||
}
|
||||
|
||||
function run_system_query_postgresql {
|
||||
query=$1
|
||||
cd /etc/postgresql
|
||||
sudo -u postgres psql -c "$query"
|
||||
}
|
||||
|
||||
function run_query_postgresql {
|
||||
database_name=$1
|
||||
database_query=$2
|
||||
cd /etc/postgresql
|
||||
sudo -u postgres psql -d $database_name -c "$database_query"
|
||||
}
|
||||
|
||||
function run_query_postgresql_with_output {
|
||||
database_name=$1
|
||||
database_query=$2
|
||||
cd /etc/postgresql
|
||||
output=$(sudo -u postgres psql -d $database_name -c << EOF
|
||||
$database_query
|
||||
EOF
|
||||
|
@ -129,6 +135,7 @@ EOF
|
|||
function initialise_database_postgresql {
|
||||
database_name=$1
|
||||
database_file=$2
|
||||
cd /etc/postgresql
|
||||
sudo -u postgres psql $database_name < $database_file
|
||||
if [ ! "$?" = "0" ]; then
|
||||
exit 7238525
|
||||
|
@ -152,6 +159,7 @@ GRANT ALL PRIVILEGES ON ${app_name}.* TO '$app_admin_username@localhost';
|
|||
flush privileges;
|
||||
quit" > $INSTALL_DIR/batch.sql
|
||||
chmod 600 $INSTALL_DIR/batch.sql
|
||||
cd /etc/postgresql
|
||||
sudo -u postgres psql -d $database_name --file=$INSTALL_DIR/batch.sql
|
||||
shred -zu $INSTALL_DIR/batch.sql
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue