feat: refs #7287 First commit #5

Open
guillermo wants to merge 3 commits from 7287-reasonLog into master
3 changed files with 17 additions and 10 deletions

View File

@ -3,6 +3,7 @@ logRelation: true
logMainShowField: false
upperCaseTable: true
userField: editorFk
reasonField: motivation
rowExcludeField: logExclude
excludeRegex: '__$'
showFields:

View File

@ -94,7 +94,8 @@ module.exports = class ModelLoader {
];
const globalProps = [
'userField',
'rowExcludeField'
'rowExcludeField',
'reasonField'
];
for (const [schema, table, tableInfo] of schemaMap) {
@ -121,8 +122,7 @@ module.exports = class ModelLoader {
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 =

View File

@ -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
]);
}