Skip to content

Commit

Permalink
HCK-8740: [Oracle] RE from DDL file: missing quotation for default va…
Browse files Browse the repository at this point in the history
…lues reversed from 'ALTER COLUMN MODIFY'
  • Loading branch information
Nightlngale committed Nov 20, 2024
1 parent 580a189 commit 0d48c5a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ const shouldUseClobForJsonColumns = dbVersion => {
return dbVersionAsNumber < DbVersion.JSON_TYPE_SINCE;
};

module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, wrapComment, prepareName }) => {
module.exports = ({
_,
wrap,
assignTemplates,
templates,
commentIfDeactivated,
wrapComment,
wrapInSingleQuotes,
prepareName,
}) => {
const { getOptionsString } = require('./constraintHelper')({ _, prepareName });

const getColumnComments = (tableName, columnDefinitions) => {
Expand Down Expand Up @@ -43,9 +52,9 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w
return primaryKeyOptions || {};
} else if (unique) {
return uniqueKeyOptions || {};
} else {
return {};
}

return {};
};

const replaceTypeByVersion = (type, version) => {
Expand Down Expand Up @@ -75,8 +84,9 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w
return ` GENERATED${getGenerated(identity)} AS IDENTITY (${_.trim(getOptions(identity))})`;
} else if (defaultValue || defaultValue === 0) {
const onNull = defaultOnNull ? ' ON NULL' : '';
const value = typeof defaultValue === 'string' ? wrapInSingleQuotes(defaultValue) : defaultValue;

return ` DEFAULT${onNull} ${defaultValue}`;
return ` DEFAULT${onNull} ${value}`;
}
return '';
};
Expand Down Expand Up @@ -106,9 +116,9 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w
return ` ${type}(${precision || '*'},${scale})`;
} else if (_.isNumber(precision)) {
return ` ${type}(${precision})`;
} else {
return ` ${type}`;
}

return ` ${type}`;
};

const addPrecision = (type, precision) => {
Expand Down
16 changes: 8 additions & 8 deletions forward_engineering/ddlProvider/ddlHelpers/keyHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module.exports = (_, clean) => {
return false;
} else if (!column.unique) {
return false;
} else {
return true;
}

return true;
};

const isInlineUnique = column => {
Expand All @@ -25,9 +25,9 @@ module.exports = (_, clean) => {
return false;
} else if (!column.primaryKey) {
return false;
} else {
return true;
}

return true;
};

const isInlinePrimaryKey = column => {
Expand Down Expand Up @@ -113,17 +113,17 @@ module.exports = (_, clean) => {
const uniqueConstraints = mapProperties(jsonSchema, ([name, columnSchema]) => {
if (!isUniqueKey(columnSchema) || isInlineUnique(columnSchema)) {
return;
} else {
return hydrateUniqueOptions(columnSchema.uniqueKeyOptions, name, columnSchema.isActivated);
}

return hydrateUniqueOptions(columnSchema.uniqueKeyOptions, name, columnSchema.isActivated);
}).filter(Boolean);

const primaryKeyConstraints = mapProperties(jsonSchema, ([name, columnSchema]) => {
if (!isPrimaryKey(columnSchema) || isInlinePrimaryKey(columnSchema)) {
return;
} else {
return hydratePrimaryKeyOptions(columnSchema.primaryKeyOptions, name, columnSchema.isActivated);
}

return hydratePrimaryKeyOptions(columnSchema.primaryKeyOptions, name, columnSchema.isActivated);
}).filter(Boolean);

return [
Expand Down
2 changes: 2 additions & 0 deletions forward_engineering/ddlProvider/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = (baseProvider, options, app) => {
getNamePrefixedWithSchemaNameForScriptFormat,
wrapComment,
getColumnsList,
wrapInSingleQuotes,
prepareNameForScriptFormat,
} = require('../utils/general')(_);

Expand Down Expand Up @@ -58,6 +59,7 @@ module.exports = (baseProvider, options, app) => {
templates,
commentIfDeactivated,
wrapComment,
wrapInSingleQuotes,
prepareName,
});

Expand Down
7 changes: 5 additions & 2 deletions forward_engineering/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ module.exports = _ => {

const wrapInQuotes = name => `"${name}"`;

const wrapInSingleQuotes = name => `'${name}'`;

const prepareNameForScriptFormat = scriptFormat => name => {
return scriptFormat === 'nonquotedIdentifier' ? name : wrapInQuotes(name);
};

const wrapComment = comment => `'${comment.replace(/'/g, "''")}'`;

const getNamePrefixedWithSchemaNameForScriptFormat = scriptFormat => (name, schemaName) => {
if (schemaName) {
return `${prepareNameForScriptFormat(scriptFormat)(schemaName)}.${prepareNameForScriptFormat(scriptFormat)(name)}`;
Expand Down Expand Up @@ -183,6 +183,8 @@ module.exports = _ => {
return str.replaceAll("'", "''");
};

const wrapComment = comment => wrapInSingleQuotes(escapeSingleQuote(comment));

const getGroupItemsByCompMode = ({ newItems = [], oldItems = [] }) => {
const addedItems = newItems.filter(newItem => !oldItems.some(item => item.id === newItem.id));
const removedItems = [];
Expand Down Expand Up @@ -224,6 +226,7 @@ module.exports = _ => {
wrap,
wrapComment,
wrapInQuotes,
wrapInSingleQuotes,
getNamePrefixedWithSchemaNameForScriptFormat,
checkFieldPropertiesChanged,
getColumnsList,
Expand Down

0 comments on commit 0d48c5a

Please sign in to comment.