Adds error if user attempts to create an index in DB > 0.
This commit is contained in:
		
							parent
							
								
									c4e96b18ab
								
							
						
					
					
						commit
						f5b507369c
					
				
					 1 changed files with 6 additions and 0 deletions
				
			
		| 
						 | 
					@ -40,6 +40,12 @@ def schema_hash_key(index_name):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async def create_index(redis: Redis, index_name, schema, current_hash):
 | 
					async def create_index(redis: Redis, index_name, schema, current_hash):
 | 
				
			||||||
 | 
					    db_number = redis.connection_pool.connection_kwargs.get("db")
 | 
				
			||||||
 | 
					    if  db_number and db_number > 0:
 | 
				
			||||||
 | 
					        raise MigrationError(
 | 
				
			||||||
 | 
					            "Creating search indexes is only supported in database 0. "
 | 
				
			||||||
 | 
					            f"You attempted to create an index in database {db_number}"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        await redis.execute_command(f"ft.info {index_name}")
 | 
					        await redis.execute_command(f"ft.info {index_name}")
 | 
				
			||||||
    except ResponseError:
 | 
					    except ResponseError:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue