diff --git a/config/logs.yml b/config/logs.yml index 6d35364..a810a63 100644 --- a/config/logs.yml +++ b/config/logs.yml @@ -3,6 +3,7 @@ logRelation: true logMainShowField: false upperCaseTable: true userField: editorFk +reasonField: motivation rowExcludeField: logExclude excludeRegex: '__$' showFields: diff --git a/lib/model-loader.js b/lib/model-loader.js index 0c3a998..4317493 100644 --- a/lib/model-loader.js +++ b/lib/model-loader.js @@ -94,9 +94,10 @@ module.exports = class ModelLoader { ]; const globalProps = [ 'userField', - 'rowExcludeField' + 'rowExcludeField', + 'reasonField' ]; - + for (const [schema, table, tableInfo] of schemaMap) { const tableConf = tableInfo.conf; @@ -109,20 +110,19 @@ module.exports = class ModelLoader { : conf[prop]; // Fetch columns & types - + const columns = new Set(); Object.assign (tableInfo, { castTypes: new Map(), columns }); - + if (tableConf.types) for (const col in tableConf.types) tableInfo.castTypes.set(col, tableConf.types[col]); - + const [dbCols] = await db.query( - `SELECT - COLUMN_NAME \`col\`, + `SELECT COLUMN_NAME \`col\`, DATA_TYPE \`type\` FROM information_schema.\`COLUMNS\` WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?`, @@ -131,6 +131,7 @@ module.exports = class ModelLoader { const exclude = new Set(tableConf.exclude); exclude.add(tableInfo.userField); + exclude.add(tableInfo.reasonField); for (const {col, type} of dbCols) { const isExcluded = diff --git a/mylogger.js b/mylogger.js index 601dbdf..9cb7155 100644 --- a/mylogger.js +++ b/mylogger.js @@ -81,7 +81,8 @@ module.exports = class MyLogger { newInstance = ?, changedModelId = ?, changedModelValue = ?, - summaryId = ?` + summaryId = ?, + reason = ?` ); logInfo.fetchStmt = await db.prepare( `SELECT id FROM ${sqlTable} @@ -97,7 +98,8 @@ module.exports = class MyLogger { creationDate = ?, oldInstance = ?, changedModelValue = ?, - summaryId = ? + summaryId = ?, + reason = ? WHERE id = ?` ); } @@ -531,6 +533,7 @@ module.exports = class MyLogger { ); try { + const reasonField = row[tableInfo.reasonField] ?? null; if (isDelete) { [[deleteRow]] = await logInfo.fetchStmt.execute([ modelName, modelId, originFk @@ -542,6 +545,7 @@ module.exports = class MyLogger { oldInstance, modelValue, summaryId, + reasonField, deleteRow.id ]); } @@ -558,7 +562,8 @@ module.exports = class MyLogger { newI ? JSON.stringify(newI) : null, modelId, modelValue, - summaryId + summaryId, + reasonField ]); }