diff --git a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/alterEntityHelper.js b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/alterEntityHelper.js index c13da50..a7a1e9c 100644 --- a/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/alterEntityHelper.js +++ b/forward_engineering/hiveHelpers/helpers/alterScriptHelpers/alterEntityHelper.js @@ -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); diff --git a/forward_engineering/hiveHelpers/helpers/columnHelper.js b/forward_engineering/hiveHelpers/helpers/columnHelper.js index 0d26895..13ea2f9 100644 --- a/forward_engineering/hiveHelpers/helpers/columnHelper.js +++ b/forward_engineering/hiveHelpers/helpers/columnHelper.js @@ -358,10 +358,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 { @@ -370,7 +370,7 @@ const getColumnStatementParts = ({ collection, column }) => { }; }; -const getColumnsStatement = ({ collection, columns, isParentActivated }) => { +const getColumnsStatement = ({ collection, columns, isParentActivated, isAlterScript }) => { const columnStatements = []; const constraintStatements = []; @@ -378,11 +378,12 @@ const getColumnsStatement = ({ collection, columns, isParentActivated }) => { const { columnStatement, constraintsStatement } = getColumnStatementParts({ collection, column: { ...columns[name], name, isParentActivated }, + isAlterScript, }); columnStatements.push(columnStatement); - if (constraintsStatement) { + if (!isAlterScript && constraintsStatement) { constraintStatements.push(constraintsStatement); } } @@ -390,7 +391,7 @@ const getColumnsStatement = ({ collection, columns, isParentActivated }) => { return [...columnStatements, ...constraintStatements].join(',\n'); }; -const getColumnConstraintsStatement = ({ collection, column }) => { +const getColumnConstraintsStatement = ({ collection, column, isAlterScript }) => { const result = { inline: '', separate: '', @@ -445,7 +446,7 @@ const getColumnConstraintsStatement = ({ collection, column }) => { ); } - if (defaultValue) { + if (defaultValue && !isAlterScript) { result.inline = ` DEFAULT ${defaultValue}`; } diff --git a/forward_engineering/types.d.ts b/forward_engineering/types.d.ts index 8b356ac..f48e22c 100644 --- a/forward_engineering/types.d.ts +++ b/forward_engineering/types.d.ts @@ -1,20 +1,29 @@ export type ColumnDefinition = { - name: string; - type: string; - isActivated: boolean; - length?: number; - precision?: number; - primaryKey?: boolean; - scale?: number; - timePrecision?: number; - unique?: boolean; + name: string; + type: string; + nullable: boolean; + isActivated: boolean; + length?: number; + precision?: number; + primaryKey?: boolean; + scale?: number; + timePrecision?: number; + unique?: boolean; + check?: string; + properties?: Record; +}; + +export type ConstraintDtoColumn = { + name: string; + isActivated: boolean; }; export type KeyType = 'PRIMARY KEY' | 'UNIQUE' | 'CHECK'; export type ConstraintDto = { - keyType: KeyType; - expression?: string; + keyType: KeyType; + name: string; + columns?: ConstraintDtoColumn[]; }; export type JsonSchema = Record; diff --git a/forward_engineering/types.ts b/forward_engineering/types.ts deleted file mode 100644 index 53bc7f8..0000000 --- a/forward_engineering/types.ts +++ /dev/null @@ -1,29 +0,0 @@ -export type ColumnDefinition = { - name: string; - type: string; - nullable: boolean; - isActivated: boolean; - length?: number; - precision?: number; - primaryKey?: boolean; - scale?: number; - timePrecision?: number; - unique?: boolean; - check?: string; - properties?: Record; -}; - -export type ConstraintDtoColumn = { - name: string; - isActivated: boolean; -}; - -export type KeyType = 'PRIMARY KEY' | 'UNIQUE' | 'CHECK'; - -export type ConstraintDto = { - keyType: KeyType; - name: string; - columns?: ConstraintDtoColumn[]; -}; - -export type JsonSchema = Record;