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:
@@ -2,6 +2,9 @@ import datetime
|
||||
from enum import IntEnum
|
||||
|
||||
from tortoise import Model, fields
|
||||
from tortoise.indexes import Index
|
||||
|
||||
from tests.indexes import CustomIndex
|
||||
|
||||
|
||||
class ProductType(IntEnum):
|
||||
@@ -31,6 +34,9 @@ class User(Model):
|
||||
intro = fields.TextField(default="")
|
||||
longitude = fields.DecimalField(max_digits=12, decimal_places=9)
|
||||
|
||||
class Meta:
|
||||
indexes = [Index(fields=("username", "is_active")), CustomIndex(fields=("is_superuser",))]
|
||||
|
||||
|
||||
class Email(Model):
|
||||
email = fields.CharField(max_length=200)
|
||||
|
||||
Reference in New Issue
Block a user