From bd24050e3f6ecdbcab40ddad0bf137bbb85f424a Mon Sep 17 00:00:00 2001 From: Andrew Brookins Date: Wed, 20 Oct 2021 17:35:46 -0700 Subject: [PATCH] Avoid creating the index if it already exists --- redis_developer/model/migrations/migrator.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/redis_developer/model/migrations/migrator.py b/redis_developer/model/migrations/migrator.py index 38f16aa..aa03231 100644 --- a/redis_developer/model/migrations/migrator.py +++ b/redis_developer/model/migrations/migrator.py @@ -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)