/** * To avoid irrecoverable deploy state, we allow the deploy to succeed even if grant fails, and we will simply log out warnings. */ private void applyGrants(Connection conn, PhysicalSchema schema, String objectName, RichIterable<Permission> permsToApply, CommandExecutionContext cec) { String lastExecutedSql = null; try { Pair<Boolean, RichIterable<String>> qualifiedObjectNames = getQualifiedObjectNames(conn, schema, objectName); ImmutableList<String> grants = this.grantChangeParser.generateGrantChanges(permsToApply, dbChangeType, schema, objectName, qualifiedObjectNames.getTwo(), qualifiedObjectNames.getOne()); LOG.info(String.format("Applying grants on db object [%s]: found %d total SQL statements to apply", objectName, grants.size())); for (String grant : grants) { if (!StringUtils.isBlank(grant)) { // need to check for blank in case it gets tokenized away during the in-memory conversion LOG.debug("Executing grant: {}", grant); lastExecutedSql = grant; // grants are automatically included as part of the original change, so we don't track the deployment in the // audit table sqlExecutor.getJdbcTemplate().update(conn, grant); } } } catch (Exception exc) { String warningMessage = "Failed executing grant on schema [" + schema + "] and object [" + objectName + "]"; if (lastExecutedSql != null) { warningMessage += " on SQL " + lastExecutedSql + ":"; } cec.addWarning(warningMessage + exc.getMessage() + "\n Proceeding with deploy. Please use a /migration script to correct this. Watch https://github.com/goldmansachs/obevo/issues/3 to see when we improve this logic."); LOG.error(warningMessage, exc); } }
/** * To avoid irrecoverable deploy state, we allow the deploy to succeed even if grant fails, and we will simply log out warnings. */ private void applyGrants(Connection conn, PhysicalSchema schema, String objectName, RichIterable<Permission> permsToApply, CommandExecutionContext cec) { String lastExecutedSql = null; try { Pair<Boolean, RichIterable<String>> qualifiedObjectNames = getQualifiedObjectNames(conn, schema, objectName); ImmutableList<String> grants = this.grantChangeParser.generateGrantChanges(permsToApply, dbChangeType, schema, objectName, qualifiedObjectNames.getTwo(), qualifiedObjectNames.getOne()); LOG.info(String.format("Applying grants on db object [%s]: found %d total SQL statements to apply", objectName, grants.size())); for (String grant : grants) { if (!StringUtils.isBlank(grant)) { // need to check for blank in case it gets tokenized away during the in-memory conversion LOG.debug("Executing grant: {}", grant); lastExecutedSql = grant; // grants are automatically included as part of the original change, so we don't track the deployment in the // audit table sqlExecutor.getJdbcTemplate().update(conn, grant); } } } catch (Exception exc) { String warningMessage = "Failed executing grant on schema [" + schema + "] and object [" + objectName + "]"; if (lastExecutedSql != null) { warningMessage += " on SQL " + lastExecutedSql + ":"; } cec.addWarning(warningMessage + exc.getMessage() + "\n Proceeding with deploy. Please use a /migration script to correct this. Watch https://github.com/goldmansachs/obevo/issues/3 to see when we improve this logic."); LOG.error(warningMessage, exc); } }