Skip to content

Commit c889407

Browse files
author
unknown
committed
Improved lookup of updated string/numeric attributes which fixes the problem with custom naming conventions
1 parent 1a9e682 commit c889407

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

forward_engineering/helpers/alterScriptHelpers/alterEntityHelper.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,21 @@ const getFullTableName = (_) => (collection) => {
123123
return getNamePrefixedWithSchemaName(tableName, schemaName);
124124
}
125125

126-
const extractNewPropertyByName = (collection, fieldName) => {
127-
return collection.role.compMod?.newProperties?.find(newProperty => newProperty.name === fieldName);
128-
}
129-
130-
const hasLengthChanged = (collection, newFieldName, oldFieldName) => {
126+
const hasLengthChanged = (collection, oldFieldName, currentJsonSchema) => {
131127
const oldProperty = collection.role.properties[oldFieldName];
132-
const newProperty = extractNewPropertyByName(collection, newFieldName);
133128

134129
const previousLength = oldProperty?.length;
135-
const newLength = newProperty?.length;
130+
const newLength = currentJsonSchema?.length;
136131
return previousLength !== newLength;
137132
}
138133

139-
const hasPrecisionOrScaleChanged = (collection, newFieldName, oldFieldName) => {
134+
const hasPrecisionOrScaleChanged = (collection, oldFieldName, currentJsonSchema) => {
140135
const oldProperty = collection.role.properties[oldFieldName];
141-
const newProperty = extractNewPropertyByName(collection, newFieldName);
142136

143137
const previousPrecision = oldProperty?.precision;
144-
const newPrecision = newProperty?.precision;
138+
const newPrecision = currentJsonSchema?.precision;
145139
const previousScale = oldProperty?.scale;
146-
const newScale = newProperty?.scale;
140+
const newScale = currentJsonSchema?.scale;
147141

148142
return previousPrecision !== newPrecision || previousScale !== newScale;
149143
}
@@ -157,8 +151,8 @@ const getUpdateTypesScripts = (_, ddlProvider) => (collection) => {
157151
const hasTypeChanged = checkFieldPropertiesChanged(jsonSchema.compMod, ['type', 'mode']);
158152
if (!hasTypeChanged) {
159153
const oldName = jsonSchema.compMod.oldField.name;
160-
const isNewLength = hasLengthChanged(collection, name, oldName);
161-
const isNewPrecisionOrScale = hasPrecisionOrScaleChanged(collection, name, oldName);
154+
const isNewLength = hasLengthChanged(collection, oldName, jsonSchema);
155+
const isNewPrecisionOrScale = hasPrecisionOrScaleChanged(collection, oldName, jsonSchema);
162156
return isNewLength || isNewPrecisionOrScale;
163157
}
164158
return hasTypeChanged;
@@ -167,8 +161,7 @@ const getUpdateTypesScripts = (_, ddlProvider) => (collection) => {
167161
([name, jsonSchema]) => {
168162
const typeName = jsonSchema.compMod.newField.mode || jsonSchema.compMod.newField.type;
169163
const columnName = wrapInQuotes(name);
170-
const newProperty = extractNewPropertyByName(collection, name);
171-
const typeConfig = _.pick(newProperty, ['length', 'precision', 'scale']);
164+
const typeConfig = _.pick(jsonSchema, ['length', 'precision', 'scale']);
172165
return ddlProvider.alterColumnType(fullTableName, columnName, typeName, typeConfig);
173166
}
174167
);

0 commit comments

Comments
 (0)