浏览代码

Move to directory when running postgresql queries

Bob Mottram 7 年前
父节点
当前提交
bca1e90808
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8
    0
      src/freedombone-utils-postgresql

+ 8
- 0
src/freedombone-utils-postgresql 查看文件

@@ -87,6 +87,7 @@ function install_postgresql {
87 87
 function add_postgresql_user {
88 88
     postgresql_username=$1
89 89
     postgresql_password=$2
90
+    cd /etc/postgresql
90 91
     if [[ "$3" != 'encrypt'* ]]; then
91 92
         sudo -u postgres psql -c "create user $postgresql_username password '$postgresql_password';"
92 93
     else
@@ -97,28 +98,33 @@ function add_postgresql_user {
97 98
 
98 99
 function remove_postgresql_user {
99 100
     postgresql_username=$1
101
+    cd /etc/postgresql
100 102
     sudo -u postgres psql -c "drop user $postgresql_username"
101 103
 }
102 104
 
103 105
 function drop_database_postgresql {
104 106
     database_name="$1"
107
+    cd /etc/postgresql
105 108
     sudo -u postgres psql -c "drop database $database_name"
106 109
 }
107 110
 
108 111
 function run_system_query_postgresql {
109 112
     query=$1
113
+    cd /etc/postgresql
110 114
     sudo -u postgres psql -c "$query"
111 115
 }
112 116
 
113 117
 function run_query_postgresql {
114 118
     database_name=$1
115 119
     database_query=$2
120
+    cd /etc/postgresql
116 121
     sudo -u postgres psql -d $database_name -c "$database_query"
117 122
 }
118 123
 
119 124
 function run_query_postgresql_with_output {
120 125
     database_name=$1
121 126
     database_query=$2
127
+    cd /etc/postgresql
122 128
     output=$(sudo -u postgres psql -d $database_name -c << EOF
123 129
 $database_query
124 130
 EOF
@@ -129,6 +135,7 @@ EOF
129 135
 function initialise_database_postgresql {
130 136
     database_name=$1
131 137
     database_file=$2
138
+    cd /etc/postgresql
132 139
     sudo -u postgres psql $database_name < $database_file
133 140
     if [ ! "$?" = "0" ]; then
134 141
         exit 7238525
@@ -152,6 +159,7 @@ GRANT ALL PRIVILEGES ON ${app_name}.* TO '$app_admin_username@localhost';
152 159
 flush privileges;
153 160
 quit" > $INSTALL_DIR/batch.sql
154 161
     chmod 600 $INSTALL_DIR/batch.sql
162
+    cd /etc/postgresql
155 163
     sudo -u postgres psql -d $database_name --file=$INSTALL_DIR/batch.sql
156 164
     shred -zu $INSTALL_DIR/batch.sql
157 165
 }