aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordglFromAtt <dgl@research.att.com>2018-04-23 22:39:55 -0400
committerdglFromAtt <dgl@research.att.com>2018-04-23 22:40:04 -0400
commit57122824826dab8e382bebcea32bddf374cebf1b (patch)
treee1b220a3b085a204120b0fcf6053a792e11d0322
parentf283c8d30ab3e5cde52906bc41c368f07733bb81 (diff)
Corrections to stmt ordering for using diff schema
Change-Id: I82b643b46f88f2c6db519bbd9b85e1a2e5d06a6d Signed-off-by: dglFromAtt <dgl@research.att.com> Issue-ID: DMAAP-434
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java25
-rw-r--r--src/main/resources/schema_8.sql27
2 files changed, 46 insertions, 6 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java b/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java
index 2a7925b..2c52b0d 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java
@@ -58,22 +58,35 @@ public class LoadSchema {
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++);
+
+
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();
diff --git a/src/main/resources/schema_8.sql b/src/main/resources/schema_8.sql
new file mode 100644
index 0000000..2652822
--- /dev/null
+++ b/src/main/resources/schema_8.sql
@@ -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;