@@ -243,7 +243,8 @@ async function processCollectionItems(nuxt: Nuxt, collections: ResolvedCollectio
243
243
continue
244
244
}
245
245
const collectionHash = hash ( collection )
246
- collectionDump [ collection . name ] = [ ]
246
+ const collectionQueries = generateCollectionTableDefinition ( collection , { drop : true } )
247
+ . split ( '\n' )
247
248
248
249
if ( ! collection . source ) {
249
250
continue
@@ -298,30 +299,26 @@ async function processCollectionItems(nuxt: Nuxt, collections: ResolvedCollectio
298
299
}
299
300
// Sort by file name to ensure consistent order
300
301
list . sort ( ( a , b ) => String ( a [ 0 ] ) . localeCompare ( String ( b [ 0 ] ) ) )
301
- const insertQueriesList = list . flatMap ( ( [ , sql ] ) => sql ! )
302
302
303
- // Collection table definition
304
- const insertQueriesListWithDefinition = [ ... generateCollectionTableDefinition ( collection , { drop : true } ) . split ( '\n' ) , ... insertQueriesList ]
303
+ collectionQueries . push ( ... list . flatMap ( ( [ , sql ] ) => sql ! ) )
304
+ }
305
305
306
- collectionChecksum [ collection . name ] = hash ( insertQueriesListWithDefinition )
306
+ const version = collectionChecksum [ collection . name ] = hash ( collectionQueries )
307
307
308
+ collectionDump [ collection . name ] = [
308
309
// we have to start the series of queries
309
310
// by telling everyone that we are setting up the collection so no
310
311
// other request start doing the same work and fail
311
312
// so we create a new entry in the info table saying that it is not ready yet
312
- collectionDump [ collection . name ] ! . push (
313
- generateCollectionTableDefinition ( infoCollection , { drop : false } ) ,
314
- `DELETE FROM ${ infoCollection . tableName } WHERE id = 'checksum_${ collection . name } ';` ,
315
- ...generateCollectionInsert ( infoCollection , { id : `checksum_${ collection . name } ` , version : collectionChecksum [ collection . name ] , ready : false } ) ,
316
- )
313
+ generateCollectionTableDefinition ( infoCollection , { drop : false } ) ,
314
+ ...generateCollectionInsert ( infoCollection , { id : `checksum_${ collection . name } ` , version, ready : false } ) ,
317
315
318
- collectionDump [ collection . name ] ! . push ( ...insertQueriesListWithDefinition )
316
+ // Insert queries for the collection
317
+ ...collectionQueries ,
319
318
320
319
// and finally when we are finished, we update the info table to say that the init is done
321
- collectionDump [ collection . name ] ! . push (
322
- `UPDATE ${ infoCollection . tableName } SET ready = true WHERE id = 'checksum_${ collection . name } '` ,
323
- )
324
- }
320
+ `UPDATE ${ infoCollection . tableName } SET ready = true WHERE id = 'checksum_${ collection . name } '` ,
321
+ ]
325
322
}
326
323
327
324
const sqlDumpList = Object . values ( collectionDump ) . flatMap ( a => a )
0 commit comments