@@ -28,10 +28,22 @@ END LOOP;
28
28
END;
29
29
/
30
30
31
+ -- Incoming USER_ INSERTs may contain STAFF_IDs which may or may not exist in stage
32
+ -- or pre-prod; we allow the DELIUS_USER_SUPPORT audit control check if they exist
33
+ -- so that we can set any invalid STAFF_IDs to NULL and allow the rest of the USER_
34
+ -- record to be created.
35
+ GRANT SELECT ON delius_app_schema.staff TO delius_user_support;
36
+
37
+ -- We do not wish to generate CDC records for LAST_ACCESSED_DATETIME as user access
38
+ -- times in the repository database have no baring on those on the client. We
39
+ -- use the Unilink-supplied PKG_TRIGGERSUPPORT package to temporarily disable
40
+ -- CDC capture on USER_ if no personal details have been changed.
41
+ GRANT EXECUTE ON delius_app_schema.pkg_triggersupport TO delius_user_support;
42
+
31
43
-- Additionally we add a trigger to enforce the same restrictions for the Application Schema itself.
32
44
-- This trigger is also used to workaround a difference between NLS Date formats used in DMS
33
45
-- and those used by the Delius application.
34
- CREATE OR REPLACE TRIGGER delius_user_support.audit_control_on_user_
46
+ create or replace TRIGGER delius_user_support.audit_control_on_user_
35
47
FOR delete OR update OR insert ON delius_app_schema.user_
36
48
COMPOUND TRIGGER
37
49
@@ -51,6 +63,7 @@ COMPOUND TRIGGER
51
63
END BEFORE STATEMENT;
52
64
53
65
BEFORE EACH ROW IS
66
+ l_staff_id_exists INTEGER;
54
67
BEGIN
55
68
IF USER = 'DELIUS_AUDIT_DMS_POOL'
56
69
THEN
@@ -69,10 +82,10 @@ COMPOUND TRIGGER
69
82
*/
70
83
EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = ''YYYY-MM-DD HH24:MI:SS''';
71
84
EXECUTE IMMEDIATE 'ALTER SESSION SET nls_timestamp_format = ''YYYY-MM-DD HH24:MI:SS.FF9''';
72
-
73
-
85
+
86
+
74
87
/*
75
- There are multiple reasons why the Delius application may update the
88
+ There are multiple reasons why the Delius application may update the
76
89
LAST_UPDATED_USER_ID and LAST_UPDATED_DATETIME columns, but not all of these involve
77
90
attributes which are replicated to the client database. This can cause confusion
78
91
if these attributes are updated but nothing appears to have changed.
@@ -94,13 +107,35 @@ COMPOUND TRIGGER
94
107
-- did not impact data that was replicated.
95
108
:new.last_updated_user_id := :old.last_updated_user_id;
96
109
:new.last_updated_datetime := :old.last_updated_datetime;
110
+ -- Also do not update the row version as no actual change has been made
111
+ :new.row_version := :old.row_version;
112
+ -- Disable CDC for the user record if no actual personal data change
113
+ -- (This is to prevent last accessed datetime records from production
114
+ -- triggering CDC even when we suppress the change in the trigger).
115
+ delius_app_schema.pkg_triggersupport.procSetCDCFlag(FALSE);
97
116
END IF;
98
117
-- Staff IDs in stage and pre-prod are independent of those in production
99
118
-- since these are not relevant to audit, and it may be necessary for
100
119
-- some users to have staff records in stage and pre-prod without having
101
120
-- corresponding records in production. Therefore we prevent any overwriting
102
121
-- of the staff ID
103
122
:new.staff_id := :old.staff_id;
123
+ -- We ignore changes to LAST_ACCESSED_DATETIME as this is the time the user was
124
+ -- accessed in the repository which is not relevant to the local database
125
+ :new.last_accessed_datetime := :old.last_accessed_datetime;
126
+ ELSIF INSERTING THEN
127
+ -- Also, not all Staff IDs from production will exist in stage & pre-prod
128
+ -- so it we are attempting to insert a new user with a non-existent staff_id
129
+ -- we simply set it to NULL
130
+ SELECT CASE WHEN EXISTS (
131
+ SELECT 1
132
+ FROM delius_app_schema.staff
133
+ WHERE staff_id = :new.staff_id
134
+ ) THEN 1 ELSE 0 END
135
+ INTO l_staff_id_exists FROM DUAL;
136
+ IF l_staff_id_exists = 0 THEN
137
+ :new.staff_id := NULL;
138
+ END IF;
104
139
END IF;
105
140
END IF;
106
141
@@ -132,6 +167,8 @@ COMPOUND TRIGGER
132
167
BEGIN
133
168
IF USER = 'DELIUS_AUDIT_DMS_POOL'
134
169
THEN
170
+ -- Reset CDC Flag to default value
171
+ delius_app_schema.pkg_triggersupport.procSetCDCFlag(NULL);
135
172
EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = ''YYYY-MM-DD HH24:MI:SS''';
136
173
EXECUTE IMMEDIATE 'ALTER SESSION SET nls_timestamp_format = ''YYYY-MM-DD HH24:MI:SS.FF9''';
137
174
END IF;
0 commit comments