Skip to content

Commit 1cc468c

Browse files
committed
Convert to retentionMonths, decrease by 6 until 12
1 parent d558ab4 commit 1cc468c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

onprc_ehr/resources/etls/auditLogArchive.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<transform id="ArchiveAuditLogs" type="StoredProcedure">
1515
<description>Archive audit log entries older than @RetentionYears</description>
1616
<procedure schemaName="audit" procedureName="ArchiveAuditTables">
17-
<parameter name="@RetentionYears" value="15" scope="global" override="false"/>
17+
<parameter name="@RetentionMonths" value="144" scope="global" override="false"/>
1818
</procedure>
1919
</transform>
2020

onprc_ehr/resources/schemas/dbscripts/sqlserver/onprc_ehr-25.002-25.003.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SET QUOTED_IDENTIFIER ON;
33
GO
44

55
ALTER PROCEDURE [audit].[ArchiveAuditTables] (
6-
@RetentionYears INT OUTPUT
6+
@RetentionMonths INT OUTPUT
77
)
88
AS
99
BEGIN
@@ -14,10 +14,10 @@ BEGIN
1414
@DestDB NVARCHAR(128) = 'labkey_audit',
1515
@SchemaName NVARCHAR(128) = 'audit';
1616

17-
SET @RetentionYears = CASE WHEN @RetentionYears - 1 > 1 THEN @RetentionYears - 1 ELSE 1 END;
18-
PRINT N'Archiving audit logs older than ' + CAST(@RetentionYears AS NVARCHAR(3)) + N' years old'
17+
SET @RetentionMonths = CASE WHEN @RetentionMonths - 6 > 12 THEN @RetentionMonths - 6 ELSE 12 END;
18+
PRINT N'Archiving audit logs older than ' + CAST(@RetentionMonths AS NVARCHAR(3)) + N' months old'
1919

20-
DECLARE @CutoffDate DATETIME = DATEADD(YEAR, -@RetentionYears, GETDATE());
20+
DECLARE @CutoffDate DATETIME = DATEADD(YEAR, -@RetentionMonths, GETDATE());
2121

2222

2323
-- Validate if source database exists
@@ -49,7 +49,7 @@ BEGIN
4949
Status NVARCHAR(50) NULL,
5050
RecordsProcessed INT NULL,
5151
ErrorMessage NVARCHAR(MAX) NULL,
52-
RetentionYears INT NULL,
52+
RetentionMonths INT NULL,
5353
CONSTRAINT PK_ArchiveAuditLog PRIMARY KEY (LogID)
5454
)'');
5555
END';
@@ -100,8 +100,8 @@ BEGIN
100100
DECLARE @InsertLogSQL NVARCHAR(MAX) = '
101101
USE ' + QUOTENAME(@DestDB) + ';
102102
INSERT INTO dbo.ArchiveAuditLog
103-
(TableName, Operation, StartTime, Status, RetentionYears)
104-
VALUES (''' + @CurrentTable + ''', ''Archive'', GETDATE(), ''Started'', ' + CAST(@RetentionYears AS NVARCHAR(10)) + ');
103+
(TableName, Operation, StartTime, Status, RetentionMonths)
104+
VALUES (''' + @CurrentTable + ''', ''Archive'', GETDATE(), ''Started'', ' + CAST(@RetentionMonths AS NVARCHAR(10)) + ');
105105
SELECT @LogIDOUT = SCOPE_IDENTITY();';
106106

107107
EXEC sp_executesql @InsertLogSQL, N'@LogIDOUT INT OUTPUT', @LogIDOUT = @LogID OUTPUT;

0 commit comments

Comments
 (0)