Avoid creating the index if it already exists
This commit is contained in:
		
							parent
							
								
									ab85e46c8b
								
							
						
					
					
						commit
						bd24050e3f
					
				
					 1 changed files with 5 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -44,6 +44,11 @@ def schema_hash_key(index_name):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
def create_index(index_name, schema, current_hash):
 | 
			
		||||
    try:
 | 
			
		||||
        redis.execute_command(f"ft.info {index_name}")
 | 
			
		||||
    except ResponseError:
 | 
			
		||||
        log.info("Index already exists, skipping. Index hash: %s", index_name)
 | 
			
		||||
        return
 | 
			
		||||
    redis.execute_command(f"ft.create {index_name} {schema}")
 | 
			
		||||
    redis.set(schema_hash_key(index_name), current_hash)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue