Fix create/drop indexes in every migration (#377)
* Add `__eq__` method for `Index`instances * tests: add Index test case * refactor: compare index instances before set hash and eq func to class * fix: sort fields when generating index hash * docs: update changlog * fix style issue * refactor: use CustomIndex instead of postgres special HashIndex * Check tortoise version before patch Index * Add comment * Add comment for why > work --------- Co-authored-by: dbf <somnium@riseup.net>
This commit is contained in:
@@ -3,6 +3,9 @@ import uuid
|
||||
from enum import IntEnum
|
||||
|
||||
from tortoise import Model, fields
|
||||
from tortoise.indexes import Index
|
||||
|
||||
from tests.indexes import CustomIndex
|
||||
|
||||
|
||||
class ProductType(IntEnum):
|
||||
@@ -33,6 +36,10 @@ class User(Model):
|
||||
|
||||
products: fields.ManyToManyRelation["Product"]
|
||||
|
||||
class Meta:
|
||||
# reverse indexes elements
|
||||
indexes = [CustomIndex(fields=("is_superuser",)), Index(fields=("username", "is_active"))]
|
||||
|
||||
|
||||
class Email(Model):
|
||||
email_id = fields.IntField(primary_key=True)
|
||||
|
||||
Reference in New Issue
Block a user