| 
									
										
										
										
											2022-12-27 14:44:28 +01:00
										 |  |  | -- case based on isDeleted is needed, otherwise 2 branches (1 deleted, 1 not) might get the same ID
 | 
					
						
							| 
									
										
										
										
											2022-12-27 14:52:32 +01:00
										 |  |  | UPDATE entity_changes SET entityId = COALESCE((
 | 
					
						
							| 
									
										
										
										
											2022-12-27 14:44:28 +01:00
										 |  |  |     SELECT
 | 
					
						
							|  |  |  |         CASE isDeleted
 | 
					
						
							|  |  |  |             WHEN 0 THEN parentNoteId || '_' || noteId
 | 
					
						
							|  |  |  |             WHEN 1 THEN branchId
 | 
					
						
							|  |  |  |         END
 | 
					
						
							|  |  |  |     FROM branches WHERE branchId = entityId
 | 
					
						
							| 
									
										
										
										
											2022-12-27 14:52:32 +01:00
										 |  |  | ), entityId)
 | 
					
						
							|  |  |  | WHERE entityName = 'branches' AND isErased = 0;
 | 
					
						
							| 
									
										
										
										
											2022-12-27 14:44:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | UPDATE branches SET branchId = parentNoteId || '_' || noteId WHERE isDeleted = 0;
 |