Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __eq__ method for Indexinstances #2

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions aerich/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,17 @@ def _handle_indexes(cls, model: Type[Model], indexes: List[Union[Tuple[str], Ind
ret = []
for index in indexes:
if isinstance(index, Index):
index.__hash__ = lambda self: md5( # nosec: B303
self.index_name(cls.ddl.schema_generator, model).encode()
+ self.__class__.__name__.encode()
).hexdigest()
def add_hash_eq_methods_to_index(idx):
def _hash(self):
return hash(self.index_name(cls.ddl.schema_generator, model).encode() + self.__class__.__name__.encode())

def _eq(self, other):
return self.__hash__() == other.__hash__()

setattr(idx.__class__, '__hash__', _hash)
setattr(idx.__class__, '__eq__', _eq)
return idx
index = add_hash_eq_methods_to_index(index)
ret.append(index)
return ret

Expand Down