* Handles processing for a modified file. * Calculates diff and applies updates/deletes to the existing collection.
(db: Db, filepath: string)
| 239 | * Calculates diff and applies updates/deletes to the existing collection. |
| 240 | */ |
| 241 | async function _handleFileModified(db: Db, filepath: string): Promise<void> { |
| 242 | const collectionName = getCollectionNameFromJsonFile(filepath); |
| 243 | if (!collectionName) { |
| 244 | console.warn(`Could not determine collection name for modified file ${filepath}. Skipping.`); |
| 245 | return; |
| 246 | } |
| 247 | console.log(`\nProcessing Modified file ${filepath} for collection '${collectionName}'...`); |
| 248 | |
| 249 | const currentData = await readFileContent(filepath); |
| 250 | const oldFileContentString = await getOldFileContent(filepath); |
| 251 | const oldData = parseJsonArrayContent(oldFileContentString, `HEAD~1:${filepath}`); |
| 252 | |
| 253 | const { operations, skippedRecords } = calculateBulkOperations(oldData, currentData, filepath); |
| 254 | await executeBulkWrite(db, collectionName, operations); |
| 255 | |
| 256 | if (skippedRecords > 0) { |
| 257 | console.warn(`Skipped ${skippedRecords} records in ${filepath} due to missing 'index' field.`); |
| 258 | } |
| 259 | // No index update needed for modification |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Handles processing for a renamed file. |
no test coverage detected