From: dglFromAtt Date: Tue, 24 Apr 2018 02:39:55 +0000 (-0400) Subject: Corrections to stmt ordering for using diff schema X-Git-Tag: 2.0.0-ONAP~3 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdbcapi.git;a=commitdiff_plain;h=57122824826dab8e382bebcea32bddf374cebf1b Corrections to stmt ordering for using diff schema Change-Id: I82b643b46f88f2c6db519bbd9b85e1a2e5d06a6d Signed-off-by: dglFromAtt Issue-ID: DMAAP-434 --- 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;