@@ -147,6 +147,7 @@ module.exports = (baseProvider, options, app) => {
147147 unlogged,
148148 selectStatement,
149149 partitionOf,
150+ partitionBounds,
150151 } ,
151152 isActivated
152153 ) {
@@ -163,24 +164,30 @@ module.exports = (baseProvider, options, app) => {
163164 key => key . statement
164165 ) ;
165166 const keyConstraintsString = generateConstraintsString ( dividedKeysConstraints , isActivated ) ;
167+ const keyConstraintsValue = partitionOf ? keyConstraintsString ?. slice ( 1 ) : keyConstraintsString
166168
167169 const dividedForeignKeys = divideIntoActivatedAndDeactivated ( foreignKeyConstraints , key => key . statement ) ;
168170 const foreignKeyConstraintsString = generateConstraintsString ( dividedForeignKeys , isActivated ) ;
169171
170172 const columnDescriptions = '\n' + getColumnComments ( tableName , columnDefinitions ) ;
171173 const template = partitionOf ? templates . createTablePartitionOf : templates . createTable ;
172174
173- const checkConstraintPrefix = partitionOf && ! keyConstraintsString ? '\n\t' : ',\n\t'
175+ const checkConstraintPrefix = partitionOf && ! keyConstraintsString ? '\n\t' : ',\n\t' ;
176+ const checkConstraintsValue = ! _ . isEmpty ( checkConstraints )
177+ ? wrap ( _ . join ( checkConstraints , ',\n\t' ) , checkConstraintPrefix , '' )
178+ : '' ;
179+
180+ const isEmptyPartitionBody = partitionOf && ! keyConstraintsValue && ! checkConstraintsValue && ! foreignKeyConstraintsString
181+ const openParenthesis = isEmptyPartitionBody ? '' : '('
182+ const closeParenthesis = isEmptyPartitionBody ? '' : ')'
174183
175184 const tableStatement = assignTemplates ( template , {
176185 temporary : getTableTemporaryValue ( temporary , unlogged ) ,
177186 ifNotExist : ifNotExistStr ,
178187 name : tableName ,
179188 columnDefinitions : ! partitionOf ? '\t' + _ . join ( columns , ',\n\t' ) : '' ,
180- keyConstraints : partitionOf ? keyConstraintsString ?. slice ( 1 ) : keyConstraintsString ,
181- checkConstraints : ! _ . isEmpty ( checkConstraints )
182- ? wrap ( _ . join ( checkConstraints , ',\n\t' ) , checkConstraintPrefix , '' )
183- : '' ,
189+ keyConstraints : keyConstraintsValue ,
190+ checkConstraints : checkConstraintsValue ,
184191 foreignKeyConstraints : foreignKeyConstraintsString ,
185192 options : getTableOptions ( {
186193 inherits,
@@ -190,10 +197,13 @@ module.exports = (baseProvider, options, app) => {
190197 storage_parameter,
191198 table_tablespace_name,
192199 selectStatement,
200+ partitionBounds,
193201 } ) ,
194202 comment : description ? comment : '' ,
195- columnDescriptions,
196203 partitionOf : partitionOf ? ` PARTITION OF ${ partitionOf } ` : '' ,
204+ columnDescriptions,
205+ openParenthesis,
206+ closeParenthesis,
197207 } ) ;
198208
199209 return tableStatement ;
@@ -547,6 +557,7 @@ module.exports = (baseProvider, options, app) => {
547557 'on_commit' ,
548558 'storage_parameter' ,
549559 'table_tablespace_name' ,
560+ 'partitionBounds'
550561 ) ,
551562 } ;
552563 } ,
0 commit comments