11const { getFullTableName} = require ( "../ddlHelper" ) ;
22const { checkFieldPropertiesChanged} = require ( "../common" ) ;
3- const extractNewPropertyByName = ( collection , fieldName ) => {
4- return collection . role . compMod ?. newProperties ?. find ( newProperty => newProperty . name === fieldName ) ;
5- }
6-
7- const hasLengthChanged = ( collection , newFieldName , oldFieldName ) => {
3+ const hasLengthChanged = ( collection , oldFieldName , currentJsonSchema ) => {
84 const oldProperty = collection . role . properties [ oldFieldName ] ;
9- const newProperty = extractNewPropertyByName ( collection , newFieldName ) ;
105
116 const previousLength = oldProperty ?. length ;
12- const newLength = newProperty ?. length ;
7+ const newLength = currentJsonSchema ?. length ;
138 return previousLength !== newLength ;
149}
1510
16- const hasPrecisionOrScaleChanged = ( collection , newFieldName , oldFieldName ) => {
11+ const hasPrecisionOrScaleChanged = ( collection , oldFieldName , currentJsonSchema ) => {
1712 const oldProperty = collection . role . properties [ oldFieldName ] ;
18- const newProperty = extractNewPropertyByName ( collection , newFieldName ) ;
1913
2014 const previousPrecision = oldProperty ?. precision ;
21- const newPrecision = newProperty ?. precision ;
15+ const newPrecision = currentJsonSchema ?. precision ;
2216 const previousScale = oldProperty ?. scale ;
23- const newScale = newProperty ?. scale ;
17+ const newScale = currentJsonSchema ?. scale ;
2418
2519 return previousPrecision !== newPrecision || previousScale !== newScale ;
2620}
@@ -34,8 +28,8 @@ const getUpdateTypesScripts = (_, ddlProvider) => (collection) => {
3428 const hasTypeChanged = checkFieldPropertiesChanged ( jsonSchema . compMod , [ 'type' , 'mode' ] ) ;
3529 if ( ! hasTypeChanged ) {
3630 const oldName = jsonSchema . compMod . oldField . name ;
37- const isNewLength = hasLengthChanged ( collection , name , oldName ) ;
38- const isNewPrecisionOrScale = hasPrecisionOrScaleChanged ( collection , name , oldName ) ;
31+ const isNewLength = hasLengthChanged ( collection , oldName , jsonSchema ) ;
32+ const isNewPrecisionOrScale = hasPrecisionOrScaleChanged ( collection , oldName , jsonSchema ) ;
3933 return isNewLength || isNewPrecisionOrScale ;
4034 }
4135 return hasTypeChanged ;
@@ -44,8 +38,7 @@ const getUpdateTypesScripts = (_, ddlProvider) => (collection) => {
4438 ( [ name , jsonSchema ] ) => {
4539 const typeName = jsonSchema . compMod . newField . mode || jsonSchema . compMod . newField . type ;
4640 const columnName = wrapInQuotes ( name ) ;
47- const newProperty = extractNewPropertyByName ( collection , name ) ;
48- const typeConfig = _ . pick ( newProperty , [ 'length' , 'precision' , 'scale' ] ) ;
41+ const typeConfig = _ . pick ( jsonSchema , [ 'length' , 'precision' , 'scale' ] ) ;
4942 return ddlProvider . alterColumnType ( fullTableName , columnName , typeName , typeConfig ) ;
5043 }
5144 ) ;
0 commit comments