tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
830 stars 95 forks source link

Does not work when using the specified index #203

Closed neo-f closed 2 years ago

neo-f commented 2 years ago

version: 0.5.8

while using the tortoise.indexes.Index based index class,migration doesn't work at all ex:

from tortoise.contrib.postgres.indexes import GinIndex

class Model(...):
    class Meta:
        indexes = [GinIndex(fields={"scopes"})]

when aerich init-db

TypeError: Object of type GinIndex is not JSON serializable
neo-f commented 2 years ago

additional, tortoise-orm generate schema feature does works

fullonic commented 2 years ago

Hey @captain-neo ! I'm having the same issue. Have you found a solution? Thanks

fullonic commented 2 years ago

@long2ice To put some more context, the issue happens when aerich saves the app information to aerich table JSONField. Is because that it works when the schema is generated by Tortoise but not when using aerich. If we commented out the aerich.__init__ line 130 it solves the issue related to JSON serialization and the SQL migration file is generated.

fullonic commented 2 years ago

Thanks, @long2ice for https://github.com/tortoise/aerich/commit/f15cbaf9e0269fca88741fae135bc7952fafd444 When can we have a release with these changes? Thanks again :+1:

long2ice commented 2 years ago

Just try it

neo-f commented 2 years ago

我都忘了提过这个issue了,哈哈,辛苦。

fullonic commented 2 years ago

@long2ice it works well. I tested the upgrade and downgrade commands and both went well. Nice work. Thanks!

long2ice commented 2 years ago

OK, I will release it in proper time