Skip to content
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 @@ -245,7 +245,7 @@ const getAddColumnsScripts = (definitions, provider) => entity => {
const entityData = { ...entity, ..._.omit(entity.role, ['properties']) };
const { columns } = getColumns(entityData, true, definitions);
const properties = getEntityProperties(entity);
const columnStatement = getColumnsStatement({ columns });
const columnStatement = getColumnsStatement({ columns, isAlterScript: true });
const fullCollectionName = generateFullEntityName(entity);
const { hydratedAddIndexes, hydratedDropIndexes } = hydrateIndex(entity, properties, definitions);
const modifyScript = generateModifyCollectionScript(entity, definitions, provider);
Expand Down
13 changes: 7 additions & 6 deletions forward_engineering/helpers/columnHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ const getColumns = (jsonSchema, areColumnConstraintsAvailable, definitions) => {
return { columns, deactivatedColumnNames };
};

const getColumnStatementParts = ({ collection, column }) => {
const getColumnStatementParts = ({ collection, column, isAlterScript }) => {
const { name, type, comment, isActivated, isParentActivated } = column;
const commentStatement = comment ? ` COMMENT '${encodeStringLiteral(comment)}'` : '';
const { inline, separate } = getColumnConstraintsStatement({ collection, column });
const { inline, separate } = getColumnConstraintsStatement({ collection, column, isAlterScript });
const isColumnActivated = isParentActivated ? isActivated : true;

return {
Expand All @@ -356,27 +356,28 @@ const getColumnStatementParts = ({ collection, column }) => {
};
};

const getColumnsStatement = ({ collection, columns, isParentActivated }) => {
const getColumnsStatement = ({ collection, columns, isParentActivated, isAlterScript }) => {
const columnStatements = [];
const constraintStatements = [];

for (const name of Object.keys(columns)) {
const { columnStatement, constraintsStatement } = getColumnStatementParts({
collection,
column: { ...columns[name], name, isParentActivated },
isAlterScript,
});

columnStatements.push(columnStatement);

if (constraintsStatement) {
if (!isAlterScript && constraintsStatement) {
constraintStatements.push(constraintsStatement);
}
}

return [...columnStatements, ...constraintStatements].join(',\n');
};

const getColumnConstraintsStatement = ({ collection, column }) => {
const getColumnConstraintsStatement = ({ collection, column, isAlterScript }) => {
const result = {
inline: '',
separate: '',
Expand Down Expand Up @@ -431,7 +432,7 @@ const getColumnConstraintsStatement = ({ collection, column }) => {
);
}

if (defaultValue) {
if (defaultValue && !isAlterScript) {
result.inline = ` DEFAULT ${defaultValue}`;
}

Expand Down