| 
									
										
										
										
											2024-07-11 16:09:39 -04:00
										 |  |  | // Copyright 2024 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { assert } from 'chai'; | 
					
						
							| 
									
										
										
										
											2024-07-22 11:16:33 -07:00
										 |  |  | import type { WritableDB } from '../../sql/Interface'; | 
					
						
							|  |  |  | import { createDB, updateToVersion } from './helpers'; | 
					
						
							| 
									
										
										
										
											2024-07-11 16:09:39 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('SQL/updateToSchemaVersion1120', () => { | 
					
						
							| 
									
										
										
										
											2024-07-22 11:16:33 -07:00
										 |  |  |   let db: WritableDB; | 
					
						
							| 
									
										
										
										
											2024-07-11 16:09:39 -04:00
										 |  |  |   beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2024-07-22 11:16:33 -07:00
										 |  |  |     db = createDB(); | 
					
						
							| 
									
										
										
										
											2024-07-11 16:09:39 -04:00
										 |  |  |     updateToVersion(db, 1120); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   afterEach(() => { | 
					
						
							|  |  |  |     db.close(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('uses index for deleting edited messages', () => { | 
					
						
							|  |  |  |     const details = db | 
					
						
							|  |  |  |       .prepare( | 
					
						
							|  |  |  |         `EXPLAIN QUERY PLAN 
 | 
					
						
							|  |  |  |             DELETE FROM edited_messages WHERE messageId = 'messageId'; | 
					
						
							|  |  |  |         `
 | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |       .all() | 
					
						
							|  |  |  |       .map(step => step.detail) | 
					
						
							|  |  |  |       .join(', '); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert.strictEqual( | 
					
						
							|  |  |  |       details, | 
					
						
							|  |  |  |       'SEARCH edited_messages USING COVERING INDEX edited_messages_messageId (messageId=?)' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('uses index for deleting mentions', () => { | 
					
						
							|  |  |  |     const details = db | 
					
						
							|  |  |  |       .prepare( | 
					
						
							|  |  |  |         `EXPLAIN QUERY PLAN 
 | 
					
						
							|  |  |  |             DELETE FROM mentions WHERE messageId = 'messageId'; | 
					
						
							|  |  |  |           `
 | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |       .all() | 
					
						
							|  |  |  |       .map(step => step.detail) | 
					
						
							|  |  |  |       .join(', '); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert.strictEqual( | 
					
						
							|  |  |  |       details, | 
					
						
							|  |  |  |       'SEARCH mentions USING COVERING INDEX mentions_messageId (messageId=?)' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |