@@ -243,7 +243,8 @@ async function processCollectionItems(nuxt: Nuxt, collections: ResolvedCollectio
243243 continue
244244 }
245245 const collectionHash = hash ( collection )
246- collectionDump [ collection . name ] = [ ]
246+ const collectionQueries = generateCollectionTableDefinition ( collection , { drop : true } )
247+ . split ( '\n' )
247248
248249 if ( ! collection . source ) {
249250 continue
@@ -298,30 +299,26 @@ async function processCollectionItems(nuxt: Nuxt, collections: ResolvedCollectio
298299 }
299300 // Sort by file name to ensure consistent order
300301 list . sort ( ( a , b ) => String ( a [ 0 ] ) . localeCompare ( String ( b [ 0 ] ) ) )
301- const insertQueriesList = list . flatMap ( ( [ , sql ] ) => sql ! )
302302
303- // Collection table definition
304- const insertQueriesListWithDefinition = [ ... generateCollectionTableDefinition ( collection , { drop : true } ) . split ( '\n' ) , ... insertQueriesList ]
303+ collectionQueries . push ( ... list . flatMap ( ( [ , sql ] ) => sql ! ) )
304+ }
305305
306- collectionChecksum [ collection . name ] = hash ( insertQueriesListWithDefinition )
306+ const version = collectionChecksum [ collection . name ] = hash ( collectionQueries )
307307
308+ collectionDump [ collection . name ] = [
308309 // we have to start the series of queries
309310 // by telling everyone that we are setting up the collection so no
310311 // other request start doing the same work and fail
311312 // 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 } ) ,
317315
318- collectionDump [ collection . name ] ! . push ( ...insertQueriesListWithDefinition )
316+ // Insert queries for the collection
317+ ...collectionQueries ,
319318
320319 // 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+ ]
325322 }
326323
327324 const sqlDumpList = Object . values ( collectionDump ) . flatMap ( a => a )
0 commit comments