@@ -106,6 +106,16 @@ module.exports = (baseProvider, options, app) => {
106106 tab,
107107 } ) ;
108108
109+ const hasActiveConstraints = ( {
110+ foreignKeyConstraints = [ ] ,
111+ compositePrimaryKeys = [ ] ,
112+ compositeUniqueKeys = [ ] ,
113+ } ) => {
114+ return [ ...foreignKeyConstraints , ...compositePrimaryKeys , ...compositeUniqueKeys ] . some (
115+ constraint => constraint . isActivated ,
116+ ) ;
117+ } ;
118+
109119 const getOutOfLineConstraints = (
110120 isParentActivated ,
111121 foreignKeyConstraints = [ ] ,
@@ -117,7 +127,7 @@ module.exports = (baseProvider, options, app) => {
117127 isParentActivated ? commentIfDeactivated ( constraint . statement , constraint ) : constraint . statement ,
118128 ) ;
119129
120- return ! isEmpty ( constraints ) ? ', \n\t\t' + constraints . join ( ',\n\t\t' ) : '' ;
130+ return isEmpty ( constraints ) ? '' : ' \n\t\t' + constraints . join ( ',\n\t\t' ) ;
121131 } ;
122132
123133 function insertNewlinesAtEdges ( input ) {
@@ -356,7 +366,6 @@ module.exports = (baseProvider, options, app) => {
356366 const copyOptions = tab ( getCopyOptions ( tableData . copyOptions ) , ' ' ) ;
357367 const atOrBefore = tab ( getAtOrBefore ( tableData . cloneParams ) , ' ' ) ;
358368 const columns = tableData . columns . map ( column => commentIfDeactivated ( column . statement , column ) ) ;
359- const columnDefinitions = joinActivatedAndDeactivatedStatements ( { statements : columns , indent : '\n\t\t' } ) ;
360369 const tagsStatement = getTagStatement ( {
361370 tags : tableData . tableTags ,
362371 isCaseSensitive : tableData . isCaseSensitive ,
@@ -446,7 +455,11 @@ module.exports = (baseProvider, options, app) => {
446455 ) ,
447456 orReplace,
448457 tableIfNotExists,
449- column_definitions : columnDefinitions ,
458+ column_definitions : joinActivatedAndDeactivatedStatements ( {
459+ statements : columns ,
460+ indent : '\n\t\t' ,
461+ keepLastDelimiter : hasActiveConstraints ( tableData ) ,
462+ } ) ,
450463 out_of_line_constraints : getOutOfLineConstraints (
451464 isActivated ,
452465 tableData . foreignKeyConstraints ,
@@ -466,7 +479,11 @@ module.exports = (baseProvider, options, app) => {
466479 [ clusterKeys , stageFileFormat , copyOptions , dataRetentionTime , copyGrants , tagsStatement ] ,
467480 comment ,
468481 ) ,
469- column_definitions : columnDefinitions ,
482+ column_definitions : joinActivatedAndDeactivatedStatements ( {
483+ statements : columns ,
484+ indent : '\n\t\t' ,
485+ keepLastDelimiter : hasActiveConstraints ( tableData ) ,
486+ } ) ,
470487 out_of_line_constraints : getOutOfLineConstraints (
471488 isActivated ,
472489 tableData . foreignKeyConstraints ,
0 commit comments