Alon Bar-Lev has uploaded a new change for review.

Change subject: db: add create_schema to allow unprivileged schema creation
......................................................................

db: add create_schema to allow unprivileged schema creation

This will enable user to create his own database and user, and still use
the installer, without having privileged user credentials.

Change-Id: I32c24e9e7a516c2c96814f7b723b98aab644ac57
Signed-off-by: Alon Bar-Lev <alo...@redhat.com>
---
M backend/manager/dbscripts/create_db.sh
A backend/manager/dbscripts/create_schema.sh
2 files changed, 76 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/12948/1

diff --git a/backend/manager/dbscripts/create_db.sh 
b/backend/manager/dbscripts/create_db.sh
index a116b86..3a28160 100755
--- a/backend/manager/dbscripts/create_db.sh
+++ b/backend/manager/dbscripts/create_db.sh
@@ -52,31 +52,12 @@
       popd>/dev/null
       exit 1;
 fi
-createlang --host=${SERVERNAME} --port=${PORT} --dbname=${DATABASE} --echo 
--username=${USERNAME} plpgsql >& /dev/null
-#set database min error level
-CMD="ALTER DATABASE \"${DATABASE}\" SET client_min_messages=ERROR;"
-execute_command "${CMD}"  ${DATABASE} ${SERVERNAME} ${PORT}> /dev/null
 
-echo user name is: ${USERNAME}
-
-printf "Creating tables...\n"
-execute_file "create_tables.sql" ${DATABASE} ${SERVERNAME} ${PORT} > /dev/null
-
-printf "Creating functions...\n"
-execute_file "create_functions.sql" ${DATABASE} ${SERVERNAME} ${PORT} > 
/dev/null
-
-printf "Creating common functions...\n"
-execute_file "common_sp.sql" ${DATABASE} ${SERVERNAME} ${PORT} > /dev/null
-
-#inserting initial data
-insert_initial_data
-
-#remove checksum file in clean install in order to run views/sp creation
-rm -f .${DATABASE}.scripts.md5 >& /dev/null
-
-# Running upgrade scripts
-printf "Running upgrade scripts...\n"
-run_upgrade_files
+if ! ./create_schema.sh -s "${SERVERNAME}" -p "${PORT}" -d "${DATABASE}" -u 
"${USERNAME}" -l "${LOGFILE}"; then
+      printf "Failed to create schema for database ${DATABASE}\n"
+      popd>/dev/null
+      exit 1;
+fi
 
 popd>/dev/null
 exit $?
diff --git a/backend/manager/dbscripts/create_schema.sh 
b/backend/manager/dbscripts/create_schema.sh
new file mode 100755
index 0000000..6a94016
--- /dev/null
+++ b/backend/manager/dbscripts/create_schema.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+#include db general functions
+pushd $(dirname ${0})>/dev/null
+source ./dbfunctions.sh
+source ./dbcustomfunctions.sh
+
+#setting defaults
+set_defaults
+
+usage() {
+    printf "Usage: ${ME} [-h] [-s SERVERNAME [-p PORT]] [-d DATABASE] [-u 
USERNAME] [-l LOGFILE] [-v]\n"
+    printf "\n"
+    printf "\t-s SERVERNAME - The database servername for the database  (def. 
${SERVERNAME})\n"
+    printf "\t-p PORT       - The database port for the database        (def. 
${PORT})\n"
+    printf "\t-d DATABASE   - The database name                         (def. 
${DATABASE})\n"
+    printf "\t-u USERNAME   - The admin username for the database.\n"
+    printf "\t-l LOGFILE    - The logfile for capturing output          (def. 
${LOGFILE})\n"
+    printf "\t-v            - Turn on verbosity                         
(WARNING: lots of output)\n"
+    printf "\t-h            - This help text.\n"
+    printf "\n"
+    popd>/dev/null
+    exit $ret
+}
+
+DEBUG () {
+    if $VERBOSE; then
+        printf "DEBUG: $*"
+    fi
+}
+
+while getopts :hs:d:u:p:l:f:v option; do
+    case $option in
+        s) SERVERNAME=$OPTARG;;
+        p) PORT=$OPTARG;;
+        d) DATABASE=$OPTARG;;
+        u) USERNAME=$OPTARG;;
+        l) LOGFILE=$OPTARG;;
+        v) VERBOSE=true;;
+        h) ret=0 && usage;;
+       \?) ret=1 && usage;;
+    esac
+done
+
+createlang --host=${SERVERNAME} --port=${PORT} --dbname=${DATABASE} --echo 
--username=${USERNAME} plpgsql >& /dev/null
+#set database min error level
+CMD="ALTER DATABASE \"${DATABASE}\" SET client_min_messages=ERROR;"
+execute_command "${CMD}"  ${DATABASE} ${SERVERNAME} ${PORT}> /dev/null
+
+echo user name is: ${USERNAME}
+
+printf "Creating tables...\n"
+execute_file "create_tables.sql" ${DATABASE} ${SERVERNAME} ${PORT} > /dev/null
+
+printf "Creating functions...\n"
+execute_file "create_functions.sql" ${DATABASE} ${SERVERNAME} ${PORT} > 
/dev/null
+
+printf "Creating common functions...\n"
+execute_file "common_sp.sql" ${DATABASE} ${SERVERNAME} ${PORT} > /dev/null
+
+#inserting initial data
+insert_initial_data
+
+#remove checksum file in clean install in order to run views/sp creation
+rm -f .${DATABASE}.scripts.md5 >& /dev/null
+
+# Running upgrade scripts
+printf "Running upgrade scripts...\n"
+run_upgrade_files
+
+popd>/dev/null
+exit $?


--
To view, visit http://gerrit.ovirt.org/12948
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I32c24e9e7a516c2c96814f7b723b98aab644ac57
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to