Skip to content

Commit

Permalink
Merge branch 'develop' into HCK-8554-display-a-proper-error-in-case-a…
Browse files Browse the repository at this point in the history
…-user-needs-to-consent-hackolade-azure-ad-app-to-allow-access-his-resources
  • Loading branch information
Vitalii4as authored Oct 29, 2024
2 parents d0c2567 + 010437b commit 0fb1c8e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
16 changes: 8 additions & 8 deletions forward_engineering/configs/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ module.exports = {
dropType: 'DROP TYPE IF EXISTS ${name}${terminator}',

createSchemaComment:
"EXEC sp_addextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}${terminator}",
"EXEC sp_addextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}${terminator}",

createTableComment:
"EXEC sp_addextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'table', ${tableName}${terminator}",
"EXEC sp_addextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'table', ${tableName}${terminator}",

createColumnComment:
"EXEC sp_addextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'table', ${tableName}, 'column', ${columnName}${terminator}",
"EXEC sp_addextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'table', ${tableName}, 'column', ${columnName}${terminator}",

createViewComment:
"EXEC sp_addextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'view', ${viewName}${terminator}",
"EXEC sp_addextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'view', ${viewName}${terminator}",

dropSchemaComment: "EXEC sp_dropextendedproperty 'MS_Description', 'schema', ${schemaName}${terminator}",

Expand All @@ -114,14 +114,14 @@ module.exports = {
"EXEC sp_dropextendedproperty 'MS_Description', 'schema', ${schemaName}, 'view', ${viewName}${terminator}",

updateSchemaComment:
"EXEC sp_updateextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}${terminator}",
"EXEC sp_updateextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}${terminator}",

updateTableComment:
"EXEC sp_updateextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'table', ${tableName}${terminator}",
"EXEC sp_updateextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'table', ${tableName}${terminator}",

updateColumnComment:
"EXEC sp_updateextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'table', ${tableName}, 'column', ${columnName}${terminator}",
"EXEC sp_updateextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'table', ${tableName}, 'column', ${columnName}${terminator}",

updateViewComment:
"EXEC sp_updateextendedproperty 'MS_Description', '${value}', 'schema', ${schemaName}, 'view', ${viewName}${terminator}",
"EXEC sp_updateextendedproperty 'MS_Description', N'${value}', 'schema', ${schemaName}, 'view', ${viewName}${terminator}",
};
27 changes: 18 additions & 9 deletions forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = (baseProvider, options, app) => {
const { wrapIfNotExistSchema, wrapIfNotExistDatabase, wrapIfNotExistTable, wrapIfNotExistView } =
require('./helpers/ifNotExistStatementHelper')(app);
const { getPartitionedTables, getCreateViewData } = require('./helpers/viewHelper')(app);
const { getFullTableName } = require('./utils/general')(_);
const { getFullTableName, escapeSpecialCharacters } = require('./utils/general')(_);

const terminator = getTerminator(options);

Expand Down Expand Up @@ -773,7 +773,7 @@ module.exports = (baseProvider, options, app) => {

createSchemaComment({ schemaName, comment, customTerminator }) {
return assignTemplates(templates.createSchemaComment, {
value: comment,
value: escapeSpecialCharacters(comment),
schemaName: wrapInBrackets(schemaName),
terminator: customTerminator ?? terminator,
});
Expand All @@ -783,8 +783,9 @@ module.exports = (baseProvider, options, app) => {
if (!schemaName) {
return '';
}

return assignTemplates(templates.createTableComment, {
value: comment,
value: escapeSpecialCharacters(comment),
schemaName: wrapInBrackets(schemaName),
tableName: wrapInBrackets(tableName),
terminator: customTerminator ?? terminator,
Expand All @@ -795,8 +796,9 @@ module.exports = (baseProvider, options, app) => {
if (!tableName || !columnName) {
return '';
}

return assignTemplates(templates.createColumnComment, {
value: comment,
value: escapeSpecialCharacters(comment),
schemaName: wrapInBrackets(schemaName),
tableName: wrapInBrackets(tableName),
columnName: wrapInBrackets(columnName),
Expand All @@ -808,8 +810,9 @@ module.exports = (baseProvider, options, app) => {
if (!schemaName) {
return '';
}

return assignTemplates(templates.createViewComment, {
value: comment,
value: escapeSpecialCharacters(comment),
schemaName: wrapInBrackets(schemaName),
viewName: wrapInBrackets(viewName),
terminator: customTerminator ?? terminator,
Expand All @@ -827,6 +830,7 @@ module.exports = (baseProvider, options, app) => {
if (!schemaName) {
return '';
}

return assignTemplates(templates.dropTableComment, {
schemaName: wrapInBrackets(schemaName),
tableName: wrapInBrackets(tableName),
Expand All @@ -838,6 +842,7 @@ module.exports = (baseProvider, options, app) => {
if (!schemaName || !tableName) {
return '';
}

return assignTemplates(templates.dropColumnComment, {
schemaName: wrapInBrackets(schemaName),
tableName: wrapInBrackets(tableName),
Expand All @@ -850,6 +855,7 @@ module.exports = (baseProvider, options, app) => {
if (!schemaName) {
return '';
}

return assignTemplates(templates.dropViewComment, {
schemaName: wrapInBrackets(schemaName),
viewName: wrapInBrackets(viewName),
Expand All @@ -859,7 +865,7 @@ module.exports = (baseProvider, options, app) => {

updateSchemaComment({ schemaName, comment, customTerminator }) {
return assignTemplates(templates.updateSchemaComment, {
value: comment,
value: escapeSpecialCharacters(comment),
schemaName: wrapInBrackets(schemaName),
terminator: customTerminator ?? terminator,
});
Expand All @@ -869,8 +875,9 @@ module.exports = (baseProvider, options, app) => {
if (!schemaName) {
return '';
}

return assignTemplates(templates.updateTableComment, {
value: comment,
value: escapeSpecialCharacters(comment),
schemaName: wrapInBrackets(schemaName),
tableName: wrapInBrackets(tableName),
terminator: customTerminator ?? terminator,
Expand All @@ -881,8 +888,9 @@ module.exports = (baseProvider, options, app) => {
if (!schemaName || !tableName) {
return '';
}

return assignTemplates(templates.updateColumnComment, {
value: comment,
value: escapeSpecialCharacters(comment),
schemaName: wrapInBrackets(schemaName),
tableName: wrapInBrackets(tableName),
columnName: wrapInBrackets(columnName),
Expand All @@ -894,8 +902,9 @@ module.exports = (baseProvider, options, app) => {
if (!schemaName) {
return '';
}

return assignTemplates(templates.updateViewComment, {
value: comment,
value: escapeSpecialCharacters(comment),
schemaName: wrapInBrackets(schemaName),
viewName: wrapInBrackets(viewName),
terminator: customTerminator ?? terminator,
Expand Down
25 changes: 13 additions & 12 deletions forward_engineering/helpers/columnDefinitionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const templates = require('../configs/templates');
module.exports = app => {
const { assignTemplates } = app.require('@hackolade/ddl-fe-utils');
const _ = app.require('lodash');
const { wrapInBrackets, escapeSpecialCharacters } = require('../utils/general')(_);

const addLength = (type, length) => {
return `${type}(${length})`;
Expand All @@ -15,9 +16,9 @@ module.exports = app => {
const addScalePrecision = (type, precision, scale) => {
if (_.isNumber(scale)) {
return `${type}(${precision},${scale})`;
} else {
return `${type}(${precision})`;
}

return `${type}(${precision})`;
};

const addPrecision = (type, precision) => {
Expand Down Expand Up @@ -69,17 +70,17 @@ module.exports = app => {
return `'${escapeQuotes(defaultValue)}'`;
} else if (type === 'XML') {
return `CAST(N'${defaultValue}' AS xml)`;
} else {
return defaultValue;
}

return defaultValue;
};

const getIdentity = identity => {
if (!identity.seed || !identity.increment) {
return '';
} else {
return ` IDENTITY(${identity.seed}, ${identity.increment})`;
}

return ` IDENTITY(${identity.seed}, ${identity.increment})`;
};

const addClustered = (statement, columnDefinition) => {
Expand All @@ -89,9 +90,9 @@ module.exports = app => {

if (!columnDefinition.clustered) {
return statement + ' NONCLUSTERED';
} else {
return statement + ' CLUSTERED';
}

return statement + ' CLUSTERED';
};

const getEncryptedWith = encryption => {
Expand All @@ -118,10 +119,10 @@ module.exports = app => {
return '';
}
const commentStatement = assignTemplates(templates.createColumnComment, {
value: comment,
schemaName: `[${schemaName}]`,
tableName: `[${tableName}]`,
columnName: `[${name}]`,
value: escapeSpecialCharacters(comment),
schemaName: wrapInBrackets(schemaName),
tableName: wrapInBrackets(tableName),
columnName: wrapInBrackets(name),
terminator,
});

Expand Down
2 changes: 1 addition & 1 deletion forward_engineering/helpers/constraintsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = app => {

const cleaned = clean(_.omit(keyData, 'keyType', 'indexOption', 'columns'));

return !_.isEmpty(cleaned) || keyData.columns?.length > 1;
return !_.isEmpty(cleaned) || keyData.columns?.length;
};

const adaptIndexOptions = indexOption => {
Expand Down
8 changes: 8 additions & 0 deletions forward_engineering/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = _ => {
} else if (!isNaN(name)) {
return `\`${name}\``;
}

return name;
};
const replaceSpaceWithUnderscore = (name = '') => {
Expand All @@ -79,6 +80,7 @@ module.exports = _ => {
const getFullCollectionName = collectionSchema => {
const collectionName = getEntityName(collectionSchema);
const bucketName = collectionSchema.compMod?.keyspaceName;

return getNamePrefixedWithSchemaName(collectionName, bucketName);
};

Expand Down Expand Up @@ -156,6 +158,10 @@ module.exports = _ => {
return `[${name}]`;
};

const escapeSpecialCharacters = (name = '') => {
return name.replace(/'/g, "''");
};

const buildScript = statements => {
const formattedScripts = statements
.filter(Boolean)
Expand Down Expand Up @@ -183,6 +189,7 @@ module.exports = _ => {
if (!newProperty && !oldProperty) {
return;
}

return !_.isEqual(newProperty, oldProperty);
};

Expand All @@ -209,6 +216,7 @@ module.exports = _ => {
commentDeactivatedInlineKeys,
buildScript,
wrapInBrackets,
escapeSpecialCharacters,
getFullEntityName,
getFullTableName,
getFullCollectionName,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SQLServer",
"version": "0.2.9",
"version": "0.2.10",
"author": "hackolade",
"engines": {
"hackolade": "7.7.10",
Expand Down

0 comments on commit 0fb1c8e

Please sign in to comment.