Alex Lourie has uploaded a new change for review.

Change subject: packaging: setup: update reports DB schema on major release 
upgrade
......................................................................

packaging: setup: update reports DB schema on major release upgrade

This addition is required because there is a major schema change
introduced by Jasper Server in 5.5 compared to 4.7; this is needed
for correct operation of export/import functionality.

Change-Id: I0f2557aae870c9f9f3c8076abd67b5c72120b279
Bug-Url: https://bugzilla.redhat.com/1043530
Signed-off-by: Alex Lourie <alou...@redhat.com>
---
M packaging/common_utils.py
M packaging/ovirt-engine-reports-setup.py
2 files changed, 34 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-reports refs/changes/48/22548/1

diff --git a/packaging/common_utils.py b/packaging/common_utils.py
index 6152e52..cd48fa8 100755
--- a/packaging/common_utils.py
+++ b/packaging/common_utils.py
@@ -44,6 +44,7 @@
 PGPASS_FILE_ADMIN_LINE = "DB ADMIN credentials"
 FILE_ENGINE_CONFIG_BIN="/usr/bin/engine-config"
 JRS_PACKAGE_PATH="/usr/share/jasperreports-server"
+FILE_DEPLOY_VERSION = "/etc/ovirt-engine/jrs-deployment.version"
 
 # Defaults
 DB_ADMIN = "engine_reports"
diff --git a/packaging/ovirt-engine-reports-setup.py 
b/packaging/ovirt-engine-reports-setup.py
index 24c3b33..736f896 100755
--- a/packaging/ovirt-engine-reports-setup.py
+++ b/packaging/ovirt-engine-reports-setup.py
@@ -53,6 +53,7 @@
 
 REPORTS_SERVER_DIR = "/usr/share/%s"  % JRS_PACKAGE_NAME
 REPORTS_SERVER_BUILDOMATIC_DIR = "%s/buildomatic" % REPORTS_SERVER_DIR
+REPORTS_DB_UPGRADE_SCRIPTS_DIR = "%s/install_resources/sql/postgresql" % 
REPORTS_SERVER_BUILDOMATIC_DIR
 FILE_JASPER_DB_CONN = "%s/default_master.properties" % 
REPORTS_SERVER_BUILDOMATIC_DIR
 FILE_DATABASE_ENGINE_CONFIG = 
"/etc/ovirt-engine/engine.conf.d/10-setup-database.conf"
 FILE_DATABASE_DWH_CONFIG = 
"/etc/ovirt-engine-dwh/ovirt-engine-dwhd.conf.d/10-setup-database.conf"
@@ -77,6 +78,7 @@
 DB_EXIST = False
 MUCK_PASSWORD="oVirtadmin2009!"
 PGDUMP_EXEC = "/usr/bin/pg_dump"
+EXEC_PSQL = "/usr/bin/psql"
 FILE_TMP_SQL_DUMP = tempfile.mkstemp(suffix=".sql", dir="/tmp")[1]
 DIR_TMP_WAR = tempfile.mkdtemp(dir="/tmp")
 
@@ -147,6 +149,33 @@
 
     (options, args) = parser.parse_args()
     return (options, args)
+
+@transactionDisplay('Updating DB Schema')
+def updateDbSchema(db_dict, TEMP_PGPASS):
+    sql_files = os.listdir(REPORTS_DB_UPGRADE_SCRIPTS_DIR)
+    sql_files.sort()
+    reports_version_type = 'ce'
+    for sql_file in sql_files:
+        if (
+            not sql_file.startswith('upgrade-postgresql-') or
+            reports_version_type not in sql_file or
+            sql_file < 'upgrade-postgresql-4.7'
+        ):
+            continue
+
+        cmd = [
+            EXEC_PSQL,
+            '-U', db_dict['username'],
+            '-d', db_dict['dbname'],
+            '-h', db_dict['hostname'],
+            '-p', db_dict['port'],
+            '-f', sql_file
+        ]
+        utils.execCmd(
+            cmdList=cmd,
+            failOnError=True,
+            envDict={'ENGINE_PGPASS': TEMP_PGPASS},
+        )
 
 @transactionDisplay("Deploying Server")
 def deployJs(db_dict, TEMP_PGPASS):
@@ -1097,6 +1126,10 @@
             if not warUpdated and isWarInstalled() and DB_EXIST:
                 backupWAR()
                 backupDB(db_dict, TEMP_PGPASS)
+                with open(FILE_DEPLOY_VERSION, 'r') as verfile:
+                    for line in verfile.readlines():
+                        if line.startswith('4.7'):
+                            updateDbSchema(db_dict, TEMP_PGPASS)
 
             # Catch failures on configuration
             try:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0f2557aae870c9f9f3c8076abd67b5c72120b279
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-reports
Gerrit-Branch: master
Gerrit-Owner: Alex Lourie <alou...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to