Skip to content

Commit

Permalink
tests: add Index test case
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng committed Dec 6, 2024
1 parent ff22def commit 5de31d7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import IntEnum

from tortoise import Model, fields
from tortoise.indexes import Index


class ProductType(IntEnum):
Expand Down Expand Up @@ -33,6 +34,9 @@ class User(Model):

products: fields.ManyToManyRelation["Product"]

class Meta:
indexes = [Index(fields=("username",))]


class Email(Model):
email_id = fields.IntField(primary_key=True)
Expand Down
4 changes: 4 additions & 0 deletions tests/old_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from enum import IntEnum

from tortoise import Model, fields
from tortoise.indexes import Index


class ProductType(IntEnum):
Expand Down Expand Up @@ -31,6 +32,9 @@ class User(Model):
intro = fields.TextField(default="")
longitude = fields.DecimalField(max_digits=12, decimal_places=9)

class Meta:
indexes = [Index(fields=("username",))]


class Email(Model):
email = fields.CharField(max_length=200)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import tortoise
from pytest_mock import MockerFixture
from tortoise.indexes import Index

from aerich.ddl.mysql import MysqlDDL
from aerich.ddl.postgres import PostgresDDL
Expand Down Expand Up @@ -565,7 +566,7 @@
"description": None,
"docstring": None,
"unique_together": [],
"indexes": [],
"indexes": [Index(fields=("username",))],
"pk_field": {
"name": "id",
"field_type": "IntField",
Expand Down

0 comments on commit 5de31d7

Please sign in to comment.