From f5b507369c814b3ef94cc69f54a6781d8b4c18bf Mon Sep 17 00:00:00 2001 From: Simon Prickett Date: Thu, 7 Apr 2022 10:02:50 +0100 Subject: [PATCH 1/2] Adds error if user attempts to create an index in DB > 0. --- aredis_om/model/migrations/migrator.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aredis_om/model/migrations/migrator.py b/aredis_om/model/migrations/migrator.py index 8ca6d63..b113cc8 100644 --- a/aredis_om/model/migrations/migrator.py +++ b/aredis_om/model/migrations/migrator.py @@ -40,6 +40,12 @@ def schema_hash_key(index_name): 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: await redis.execute_command(f"ft.info {index_name}") except ResponseError: From 6193c238d809d780b17bbdf489245b78ef478e1f Mon Sep 17 00:00:00 2001 From: Simon Prickett Date: Thu, 7 Apr 2022 10:22:32 +0100 Subject: [PATCH 2/2] Fixed linter issue. --- aredis_om/model/migrations/migrator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aredis_om/model/migrations/migrator.py b/aredis_om/model/migrations/migrator.py index b113cc8..1af7428 100644 --- a/aredis_om/model/migrations/migrator.py +++ b/aredis_om/model/migrations/migrator.py @@ -41,7 +41,7 @@ def schema_hash_key(index_name): 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: + 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}"