Skip to content

Commit 1c8a1d7

Browse files
Merge pull request #57 from ArzamastsevVladyslav/fix/HCK-3442-type-conversion
fix/HCK-3443
2 parents 7f6bd99 + 4522e90 commit 1c8a1d7

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
@@ -236,27 +236,21 @@ const getDeleteColumnScript = app => collection => {
236236
.map(([name]) => `ALTER TABLE IF EXISTS ${fullName} DROP COLUMN IF EXISTS ${wrapInQuotes(name)};`);
237237
};
238238

239-
const extractNewPropertyByName = (collection, fieldName) => {
240-
return collection.role.compMod?.newProperties?.find(newProperty => newProperty.name === fieldName);
241-
}
242-
243-
const hasLengthChanged = (collection, newFieldName, oldFieldName) => {
239+
const hasLengthChanged = (collection, oldFieldName, currentJsonSchema) => {
244240
const oldProperty = collection.role.properties[oldFieldName];
245-
const newProperty = extractNewPropertyByName(collection, newFieldName);
246241

247242
const previousLength = oldProperty?.length;
248-
const newLength = newProperty?.length;
243+
const newLength = currentJsonSchema?.length;
249244
return previousLength !== newLength;
250245
}
251246

252-
const hasPrecisionOrScaleChanged = (collection, newFieldName, oldFieldName) => {
247+
const hasPrecisionOrScaleChanged = (collection, oldFieldName, currentJsonSchema) => {
253248
const oldProperty = collection.role.properties[oldFieldName];
254-
const newProperty = extractNewPropertyByName(collection, newFieldName);
255249

256250
const previousPrecision = oldProperty?.precision;
257-
const newPrecision = newProperty?.precision;
251+
const newPrecision = currentJsonSchema?.precision;
258252
const previousScale = oldProperty?.scale;
259-
const newScale = newProperty?.scale;
253+
const newScale = currentJsonSchema?.scale;
260254

261255
return previousPrecision !== newPrecision || previousScale !== newScale;
262256
}
@@ -270,8 +264,8 @@ const getUpdateTypesScripts = (_, ddlProvider) => (collection) => {
270264
const hasTypeChanged = checkFieldPropertiesChanged(jsonSchema.compMod, ['type', 'mode']);
271265
if (!hasTypeChanged) {
272266
const oldName = jsonSchema.compMod.oldField.name;
273-
const isNewLength = hasLengthChanged(collection, name, oldName);
274-
const isNewPrecisionOrScale = hasPrecisionOrScaleChanged(collection, name, oldName);
267+
const isNewLength = hasLengthChanged(collection, oldName, jsonSchema);
268+
const isNewPrecisionOrScale = hasPrecisionOrScaleChanged(collection, oldName, jsonSchema);
275269
return isNewLength || isNewPrecisionOrScale;
276270
}
277271
return hasTypeChanged;
@@ -280,8 +274,7 @@ const getUpdateTypesScripts = (_, ddlProvider) => (collection) => {
280274
([name, jsonSchema]) => {
281275
const typeName = jsonSchema.compMod.newField.mode || jsonSchema.compMod.newField.type;
282276
const columnName = wrapInQuotes(name);
283-
const newProperty = extractNewPropertyByName(collection, name);
284-
const typeConfig = _.pick(newProperty, ['length', 'precision', 'scale']);
277+
const typeConfig = _.pick(jsonSchema, ['length', 'precision', 'scale']);
285278
return ddlProvider.alterColumnType(fullTableName, columnName, typeName, typeConfig);
286279
}
287280
);

0 commit comments

Comments
 (0)