Skip to content

Commit

Permalink
change capture
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyGaluzo committed Nov 19, 2024
1 parent ce28891 commit 848195c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5728,6 +5728,27 @@ CREATE TRIGGER dbo.ResourceUpd
WHERE A.IsHistory = 0;
RETURN;
END
IF UPDATE (TransactionId)
AND NOT UPDATE (IsHistory)
BEGIN
UPDATE B
SET TransactionId = A.TransactionId
FROM Inserted AS A
INNER JOIN
dbo.CurrentResources AS B
ON B.ResourceTypeId = A.ResourceTypeId
AND B.ResourceSurrogateId = A.ResourceSurrogateId
AND B.IsHistory = 0;
UPDATE B
SET TransactionId = A.TransactionId
FROM Inserted AS A
INNER JOIN
dbo.HistoryResources AS B
ON B.ResourceTypeId = A.ResourceTypeId
AND B.ResourceSurrogateId = A.ResourceSurrogateId
AND B.IsHistory = 1;
RETURN;
END
IF UPDATE (RawResource)
BEGIN
UPDATE B
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ GO
CREATE TRIGGER dbo.ResourceUpd ON dbo.Resource INSTEAD OF UPDATE
AS
BEGIN
IF UPDATE(IsDeleted) AND UPDATE(RawResource) AND UPDATE(SearchParamHash) AND UPDATE(HistoryTransactionId) AND NOT UPDATE(IsHistory) -- HardDeleteResource
IF UPDATE(IsDeleted) AND UPDATE(RawResource) AND UPDATE(SearchParamHash) AND UPDATE(HistoryTransactionId) AND NOT UPDATE(IsHistory) -- hard delete resource
BEGIN
UPDATE B
SET RawResource = A.RawResource
Expand All @@ -87,7 +87,7 @@ BEGIN
RETURN
END

IF UPDATE(SearchParamHash) AND NOT UPDATE(IsHistory)
IF UPDATE(SearchParamHash) AND NOT UPDATE(IsHistory) -- reindex
BEGIN
UPDATE B
SET SearchParamHash = A.SearchParamHash
Expand All @@ -98,6 +98,21 @@ BEGIN
RETURN
END

IF UPDATE(TransactionId) AND NOT UPDATE(IsHistory) -- cleanup trans
BEGIN
UPDATE B
SET TransactionId = A.TransactionId
FROM Inserted A
JOIN dbo.CurrentResources B ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceSurrogateId = A.ResourceSurrogateId AND B.IsHistory = 0

UPDATE B
SET TransactionId = A.TransactionId
FROM Inserted A
JOIN dbo.HistoryResources B ON B.ResourceTypeId = A.ResourceTypeId AND B.ResourceSurrogateId = A.ResourceSurrogateId AND B.IsHistory = 1

RETURN
END

IF UPDATE(RawResource) -- invisible records
BEGIN
UPDATE B
Expand Down

0 comments on commit 848195c

Please sign in to comment.