Corrections to stmt ordering for using diff schema 33/44533/1
authordglFromAtt <dgl@research.att.com>
Tue, 24 Apr 2018 02:39:55 +0000 (22:39 -0400)
committerdglFromAtt <dgl@research.att.com>
Tue, 24 Apr 2018 02:40:04 +0000 (22:40 -0400)
Change-Id: I82b643b46f88f2c6db519bbd9b85e1a2e5d06a6d
Signed-off-by: dglFromAtt <dgl@research.att.com>
Issue-ID: DMAAP-434

src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java
src/main/resources/schema_8.sql [new file with mode: 0644]

index 2a7925b..2c52b0d 100644 (file)
@@ -58,22 +58,35 @@ public class LoadSchema     {
                try { 
                        c = cf.get(true);
                        stmt = c.createStatement();
                try { 
                        c = cf.get(true);
                        stmt = c.createStatement();
+                       
+                       // this sets the PG search_path to a consistent schema, otherwise sometimes
+                       // we get public, and sometimes we get dmaap_admin
+                       String cmd = String.format( "SET search_path to %s;", cf.getSchema());
+                       try {
+                               stmt.execute(cmd);
+                               logger.info("SCHEMA: " + cmd);
+                       } catch (SQLException sqle) {
+                                       throw sqle;
+                       }
+                       
+                       
+                       // determine if an upgrade is needed
                        int newver = -1;
                        try {
                                newver = getVer(stmt);
                        } catch (Exception e) {}
                        logger.info("Database schema currently at version " + newver++);
                        int newver = -1;
                        try {
                                newver = getVer(stmt);
                        } catch (Exception e) {}
                        logger.info("Database schema currently at version " + newver++);
+                       
+
 
                        while ((is = LoadSchema.class.getClassLoader().getResourceAsStream("schema_" + newver + ".sql")) != null) {
                                logger.info("Upgrading database schema to version " + newver);
                                BufferedReader br = new BufferedReader(new InputStreamReader(is));
                                String s;
 
                        while ((is = LoadSchema.class.getClassLoader().getResourceAsStream("schema_" + newver + ".sql")) != null) {
                                logger.info("Upgrading database schema to version " + newver);
                                BufferedReader br = new BufferedReader(new InputStreamReader(is));
                                String s;
-                               String sofar;
-                               if ( newver > 0 ) {
-                                       sofar = null;
-                               } else {
-                                       sofar = String.format( "SET search_path to %s;", cf.getSchema());
-                               }
+                               String sofar = null;
+                               
+
+                               
                                while ((s = br.readLine()) != null) {
                                        logger.info("SCHEMA: " + s);
                                        s = s.trim();
                                while ((s = br.readLine()) != null) {
                                        logger.info("SCHEMA: " + s);
                                        s = s.trim();
diff --git a/src/main/resources/schema_8.sql b/src/main/resources/schema_8.sql
new file mode 100644 (file)
index 0000000..2652822
--- /dev/null
@@ -0,0 +1,27 @@
+---
+-- ============LICENSE_START=======================================================
+-- OpenECOMP - org.onap.dbcapi
+-- ================================================================================
+-- Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+-- ================================================================================
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+-- 
+--      http://www.apache.org/licenses/LICENSE-2.0
+-- 
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+-- ============LICENSE_END=========================================================
+---
+
+
+@alter table mr_cluster
+       drop column     hosts           
+;
+
+
+update dmaapbc_sch_ver set version = 8 where version = 7;