Avoid creating the index if it already exists

This commit is contained in:
Andrew Brookins 2021-10-20 17:35:46 -07:00
parent ab85e46c8b
commit bd24050e3f

View file

@ -44,6 +44,11 @@ def schema_hash_key(index_name):
def create_index(index_name, schema, current_hash): 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.execute_command(f"ft.create {index_name} {schema}")
redis.set(schema_hash_key(index_name), current_hash) redis.set(schema_hash_key(index_name), current_hash)