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

Fix create/drop indexes in every migration #377

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from

Conversation

waketzheng
Copy link
Contributor

Base on #311

Will close #258

@waketzheng waketzheng requested a review from henadzit December 6, 2024 11:11
aerich/migrate.py Outdated Show resolved Hide resolved
@waketzheng waketzheng force-pushed the fix/create-drop-indexes-in-every-migration branch from c168d24 to 87207f7 Compare December 7, 2024 02:18
@waketzheng
Copy link
Contributor Author

@henadzit Cloud you review it and #376 again?

ret.append(index)
return ret
def _eq(self, other) -> bool:
return type(self) is type(other) and hash(self) == hash(other)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an incorrect implementation of __eq__. Hashes happen to have collisions.

return type(self) is type(other) and hash(self) == hash(other)

setattr(index_cls, "__hash__", _hash)
setattr(index_cls, "__eq__", _eq)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are setting the lower boundary on the tortoise version in #388. Why not just implement __eq__ and __hash__ in Tortoise and set the corresponding version boundary. You won't have to have this hacky code then.

tests/models.py Outdated
class Meta:
indexes = [Index(fields=("is_active", "username"))]
if "postgres" in os.getenv("TEST_DB", "") and len(indexes) == 1:
indexes.append(HashIndex(fields=("intro",)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it required for postgres? Looks like a hack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New migration file on migrate for Indexes defined on a Model.
3 participants