-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4. Log Problem.sql
More file actions
72 lines (60 loc) · 1.93 KB
/
4. Log Problem.sql
File metadata and controls
72 lines (60 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---| sqlite - audit log table
---| Create tabel audit log untuk record semua anomali data
CREATE TABLE IF NOT EXISTS audit_log (
log_id INTEGER PRIMARY KEY,
logged_at DATETIME DEFAULT (DATETIME(CURRENT_TIMESTAMP, '+7 hours')),
row_id INTEGER,
attribute TEXT,
reason TEXT,
solution TEXT,
source_table TEXT,
total_rows INTEGER,
status_log TEXT,
UNIQUE(row_id, attribute, reason, solution, source_table, total_rows) );
--- checking newest unique records of audit_log max 100 rows (unique without log_id, row_id, logged_at)
SELECT DISTINCT
attribute, reason, solution, source_table, total_rows, status_log
FROM audit_log
ORDER BY logged_at DESC;
--- checking the latest record date-time in audit_log table
SELECT DISTINCT logged_at
FROM audit_log
ORDER BY logged_at DESC;
---| Create tabel BACKUP audit log untuk backup semua record di audit log
CREATE TABLE IF NOT EXISTS BACKUP_audit_log (
log_id INTEGER PRIMARY KEY,
logged_at DATETIME DEFAULT (DATETIME(CURRENT_TIMESTAMP, '+7 hours')),
row_id INTEGER,
attribute TEXT,
reason TEXT,
solution TEXT,
source_table TEXT,
total_rows INTEGER,
status_log TEXT,
UNIQUE(row_id, attribute, reason, solution, source_table, total_rows) );
---| CREATE Trigger for automate input ke BACKUP_audit_log table
---| Trigger activated after every INSERT on the audit_log table
CREATE TRIGGER trigger_insert_to_BACKUP_audit_log
AFTER INSERT ON audit_log
BEGIN
INSERT INTO BACKUP_audit_log (
log_id,
logged_at,
row_id,
attribute,
reason,
solution,
source_table,
total_rows,
status_log)
VALUES (
NEW.log_id,
NEW.logged_at,
NEW.row_id,
NEW.attribute,
NEW.reason,
NEW.solution,
NEW.source_table,
NEW.total_rows,
NEW.status_log);
END;