Skip to content

Commit

Permalink
don't escape default value for array columns
Browse files Browse the repository at this point in the history
  • Loading branch information
taras-dubyk committed Aug 31, 2023
1 parent 8316a59 commit 4def5c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ module.exports = ({ _, assignTemplates, templates, commentIfDeactivated, wrapCom
const isString = type => ['char', 'varchar', 'text', 'bit', 'varbit'].includes(type);
const isDateTime = type => ['date', 'time', 'timestamp', 'interval'].includes(type);

const decorateDefault = (type, defaultValue) => {
const decorateDefault = (type, defaultValue, isArrayType) => {
const constantsValues = ['current_timestamp', 'null'];
if ((isString(type) || isDateTime(type)) && !constantsValues.includes(_.toLower(defaultValue))) {
if ((isString(type) || isDateTime(type)) && !constantsValues.includes(_.toLower(defaultValue)) && !isArrayType) {
return wrapComment(defaultValue);
} else {
return defaultValue;
Expand Down
3 changes: 2 additions & 1 deletion forward_engineering/ddlProvider/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,9 @@ module.exports = (baseProvider, options, app) => {
? ' ' + createKeyConstraint(templates, true)(columnDefinition.uniqueKeyOptions).statement
: '';
const collation = columnDefinition.collationRule ? ` COLLATE "${columnDefinition.collationRule}"` : '';
const isArrayType = Array.isArray(columnDefinition.array_type) && columnDefinition.array_type.length > 0;
const defaultValue = !_.isUndefined(columnDefinition.default)
? ' DEFAULT ' + decorateDefault(type, columnDefinition.default)
? ' DEFAULT ' + decorateDefault(type, columnDefinition.default, isArrayType)
: '';

return commentIfDeactivated(
Expand Down

0 comments on commit 4def5c6

Please sign in to comment.