11module . exports = ( app , ddlProvider ) => {
2+ const _ = app . require ( 'lodash' ) ;
23 const { AlterScriptDto } = require ( '../types/AlterScriptDto' ) ;
3- const { sanitizeConstraintName } = require ( '../../../helpers/general' ) ( app ) ;
4+ const { sanitizeConstraintName, hasType, getTableName } = require ( '../../../helpers/general' ) ( app ) ;
5+ const { decorateDefault } = require ( '../../columnDefinitionHelper' ) ( app ) ;
46
57 const getDefaultValueChangeDto = ( collection , fullName ) => {
68 const scripts = [ ] ;
79
810 const getDefaultConstraintName = columnName => sanitizeConstraintName ( `DF_${ fullName } _${ columnName } ` ) ;
911
1012 Object . entries ( collection ?. properties ?? [ ] ) . forEach ( ( [ columnName , collectionSchema ] ) => {
13+ const type = hasType ( collectionSchema . type )
14+ ? _ . toUpper ( collectionSchema . type )
15+ : getTableName ( collectionSchema . type , collectionSchema . schemaName ) ;
16+
1117 const newDefaultValue = collectionSchema . default ;
1218 const newConstraintName = collectionSchema . defaultConstraintName ;
1319 const oldDefaultValue = collection . role . properties [ columnName ] ?. default ;
@@ -24,6 +30,7 @@ module.exports = (app, ddlProvider) => {
2430 ! ! oldConstraintName &&
2531 ! ! newConstraintName &&
2632 oldConstraintName !== newConstraintName ;
33+ const decoratedValue = decorateDefault ( type , newDefaultValue ) ;
2734
2835 switch ( true ) {
2936 case defaultValueWasRemoved : {
@@ -40,7 +47,7 @@ module.exports = (app, ddlProvider) => {
4047 {
4148 constraintName,
4249 columnName,
43- value : newDefaultValue ,
50+ value : decoratedValue ,
4451 } ,
4552 fullName ,
4653 ) ;
@@ -58,7 +65,7 @@ module.exports = (app, ddlProvider) => {
5865 {
5966 constraintName,
6067 columnName,
61- value : newDefaultValue ,
68+ value : decoratedValue ,
6269 } ,
6370 fullName ,
6471 ) ;
@@ -72,7 +79,7 @@ module.exports = (app, ddlProvider) => {
7279 {
7380 constraintName : newConstraintName ,
7481 columnName,
75- value : newDefaultValue ,
82+ value : decoratedValue ,
7683 } ,
7784 fullName ,
7885 ) ;
0 commit comments