@@ -9,7 +9,7 @@ const { mergeArrays, checkIsOldModel, fieldTypeCompatible } = require('./updateH
9
9
const { getViewScript } = require ( './updateHelpers/viewHelper' ) ;
10
10
const { getIndexTable, getDataColumnIndex } = require ( './updateHelpers/indexHelper' ) ;
11
11
const { getUdtScript, sortAddedUdt } = require ( './updateHelpers/udtHelper' ) ;
12
- const { alterTablePrefix, getDelete, hydrateColumn } = require ( './updateHelpers/tableHelper' ) ;
12
+ const { alterTablePrefix, getDelete, hydrateColumn, isTableChange , getTableParameter } = require ( './updateHelpers/tableHelper' ) ;
13
13
14
14
let _ ;
15
15
@@ -144,12 +144,7 @@ const getIsColumnInIndex = (item, columnName, data) => {
144
144
return [ ...searchIndexes , ...secIndexes ] . includes ( columnName ) ;
145
145
} ;
146
146
147
- const getIsChangeTable = compMod => {
148
- const tableProperties = [ 'name' , 'isActivated' ] ;
149
- return tableProperties . some ( property => ! _ . isEqual ( compMod [ property ] ?. new , compMod [ property ] ?. old ) ) ;
150
- }
151
-
152
- const getPropertiesForUpdateTable = properties => {
147
+ const getPropertiesForUpdateTable = ( properties = [ ] ) => {
153
148
const newProperties = Object . entries ( properties ) . map ( ( [ name , value ] ) => {
154
149
if ( ! value . compMod ) {
155
150
return [ name , value ] ;
@@ -174,10 +169,17 @@ const getUpdateTable = updateData => {
174
169
const { oldName, newName } = getCollectionName ( item . role ?. compMod ) ;
175
170
176
171
const indexTableScript = getIndexTable ( item , updateData . data ) ;
172
+ const compModeWithName = { ...item . role ?. compMod || { } , name : { new : newName , old : oldName } }
177
173
178
- const isChangeTable = getIsChangeTable ( { ...item . role ?. compMod , name : { new : newName , old : oldName } } || { } ) ;
174
+ const tableIsChange = isTableChange ( {
175
+ item : {
176
+ ...item ,
177
+ role : { ...item . role , compMod : compModeWithName } ,
178
+ } ,
179
+ data : updateData . data ,
180
+ } ) ;
179
181
180
- if ( ! isChangeTable ) {
182
+ if ( ! tableIsChange ) {
181
183
const tableName = updateData . tableName || oldName || newName ;
182
184
const optionScript = getOptionsScript ( item . role ?. compMod || { } , tableName , updateData . isOptionScript ) ;
183
185
return [
@@ -203,7 +205,12 @@ const getUpdateTable = updateData => {
203
205
item : {
204
206
...item ,
205
207
properties : getPropertiesForUpdateTable ( item . role ?. properties || item . properties ) ,
208
+ role : {
209
+ ...( item ?. role || { } ) ,
210
+ tableOptions : getTableParameter ( item , 'tableOptions' ) || { } ,
211
+ }
206
212
} ,
213
+ modifiedProperties : item . properties ,
207
214
isKeyspaceActivated : true ,
208
215
} ;
209
216
const deleteScript = getDeleteTable ( { ...data , tableName : oldName } ) ;
@@ -324,29 +331,13 @@ const handleItem = (item, udtMap, generator, data) => {
324
331
const getAddTable = ( addTableData ) => {
325
332
const table = addTableData . item ;
326
333
const data = addTableData . data ;
327
- const tableProperties = table . properties || { } ;
328
- let partitionKeys = [ ] ;
329
- let clusteringKeys = [ ] ;
330
- if ( tableProperties ) {
331
- partitionKeys = Object . keys ( tableProperties ) . map ( key => {
332
- if ( tableProperties [ key ] . compositePartitionKey ) {
333
- return { keyId : tableProperties [ key ] . GUID } ;
334
- }
335
- return ;
336
- } ) . filter ( item => item ) ;
337
-
338
- clusteringKeys = Object . keys ( tableProperties ) . map ( key => {
339
- if ( tableProperties [ key ] . compositeClusteringKey ) {
340
- return { keyId : tableProperties [ key ] . GUID } ;
341
- }
342
- return ;
343
- } ) . filter ( item => item ) ;
344
- }
334
+ const compositePartitionKey = getTableParameter ( table , 'compositePartitionKey' ) || [ ] ;
335
+ const compositeClusteringKey = getTableParameter ( table , 'compositeClusteringKey' ) || [ ] ;
345
336
346
337
const entityData = [ {
338
+ compositePartitionKey,
339
+ compositeClusteringKey,
347
340
collectionName : addTableData . tableName ,
348
- compositePartitionKey : [ ...partitionKeys ] ,
349
- compositeClusteringKey : [ ...clusteringKeys ] ,
350
341
tableOptions : table . role . tableOptions || '' ,
351
342
comments : table . role . comments || '' ,
352
343
isActivated : table . role . isActivated ,
@@ -356,7 +347,8 @@ const getAddTable = (addTableData) => {
356
347
data . externalDefinitions ,
357
348
data . modelDefinitions ,
358
349
data . internalDefinitions ,
359
- table
350
+ table ,
351
+ { properties : addTableData . modifiedProperties || [ ] }
360
352
] ;
361
353
362
354
const script = getTableStatement ( {
0 commit comments