Skip to content

Commit

Permalink
Only store old records in logging table
Browse files Browse the repository at this point in the history
  • Loading branch information
jthompson-arcus committed Oct 29, 2024
1 parent 91a8c49 commit f98f0d2
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions R/fct_SQLite.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,23 @@ db_add_primary_key <- function(con, name, value) {

db_add_log <- function(con) {
DBI::dbCreateTable(con, "all_review_data_log",
c(id = "INTEGER PRIMARY KEY AUTOINCREMENT", review_id = "CHAR NOT NULL",
old_data = "JSON", new_data = "JSON",
c(id = "INTEGER PRIMARY KEY AUTOINCREMENT", review_id = "INTEGER NOT NULL",
reviewed = "CHAR", comment = "CHAR", reviewer = "CHAR", timestamp = "CHAR", status = "CHAR",
dml_type = "CHAR NOT NULL", dml_timestamp = "DATETIME DEFAULT CURRENT_TIMESTAMP"))
DBI::dbExecute(con, paste(
"CREATE TRIGGER all_review_data_update_log_trigger",
"AFTER UPDATE ON all_review_data FOR EACH ROW",
"BEGIN",
"INSERT INTO all_review_data_log (",
"review_id, old_data, new_data, dml_type",
"review_id, reviewed, comment, reviewer, timestamp, status, dml_type",
")",
"VALUES(",
"NEW.id,",
"JSON_OBJECT(",
"'reviewed', OLD.reviewed,",
"'comment', OLD.comment,",
"'reviewer', OLD.reviewer,",
"'timestamp', OLD.timestamp,",
"'status', OLD.status",
"),",
"JSON_OBJECT(",
"'reviewed', NEW.reviewed,",
"'comment', NEW.comment,",
"'reviewer', NEW.reviewer,",
"'timestamp', NEW.timestamp,",
"'status', NEW.status",
"),",
"OLD.reviewed,",
"OLD.comment,",
"OLD.reviewer,",
"OLD.timestamp,",
"OLD.status,",
"'UPDATE'",
");",
"END"
Expand Down

0 comments on commit f98f0d2

Please sign in to comment.