Permalink
Browse files

[bamboo] Automated branch merge (from release-21.0.2:24c00ba90b103666…

…a302ae5db246854ca4d1dbcc)
  • Loading branch information...
opennms-bamboo committed Dec 7, 2017
2 parents 3dbb4b6 + 24c00ba commit f10dfbe2231626bd1a07f5fa7229ef3dd278338f
@@ -39,4 +39,48 @@
</rollback>
</changeSet>
<!-- See NMS-9742 -->
<changeSet id="foundation-2017-remove-duplicate-reductionkey-memos" author="mvrueden">
<!-- Merge existing duplicate entries -->
<sql>
WITH subquery AS (
SELECT
reductionkey,
type,
max(updated) AS updated,
string_agg(body, E'\n\nMerged by database installer - ' || to_char(current_timestamp, 'YYYY-MM-DD') || E':\n') AS body,
count(*)
FROM memos
WHERE reductionkey IS NOT NULL
GROUP BY reductionkey, type
HAVING count(*) > 1
)
UPDATE memos
SET body = subquery.body
FROM subquery
WHERE memos.reductionkey = subquery.reductionkey
AND memos.type = subquery.type
AND memos.updated = subquery.updated;
</sql>
<!-- Delete duplicate entries except the newest -->
<sql>
WITH merged_memos AS (
SELECT reductionkey, MAX(updated) as max_updated
FROM memos
WHERE reductionkey IS NOT NULL
GROUP BY reductionkey
HAVING count(*) > 1
)
DELETE from memos where id in (
SELECT memos.id
FROM memos
JOIN merged_memos ON memos.reductionkey = merged_memos.reductionkey
WHERE memos.reductionkey = merged_memos.reductionkey AND memos.updated &lt; merged_memos.max_updated
);
</sql>
<!-- Add constraint to prevent duplicate entries in the future -->
<addUniqueConstraint tableName="memos" columnNames="reductionkey, type" />
</changeSet>
</databaseChangeLog>
@@ -184,7 +184,7 @@ public void reload(Page page) {
}
// Ensure that the number of items expected matches with the actual ones. See issue NMS-8079 fore more details.
if (beans.size() != rowMap.size()) {
throw new IllegalStateException("The cache is supposed to carry " + beans.size() + " but only contains " + rowMap.size() + " items.");
throw new IllegalStateException("The cache is supposed to carry " + beans.size() + " but contains " + rowMap.size() + " items.");
}
}
}
@@ -462,6 +462,8 @@ public void addBeanToHibernatePropertyMapping(final String key, final String val
}
// Ensure that the number of items expected matches with the actual ones. See issue NMS-8079 fore more details.
if (itemIds.size() != numberOfItems) {
LOG.warn("The container is supposed to carry {} but contains {} item. Expected itemIds: {}. Actual items: {}. Executed Criteria: {}. Bailing.",
numberOfItems, itemIds.size(), itemIds, getItemsForCache(m_datasource, getPage()), getCriteria(getPage(), true));
throw new IllegalStateException("The container is supposed to carry " + numberOfItems + " but only contains " + itemIds.size() + " items.");
}
return itemIds;
@@ -1010,6 +1010,8 @@ create table memos (
type character varying(64),
CONSTRAINT memos_pkey PRIMARY KEY (id)
);
ALTER TABLE memos ADD CONSTRAINT reductionkey_type_unique_constraint UNIQUE (reductionkey, type);
--########################################################################
--#
--# This table contains the following fields:

0 comments on commit f10dfbe

Please sign in to comment.