mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 07:01:31 +08:00 
			
		
		
		
	fix direct migration from 0.30 to 0.32, closes #557
This commit is contained in:
		
							parent
							
								
									b389ec5ea3
								
							
						
					
					
						commit
						19a154c2f4
					
				@ -62,26 +62,33 @@ async function cleanupSyncRowsForMissingEntities(entityName, entityKey) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function fillSyncRows(entityName, entityKey, condition = '') {
 | 
					async function fillSyncRows(entityName, entityKey, condition = '') {
 | 
				
			||||||
    await cleanupSyncRowsForMissingEntities(entityName, entityKey);
 | 
					    try {
 | 
				
			||||||
 | 
					        await cleanupSyncRowsForMissingEntities(entityName, entityKey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const entityIds = await sql.getColumn(`SELECT ${entityKey} FROM ${entityName}`
 | 
					        const entityIds = await sql.getColumn(`SELECT ${entityKey} FROM ${entityName}`
 | 
				
			||||||
        + (condition ? ` WHERE ${condition}` : ''));
 | 
					            + (condition ? ` WHERE ${condition}` : ''));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const entityId of entityIds) {
 | 
					        for (const entityId of entityIds) {
 | 
				
			||||||
        const existingRows = await sql.getValue("SELECT COUNT(id) FROM sync WHERE entityName = ? AND entityId = ?", [entityName, entityId]);
 | 
					            const existingRows = await sql.getValue("SELECT COUNT(id) FROM sync WHERE entityName = ? AND entityId = ?", [entityName, entityId]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // we don't want to replace existing entities (which would effectively cause full resync)
 | 
					            // we don't want to replace existing entities (which would effectively cause full resync)
 | 
				
			||||||
        if (existingRows === 0) {
 | 
					            if (existingRows === 0) {
 | 
				
			||||||
            log.info(`Creating missing sync record for ${entityName} ${entityId}`);
 | 
					                log.info(`Creating missing sync record for ${entityName} ${entityId}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await sql.insert("sync", {
 | 
					                await sql.insert("sync", {
 | 
				
			||||||
                entityName: entityName,
 | 
					                    entityName: entityName,
 | 
				
			||||||
                entityId: entityId,
 | 
					                    entityId: entityId,
 | 
				
			||||||
                sourceId: "SYNC_FILL",
 | 
					                    sourceId: "SYNC_FILL",
 | 
				
			||||||
                utcSyncDate: dateUtils.utcNowDateTime()
 | 
					                    utcSyncDate: dateUtils.utcNowDateTime()
 | 
				
			||||||
            });
 | 
					                });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    catch (e) {
 | 
				
			||||||
 | 
					        // this is to fix migration from 0.30 to 0.32, can be removed later
 | 
				
			||||||
 | 
					        // see https://github.com/zadam/trilium/issues/557
 | 
				
			||||||
 | 
					        log.error(`Filling sync rows failed for ${entityName} ${entityKey} with error "${e.message}", continuing`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function fillAllSyncRows() {
 | 
					async function fillAllSyncRows() {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user