Skip to content

Conversation

@simonprickett
Copy link
Contributor

Adds an error if the user attempts to create a search index on database > 0 as RediSearch does not support this.

Closes #190

@simonprickett simonprickett added the enhancement New feature or request label Apr 7, 2022
@simonprickett simonprickett self-assigned this Apr 7, 2022
@simonprickett
Copy link
Contributor Author

Example of the error you will see now:

from redis_om import HashModel, Field, Migrator

class Person(HashModel):
    name: str = Field(index=True)
    age: int = Field(index=True)


simon = Person(
    name = "Simon",
    age = 99
)

simon.save()

Migrator().run()

results = Person.find(Person.name == "Simon").all()

print(results)
$ export REDIS_OM_URL=redis://127.0.0.1:6379/2
(venv) python_om_db_test $ python testapp.py
Traceback (most recent call last):
  File "/Users/simonprickett/tmp/python_om_db_test/testapp.py", line 15, in <module>
    Migrator().run()
  File "/Users/simonprickett/tmp/python_om_db_test/venv/lib/python3.9/site-packages/redis_om/model/migrations/migrator.py", line 165, in run
    migration.run()
  File "/Users/simonprickett/tmp/python_om_db_test/venv/lib/python3.9/site-packages/redis_om/model/migrations/migrator.py", line 76, in run
    self.create()
  File "/Users/simonprickett/tmp/python_om_db_test/venv/lib/python3.9/site-packages/redis_om/model/migrations/migrator.py", line 82, in create
    create_index(self.redis, self.index_name, self.schema, self.hash)
  File "/Users/simonprickett/tmp/python_om_db_test/venv/lib/python3.9/site-packages/redis_om/model/migrations/migrator.py", line 45, in create_index
    raise MigrationError(
redis_om.model.migrations.migrator.MigrationError: Creating search indexes is only supported in database 0. You attempted to create an index in database 2

@codecov-commenter
Copy link

Codecov Report

Merging #196 (6193c23) into main (c4e96b1) will decrease coverage by 0.02%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##             main     #196      +/-   ##
==========================================
- Coverage   77.32%   77.30%   -0.03%     
==========================================
  Files          12       12              
  Lines        1160     1163       +3     
==========================================
+ Hits          897      899       +2     
- Misses        263      264       +1     
Flag Coverage Δ
unit 77.30% <66.66%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aredis_om/model/migrations/migrator.py 75.86% <66.66%> (-0.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4e96b1...6193c23. Read the comment docs.

@simonprickett simonprickett merged commit 0841d9f into main Apr 7, 2022
@simonprickett simonprickett deleted the warn-index-on-non-zero-database branch April 7, 2022 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update migrator to error if used with db > 0

3 participants