File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -251,6 +251,24 @@ const queryDatabaseData = async (database) => {
251
251
user : 'postgres' ,
252
252
password : 'postgres' ,
253
253
} ) ;
254
+
255
+ // Deep sort function to handle arrays within data
256
+ const deepSort = ( obj ) => {
257
+ if ( Array . isArray ( obj ) ) {
258
+ return obj . map ( deepSort ) . sort ( autoCompare ) ;
259
+ }
260
+
261
+ if ( obj && typeof obj === 'object' ) {
262
+ const sorted = { } ;
263
+ Object . keys ( obj ) . sort ( ) . forEach ( key => {
264
+ sorted [ key ] = deepSort ( obj [ key ] ) ;
265
+ } ) ;
266
+ return sorted ;
267
+ }
268
+
269
+ return obj ;
270
+ } ;
271
+
254
272
const result = await Promise . all (
255
273
manifests [ 0 ] . tables . map ( async ( { table_schema, table_name } ) => {
256
274
const { rows } = await pool . query (
@@ -262,7 +280,7 @@ const queryDatabaseData = async (database) => {
262
280
const data = omitArray ( rows , 'value' ) ;
263
281
return [
264
282
table_name ,
265
- data . sort ( buildSortByKeys ( Object . keys ( data [ 0 ] ?? { } ) ) ) ,
283
+ data . map ( deepSort ) . sort ( buildSortByKeys ( Object . keys ( data [ 0 ] ?? { } ) ) ) ,
266
284
] ;
267
285
}
268
286
@@ -281,7 +299,7 @@ const queryDatabaseData = async (database) => {
281
299
'add_on_sku_id'
282
300
) ;
283
301
284
- return [ table_name , data . sort ( buildSortByKeys ( Object . keys ( data [ 0 ] ?? { } ) ) ) ] ;
302
+ return [ table_name , data . map ( deepSort ) . sort ( buildSortByKeys ( Object . keys ( data [ 0 ] ?? { } ) ) ) ] ;
285
303
} )
286
304
) ;
287
305
You can’t perform that action at this time.
0 commit comments