feat: refs #7287 First commit #5
|
@ -3,6 +3,7 @@ logRelation: true
|
||||||
logMainShowField: false
|
logMainShowField: false
|
||||||
upperCaseTable: true
|
upperCaseTable: true
|
||||||
userField: editorFk
|
userField: editorFk
|
||||||
|
reasonField: motivation
|
||||||
rowExcludeField: logExclude
|
rowExcludeField: logExclude
|
||||||
excludeRegex: '__$'
|
excludeRegex: '__$'
|
||||||
showFields:
|
showFields:
|
||||||
|
|
|
@ -94,9 +94,10 @@ module.exports = class ModelLoader {
|
||||||
];
|
];
|
||||||
const globalProps = [
|
const globalProps = [
|
||||||
'userField',
|
'userField',
|
||||||
'rowExcludeField'
|
'rowExcludeField',
|
||||||
|
'reasonField'
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const [schema, table, tableInfo] of schemaMap) {
|
for (const [schema, table, tableInfo] of schemaMap) {
|
||||||
const tableConf = tableInfo.conf;
|
const tableConf = tableInfo.conf;
|
||||||
|
|
||||||
|
@ -109,20 +110,19 @@ module.exports = class ModelLoader {
|
||||||
: conf[prop];
|
: conf[prop];
|
||||||
|
|
||||||
// Fetch columns & types
|
// Fetch columns & types
|
||||||
|
|
||||||
const columns = new Set();
|
const columns = new Set();
|
||||||
Object.assign (tableInfo, {
|
Object.assign (tableInfo, {
|
||||||
castTypes: new Map(),
|
castTypes: new Map(),
|
||||||
columns
|
columns
|
||||||
});
|
});
|
||||||
|
|
||||||
if (tableConf.types)
|
if (tableConf.types)
|
||||||
for (const col in tableConf.types)
|
for (const col in tableConf.types)
|
||||||
tableInfo.castTypes.set(col, tableConf.types[col]);
|
tableInfo.castTypes.set(col, tableConf.types[col]);
|
||||||
|
|
||||||
const [dbCols] = await db.query(
|
const [dbCols] = await db.query(
|
||||||
`SELECT
|
`SELECT COLUMN_NAME \`col\`,
|
||||||
COLUMN_NAME \`col\`,
|
|
||||||
DATA_TYPE \`type\`
|
DATA_TYPE \`type\`
|
||||||
FROM information_schema.\`COLUMNS\`
|
FROM information_schema.\`COLUMNS\`
|
||||||
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?`,
|
WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?`,
|
||||||
|
@ -131,6 +131,7 @@ module.exports = class ModelLoader {
|
||||||
|
|
||||||
const exclude = new Set(tableConf.exclude);
|
const exclude = new Set(tableConf.exclude);
|
||||||
exclude.add(tableInfo.userField);
|
exclude.add(tableInfo.userField);
|
||||||
|
exclude.add(tableInfo.reasonField);
|
||||||
|
|
||||||
for (const {col, type} of dbCols) {
|
for (const {col, type} of dbCols) {
|
||||||
const isExcluded =
|
const isExcluded =
|
||||||
|
|
11
mylogger.js
11
mylogger.js
|
@ -81,7 +81,8 @@ module.exports = class MyLogger {
|
||||||
newInstance = ?,
|
newInstance = ?,
|
||||||
changedModelId = ?,
|
changedModelId = ?,
|
||||||
changedModelValue = ?,
|
changedModelValue = ?,
|
||||||
summaryId = ?`
|
summaryId = ?,
|
||||||
|
reason = ?`
|
||||||
);
|
);
|
||||||
logInfo.fetchStmt = await db.prepare(
|
logInfo.fetchStmt = await db.prepare(
|
||||||
`SELECT id FROM ${sqlTable}
|
`SELECT id FROM ${sqlTable}
|
||||||
|
@ -97,7 +98,8 @@ module.exports = class MyLogger {
|
||||||
creationDate = ?,
|
creationDate = ?,
|
||||||
oldInstance = ?,
|
oldInstance = ?,
|
||||||
changedModelValue = ?,
|
changedModelValue = ?,
|
||||||
summaryId = ?
|
summaryId = ?,
|
||||||
|
reason = ?
|
||||||
WHERE id = ?`
|
WHERE id = ?`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -531,6 +533,7 @@ module.exports = class MyLogger {
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const reasonField = row[tableInfo.reasonField] ?? null;
|
||||||
if (isDelete) {
|
if (isDelete) {
|
||||||
[[deleteRow]] = await logInfo.fetchStmt.execute([
|
[[deleteRow]] = await logInfo.fetchStmt.execute([
|
||||||
modelName, modelId, originFk
|
modelName, modelId, originFk
|
||||||
|
@ -542,6 +545,7 @@ module.exports = class MyLogger {
|
||||||
oldInstance,
|
oldInstance,
|
||||||
modelValue,
|
modelValue,
|
||||||
summaryId,
|
summaryId,
|
||||||
|
reasonField,
|
||||||
deleteRow.id
|
deleteRow.id
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -558,7 +562,8 @@ module.exports = class MyLogger {
|
||||||
newI ? JSON.stringify(newI) : null,
|
newI ? JSON.stringify(newI) : null,
|
||||||
modelId,
|
modelId,
|
||||||
modelValue,
|
modelValue,
|
||||||
summaryId
|
summaryId,
|
||||||
|
reasonField
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue