ctsit / redcapcustodian

Simplified, automated data management on REDCap systems
Other
13 stars 6 forks source link

Add an ETL logging facility #25

Closed pbchase closed 2 years ago

pbchase commented 2 years ago

Steal ETL logging code from STP and bend it toward the REDCap worldview

pbchase commented 2 years ago

Here are some thoughts from @ChemiKyle and @pbchase. There are flaws here, but it is useful.

Log table schema

CREATE TABLE `etl_log` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `log_date` datetime NOT NULL,
  `script_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `target_uri` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, -- e.g. https://redcap.ctsi.ufl.edu/redcap/api/, smtp://smtp.ufl.edu, mysql://user_name@example.com:3306/schema
  `table_written` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `project_id_written` int CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  -- `record_id` varchar(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `primary_key` varchar(63) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `record_level_data` json DEFAULT NULL,
  `level` enum('INFO','DEBUG','ERROR') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `log_date` (`log_date`),
  KEY `script_name` (`script_name`),
  KEY `script_run_time` (`script_run_time`),
  KEY `database_written` (`database_written`),
  KEY `ufid` (`ufid`),
  KEY `primary_key` (`primary_key`),
  KEY `level` (`level`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Examples

REDCap API write

Write to redcap_user_information

Write to redcap_projects

Write to redcap_project_invoices

Write to redcap_metadata

Write to email

pbchase commented 2 years ago

Here's the product of the 2022-03-30 convo between @pbchase, @ChemiKyle, and @mbentz-uf

CREATE TABLE `rcc_detail_log` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `log_date` datetime NOT NULL,
  `script_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `target_uri` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, -- e.g. https://redcap.ctsi.ufl.edu/redcap/api/, smtp://smtp.ufl.edu, mysql://user_name@example.com:3306/schema
  `table_written` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, -- e.g. ...
  `project_id_written` int CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  -- `record_id` varchar(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `primary_key` varchar(63) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, -- REDCap Project record_id or table PK
  `record_level_data` json DEFAULT NULL,
  `level` enum('INFO','DEBUG','ERROR') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `log_date` (`log_date`),
  KEY `script_name` (`script_name`),
  KEY `target_uri` (`target_uri`),
  KEY `table_written` (`table_written`),
  KEY `project_id_written` (`project_id_written`),
  KEY `primary_key` (`primary_key`),
  KEY `level` (`level`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

-- sftp://user@example.com/path/filename (??)
CREATE TABLE `rcc_job_log` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `log_date` datetime NOT NULL,
  `script_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `script_run_time` datetime NOT NULL,
  `job_summary_data` text DEFAULT NULL,
  `job_duration` double not null,
  `level` enum('SUCCESS','DEBUG','ERROR') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `log_date` (`log_date`),
  KEY `script_name` (`script_name`),
  KEY `script_run_time` (`script_run_time`),
  KEY `level` (`level`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
pbchase commented 2 years ago

Addressed by PR #42