Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCK-7066: refactor: fix SonarCloud reports #111

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const mapRegularField = _ => (code, property, collectionRefsDefinitionsMap) => {
/**
* @type {DeltaDualityViewCompModCollectionRefsDefinitionsMapValue}
*/
const refDefinition = (collectionRefsDefinitionsMap || {})[property.refId];
const refDefinition = collectionRefsDefinitionsMap?.[property.refId];
const columnDefinition = refDefinition?.definition || {};
const columnName = columnDefinition.code || columnDefinition.name || '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const getDeletedIndexesScriptDtos =
newIndex,
}),
);
return !Boolean(correspondingNewIndex);
return !correspondingNewIndex;
});

return deletedIndexes.map(index => getDeleteIndexScriptDto({ ddlProvider })({ index, collection }));
Expand Down Expand Up @@ -157,7 +157,7 @@ const getAddedIndexesScriptDtos =
newIndex,
}),
);
return !Boolean(correspondingOldIndex);
return !correspondingOldIndex;
});

return addedIndexes.map(index => getAddIndexScriptDto({ ddlProvider })({ index, collection }));
Expand Down
4 changes: 2 additions & 2 deletions forward_engineering/alterScript/types/AlterScriptDto.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ class AlterScriptDto {
* @type {ModificationScript[]}
* */
const scriptModificationDtos = [];
if (Boolean(dropScript)) {
if (dropScript) {
scriptModificationDtos.push({
isDropScript: true,
script: dropScript,
});
}
if (Boolean(createScript)) {
if (createScript) {
scriptModificationDtos.push({
isDropScript: false,
script: createScript,
Expand Down
2 changes: 1 addition & 1 deletion forward_engineering/applyToInstanceHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const applyToInstance = async (connectionInfo, logger, app) => {
.split('\n\n')
.filter(Boolean)
.map(query => _.trim(_.trim(_.trim(query), '/'), ';'));
let i = 0;

let error;

await async.mapSeries(queries, async query => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w
const getColumnEncrypt = ({ encryption }) => {
if (_.isPlainObject(encryption) && !_.isEmpty(_.omit(encryption, 'id'))) {
const { ENCRYPTION_ALGORITHM, INTEGRITY_ALGORITHM, noSalt } = encryption;
return ` ENCRYPT${ENCRYPTION_ALGORITHM ? ` USING '${ENCRYPTION_ALGORITHM}'` : ''}${INTEGRITY_ALGORITHM ? ` '${INTEGRITY_ALGORITHM}'` : ''}${noSalt ? ' NO SALT' : ''}`;
const encryptionAlgorithm = ENCRYPTION_ALGORITHM ? ` USING '${ENCRYPTION_ALGORITHM}'` : '';
const integrityAlgorithm = INTEGRITY_ALGORITHM ? ` '${INTEGRITY_ALGORITHM}'` : '';
const salt = noSalt ? ' NO SALT' : '';

return ` ENCRYPT${encryptionAlgorithm}${integrityAlgorithm}${salt}`;
}
return '';
};
Expand All @@ -97,7 +101,7 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w

const addScalePrecision = (type, precision, scale) => {
if (_.isNumber(scale)) {
return ` ${type}(${precision ? precision : '*'},${scale})`;
return ` ${type}(${precision || '*'},${scale})`;
} else if (_.isNumber(precision)) {
return ` ${type}(${precision})`;
} else {
Expand All @@ -113,15 +117,23 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w
};

const timestamp = (fractSecPrecision, withTimeZone, localTimeZone) => {
return ` TIMESTAMP${_.isNumber(fractSecPrecision) ? `(${fractSecPrecision})` : ''}${withTimeZone ? ` WITH${localTimeZone ? ' LOCAL' : ''} TIME ZONE` : ''}`;
const fractSecPrecisionPart = _.isNumber(fractSecPrecision) ? `(${fractSecPrecision})` : '';
const localPart = localTimeZone ? ' LOCAL' : '';
const timeZonePart = withTimeZone ? ` WITH${localPart} TIME ZONE` : '';

return ` TIMESTAMP${fractSecPrecisionPart}${timeZonePart}`;
};

const intervalYear = yearPrecision => {
return ` INTERVAL YEAR${_.isNumber(yearPrecision) ? `(${yearPrecision})` : ''} TO MONTH`;
const yearPrecisionPart = _.isNumber(yearPrecision) ? `(${yearPrecision})` : '';
return ` INTERVAL YEAR${yearPrecisionPart} TO MONTH`;
};

const intervalDay = (dayPrecision, fractSecPrecision) => {
return ` INTERVAL DAY${_.isNumber(dayPrecision) ? `(${dayPrecision})` : ''} TO SECOND${_.isNumber(fractSecPrecision) ? `(${fractSecPrecision})` : ''}`;
const dayPrecisionPart = _.isNumber(dayPrecision) ? `(${dayPrecision})` : '';
const fractSecPrecisionPart = _.isNumber(fractSecPrecision) ? `(${fractSecPrecision})` : '';

return ` INTERVAL DAY${dayPrecisionPart} TO SECOND${fractSecPrecisionPart}`;
};

const decorateVector = (type, dimensionNumber, subtype) => {
Expand Down Expand Up @@ -150,7 +162,7 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w
const isIntervalYear = type => type === 'INTERVAL YEAR';
const isIntervalDay = type => type === 'INTERVAL DAY';
const isTimezone = type => type === 'TIMESTAMP';
const isVector = type => type === 'VECTOR';
const canDecorateVector = (type, dimension, subtype) => type === 'VECTOR' && (dimension || subtype);
const isJson = type => type === 'JSON';

const decorateType = (type, columnDefinition) => {
Expand Down Expand Up @@ -194,7 +206,7 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w
if (isUDTRef && schemaName) {
return ` "${schemaName}"."${type}"`;
}
if (isVector(type) && (dimension || subtype)) {
if (canDecorateVector(type, dimension, subtype)) {
return decorateVector(type, dimension, subtype);
}

Expand Down
15 changes: 9 additions & 6 deletions forward_engineering/ddlProvider/ddlHelpers/constraintHelper.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const _ = require('lodash');

module.exports = ({ wrapInQuotes, _ }) => {
const getOptionsString = ({ constraintName, deferClause, rely, validate, indexClause, exceptionClause }) => ({
constraintString: `${constraintName ? ` CONSTRAINT ${wrapInQuotes(_.trim(constraintName))}` : ''}`,
statement: `${deferClause ? ` ${deferClause}` : ''}${rely ? ` ${rely}` : ''}${
indexClause ? ` ${indexClause}` : ''
}${validate ? ` ${validate}` : ''}${exceptionClause ? ` ${exceptionClause}` : ''}`,
});
const getOptionsString = ({ constraintName, deferClause, rely, validate, indexClause, exceptionClause }) => {
const constraintString = constraintName ? ` CONSTRAINT ${wrapInQuotes(_.trim(constraintName))}` : '';
const statement = [deferClause, rely, indexClause, validate, exceptionClause].filter(Boolean).join(' ');

return {
constraintString,
statement: statement && ` ${statement}`,
};
};

return {
getOptionsString,
Expand Down
9 changes: 5 additions & 4 deletions forward_engineering/ddlProvider/ddlHelpers/indexHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ module.exports = ({ _, wrapInQuotes }) => {
indxKey,
column_expression,
}) => {
let options =
`${logging_clause ? ` ${_.toUpper(logging_clause)}` : ''}` +
`${tablespace ? ` TABLESPACE ${tablespace}` : ''}` +
`${index_compression ? ` ${index_compression}` : ''}`;
const loggingClause = logging_clause ? ` ${_.toUpper(logging_clause)}` : '';
const tableSpacePart = tablespace ? ` TABLESPACE ${tablespace}` : '';
const indexCompression = index_compression ? ` ${index_compression}` : '';

let options = `${loggingClause}${tableSpacePart}${indexCompression}`;

if (index_properties) {
options = ` ${index_properties}`;
Expand Down
4 changes: 2 additions & 2 deletions forward_engineering/ddlProvider/ddlHelpers/keyHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = (_, clean) => {
return jsonSchema.primaryKey
.filter(primaryKey => !_.isEmpty(primaryKey.compositePrimaryKey))
.map(primaryKey => ({
...hydratePrimaryKeyOptions(primaryKey, null, null, jsonSchema),
...hydratePrimaryKeyOptions(primaryKey, null, null),
columns: getKeys(primaryKey.compositePrimaryKey, jsonSchema),
}));
};
Expand All @@ -100,7 +100,7 @@ module.exports = (_, clean) => {
return jsonSchema.uniqueKey
.filter(uniqueKey => !_.isEmpty(uniqueKey.compositeUniqueKey))
.map(uniqueKey => ({
...hydrateUniqueOptions(uniqueKey, null, null, jsonSchema),
...hydrateUniqueOptions(uniqueKey, null, null),
columns: getKeys(uniqueKey.compositeUniqueKey, jsonSchema),
}));
};
Expand Down
19 changes: 12 additions & 7 deletions forward_engineering/ddlProvider/ddlHelpers/tableHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ module.exports = ({
opaque_format_spec,
clob_subquery,
reject_limit,
project_column,
location,
} = value;
const locationList = `(${_.map(
Expand Down Expand Up @@ -145,32 +144,37 @@ module.exports = ({

const getPartitionClause = (value, isActivated) => {
switch (value.partitionBy) {
case 'range':
case 'range': {
const interval = value.interval ? `\nINTERVAL (${value.interval})` : '';

return (
`${interval}` +
getTablespaceList(value.store_in_tablespaces) +
partitionsToString(value.range_partitions, 'range_partition_clause')
);
case 'list':
}
case 'list': {
return (
`${value.automatic ? ` AUTOMATIC` : ''}` +
getTablespaceList(value.store_in_tablespaces) +
partitionsToString(value.list_partitions, 'list_partition_clause')
);
case 'hash':
}
case 'hash': {
return getHashPartition(value);
case 'reference':
}
case 'reference': {
return (
`${value.constraint ? ` (${value.constraint})` : ''}` +
partitionsToString(value.reference_partition_descs, 'reference_partition_desc')
);
case 'system':
}
case 'system': {
if (value.system_partitioning_quantity) {
return ` PARTITIONS ${value.system_partitioning_quantity}`;
}
return partitionsToString(value.system_partition_descs, 'system_partition_desc');
}
case 'composite range': {
const subpartition = getSubpartition(value, isActivated);
return (
Expand All @@ -193,8 +197,9 @@ module.exports = ({
const hashPartition = getHashPartition(value);
return `${subpartition}${hashPartition}`;
}
default:
default: {
return '';
}
}
};

Expand Down
10 changes: 7 additions & 3 deletions forward_engineering/ddlProvider/ddlHelpers/udtHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ module.exports = ({ _, assignTemplates, templates, getNamePrefixedWithSchemaName
const getPlainUdt = (udt, getColumnDefinition) => {
const udtName = getNamePrefixedWithSchemaName(udt.name, udt.schemaName);
switch (udt.type) {
case 'OBJECT_UDT':
case 'OBJECT_UDT': {
return assignTemplates(templates.createObjectType, {
name: udtName,
properties: _.map(udt.properties, prop =>
getColumnDefinition(prop, templates.objectTypeColumnDefinition),
).join(',\n\t'),
});
}
case 'VARRAY':
case 'TABLE':
case 'TABLE': {
const defaultSize = udt.type === 'VARRAY' ? '(64)' : '';

return assignTemplates(templates.createCollectionType, {
name: udtName,
collectionType: udt.type,
size: _.isNumber(udt.size) ? `(${udt.size})` : defaultSize,
datatype: `${udt.ofType}${udt.nullable ? '' : ' NOT NULL'}`,
notPersistable: `${udt.notPersistable ? ' NOT PERSISTABLE' : ''}`,
});
default:
}
default: {
return '';
}
}
};

Expand Down
40 changes: 22 additions & 18 deletions forward_engineering/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,54 @@ module.exports = _ => {
};

const getDbData = containerData => {
return Object.assign({}, _.get(containerData, '[0]', {}), { name: getDbName(containerData) });
const dbData = _.get(containerData, '[0]', {});
return {
...dbData,
name: getDbName(containerData),
};
};

const getViewOn = viewData => _.get(viewData, '[0].viewOn');

const isRecursiveRelationship = foreignTableId => item =>
item.primaryTableId === foreignTableId && item.primaryTableId !== item.foreignTableId;

const rejectRecursiveRelationships = foreignTableToRelationshipData => {
return Object.keys(foreignTableToRelationshipData).reduce((result, foreignTableId) => {
const tables = foreignTableToRelationshipData[foreignTableId].filter(item => {
const tables = foreignTableToRelationshipData[item.primaryTableId];
const foreignRelatedTables = foreignTableToRelationshipData[foreignTableId].filter(table => {
const primaryRelatedTables = foreignTableToRelationshipData[table.primaryTableId];

if (!Array.isArray(tables)) {
if (!Array.isArray(primaryRelatedTables)) {
return true;
}

return !tables.some(
item => item.primaryTableId === foreignTableId && item.primaryTableId !== item.foreignTableId,
);
return !primaryRelatedTables.some(isRecursiveRelationship(foreignTableId));
});

if (_.isEmpty(tables)) {
if (_.isEmpty(foreignRelatedTables)) {
return result;
}

return Object.assign({}, result, {
[foreignTableId]: tables,
});
return {
...result,
[foreignTableId]: foreignRelatedTables,
};
}, {});
};

const filterRecursiveRelationships = foreignTableToRelationshipData => {
return Object.keys(foreignTableToRelationshipData).reduce((result, foreignTableId) => {
const tables = foreignTableToRelationshipData[foreignTableId].filter(item => {
const tables = foreignTableToRelationshipData[item.primaryTableId];
const foreignRelatedTables = foreignTableToRelationshipData[foreignTableId].filter(item => {
const primaryRelatedTables = foreignTableToRelationshipData[item.primaryTableId];

if (!Array.isArray(tables)) {
if (!Array.isArray(primaryRelatedTables)) {
return false;
}

return tables.some(
item => item.primaryTableId === foreignTableId && item.primaryTableId !== item.foreignTableId,
);
return primaryRelatedTables.some(isRecursiveRelationship(foreignTableId));
});

return result.concat(tables);
return result.concat(foreignRelatedTables);
}, []);
};

Expand Down
Loading