[feature] Compability check of changes table added

This commit is contained in:
Georgii Petrov
2024-03-22 20:44:49 +03:00
parent 023247c7d2
commit 2b9f7fd7cd
3 changed files with 46 additions and 50 deletions

View File

@ -294,7 +294,7 @@ exports.SUPPORTED_TEMPLATES_EXTENSIONS = {
'Excel': ['xlsx'],
'PowerPoint': ['pptx']
};
exports.TASK_RESULT_SCHEMA = [
exports.TABLE_RESULT_SCHEMA = [
'tenant',
'id',
'status',
@ -308,7 +308,7 @@ exports.TASK_RESULT_SCHEMA = [
'password',
'additional'
];
exports.DOC_CHANGES_SCHEMA = [
exports.TABLE_CHANGES_SCHEMA = [
'tenant',
'id',
'change_id',

View File

@ -144,6 +144,7 @@ const cfgExpDocumentsCron = config.get('services.CoAuthoring.expire.documentsCro
const cfgRefreshLockInterval = ms(config.get('wopi.refreshLockInterval'));
const cfgSocketIoConnection = config.get('services.CoAuthoring.socketio.connection');
const cfgTableResult = config.get('services.CoAuthoring.sql.tableResult');
const cfgTableChanges = config.get('services.CoAuthoring.sql.tableChanges');
const EditorTypes = {
document : 0,
@ -1476,6 +1477,26 @@ function getOpenFormatByEditor(editorType) {
return res;
}
async function isSchemaCompatible([tableName, tableSchema]) {
const resultSchema = await sqlBase.getTableColumns(operationContext.global, tableName);
if (resultSchema.length === 0) {
operationContext.global.logger.error('DB table "%s" does not exist', tableName);
return false;
}
const columnArray = resultSchema.map(row => row['column_name']);
const hashedResult = new Set(columnArray);
const schemaDiff = tableSchema.filter(column => !hashedResult.has(column));
if (schemaDiff.length > 0) {
operationContext.global.logger.error(`DB table "${tableName}" does not contain columns: ${schemaDiff}, columns info: ${columnArray}`);
return false;
}
return true;
}
exports.c_oAscServerStatus = c_oAscServerStatus;
exports.editorData = editorData;
exports.sendData = sendData;
@ -3935,31 +3956,28 @@ exports.install = function(server, callbackFunction) {
gc.startGC();
//check data base compatibility
sqlBase.getTableColumns(operationContext.global, cfgTableResult).then(function(result) {
if (result.length === 0) {
operationContext.global.logger.error('DB table "%s" does not exist', cfgTableResult);
return;
}
const tables = [
[cfgTableResult, constants.TABLE_RESULT_SCHEMA],
[cfgTableChanges, constants.TABLE_CHANGES_SCHEMA]
];
const requestPromises = tables.map(table => isSchemaCompatible(table));
const columnArray = result.map(row => row['column_name']);
const hashedResult = new Set(columnArray);
const schemaDiff = constants.TASK_RESULT_SCHEMA.filter(column => !hashedResult.has(column));
Promise.all(requestPromises).then(
checkResult => {
if (checkResult.includes(false)) {
return;
}
if (schemaDiff.length > 0) {
operationContext.global.logger.error(`DB table "${cfgTableResult}" does not contain columns: ${schemaDiff}, columns info: ${columnArray}`);
return;
}
return editorData.connect().then(
() => {
callbackFunction();
isServerStartedUp = true;
},
error => operationContext.global.logger.error('editorData error: %s', error.stack)
);
}).catch(err => {
operationContext.global.logger.error('getTableColumns error: %s', err.stack);
});
editorData.connect().then(
() => {
callbackFunction();
isServerStartedUp = true;
},
error => operationContext.global.logger.error('editorData error: %s', error.stack)
);
},
error => operationContext.global.logger.error('getTableColumns error: %s', error.stack)
);
});
});
};

View File

@ -218,30 +218,8 @@ describe('Base database connector', function () {
describe('DB tables existence', function () {
const tables = {
[cfgTableResult]: [
{ column_name: 'tenant' },
{ column_name: 'id' },
{ column_name: 'status' },
{ column_name: 'status_info' },
{ column_name: 'created_at' },
{ column_name: 'last_open_date' },
{ column_name: 'user_index' },
{ column_name: 'change_id' },
{ column_name: 'callback' },
{ column_name: 'baseurl' },
{ column_name: 'password' },
{ column_name: 'additional' }
],
[cfgTableChanges]: [
{ column_name: 'tenant' },
{ column_name: 'id' },
{ column_name: 'change_id' },
{ column_name: 'user_id' },
{ column_name: 'user_id_original' },
{ column_name: 'user_name' },
{ column_name: 'change_data' },
{ column_name: 'change_date' }
]
[cfgTableResult]: constants.TABLE_RESULT_SCHEMA.map(column => { return { column_name: column } }),
[cfgTableChanges]: constants.TABLE_CHANGES_SCHEMA.map(column => { return { column_name: column } })
};
for (const table in tables) {
@ -437,4 +415,4 @@ describe('Base database connector', function () {
expect(updatedRow).toEqual(expectedUrlChanges);
});
});
});
});