fix: use only cols with comments for obj hash

This commit is contained in:
Pavel
2025-08-07 14:17:28 +02:00
parent 52f74f1204
commit bfafcb76ba
2 changed files with 10 additions and 8 deletions

View File

@@ -90,7 +90,7 @@ function getColumnInfo({
/**
* @param {ReturnType<objectTypeToField>} fieldType
* @param {any} item
* @param {Array<{ objectId: string; columnComment: string }>} columns
* @param {Array<{ objectId: string; columnId: number, columnComment: string }>} columns
* @returns {string|null}
*/
function createObjectContentHash(fieldType, item, columns) {
@@ -100,12 +100,13 @@ function createObjectContentHash(fieldType, item, columns) {
if ((columns?.length && fieldType === 'tables') || fieldType === 'views') {
const modifyDateStr = modifyDate ? modifyDate.toISOString() : '';
const objectColumns = columns.filter(col => col.objectId == item.objectId);
const colsComments = objectColumns.map(i => i.columnComment).join(',');
const colsComments = objectColumns
.filter(i => i.columnComment)
.map(i => `${i.columnId}/${i.columnComment}`)
.join('||');
const objectComment = item.objectComment || '';
return crypto
.createHash('sha256')
.update(modifyDateStr + colsComments)
.digest('hex');
return crypto.createHash('sha256').update(`${modifyDateStr}:${colsComments}:${objectComment}`).digest('hex');
}
if (!modifyDate) return null;

View File

@@ -1,10 +1,11 @@
module.exports = `
select c.object_id as objectId,
ep.value as columnComment
ep.value as columnComment,
c.column_id as columnId
from sys.columns c
inner join sys.objects o on c.object_id = o.object_id
INNER JOIN sys.schemas u ON u.schema_id=o.schema_id
left join sys.extended_properties ep on ep.major_id = c.object_id and ep.minor_id = c.column_id and ep.name = 'MS_Description'
INNER JOIN sys.extended_properties ep on ep.major_id = c.object_id and ep.minor_id = c.column_id and ep.name = 'MS_Description'
where o.type IN ('U', 'V') and o.object_id =OBJECT_ID_CONDITION and u.name =SCHEMA_NAME_CONDITION
order by c.column_id
`;