Skip to content

Commit b8c5d09

Browse files
committed
Ensure ConsolidateVersions addresses Relationships
`Relationships` operate a bit different than `TopicReferences` (7e322c0) since it is _expected_ that there will be multiple values per `Source_TopicID` and `RelationshipKey`; instead, updates are tracked via the `IsDeleted` column. This addresses the `Relationships` portion of #75.
1 parent 7e322c0 commit b8c5d09

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

OnTopic.Data.Sql.Database/Utilities/Stored Procedures/ConsolidateVersions.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ FROM ExtendedAttributes
9393
WHERE Version > @StartDate
9494
AND Version < @EndDate
9595

96+
--------------------------------------------------------------------------------------------------------------------------------
97+
-- CREATE CONSOLIDATED RELATIONSHIPS RECORD
98+
--------------------------------------------------------------------------------------------------------------------------------
99+
;WITH TopicRelationships
100+
AS (
101+
SELECT Version,
102+
RowNumber = ROW_NUMBER() OVER (
103+
PARTITION BY Source_TopicID,
104+
RelationshipKey,
105+
Target_TopicID
106+
ORDER BY Version DESC
107+
)
108+
FROM Relationships
109+
WHERE Version > @StartDate
110+
AND Version <= @EndDate
111+
)
112+
UPDATE TopicRelationships
113+
SET Version = @EndDate
114+
WHERE RowNumber = 1
115+
116+
--------------------------------------------------------------------------------------------------------------------------------
117+
-- DELETE CONSOLIDATED RELATIONSHIPS
118+
--------------------------------------------------------------------------------------------------------------------------------
119+
DELETE
120+
FROM Relationships
121+
WHERE Version > @StartDate
122+
AND Version < @EndDate
123+
96124
--------------------------------------------------------------------------------------------------------------------------------
97125
-- CREATE CONSOLIDATED TOPIC REFERENCES RECORD
98126
--------------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)