aerich icon indicating copy to clipboard operation
aerich copied to clipboard

Process distributed models

Open mahenzon opened this issue 3 years ago • 0 comments

If models are distributed, for example this way:

├── models
│   ├── __init__.py
│   ├── user.py
│   ├── order.py

then you have to specify each file with model separately in the config array. It would be better if you could specify just the models module (all imports are in the __init__.py). But if I specify only the models module it imports this way:

from models.user import User
from models.order import Order

and cannot process it properly, so creates a CREATE TABLE for each model when creating new migration again and again


also it needs to add a prepending new line in the old_models because it looks like this now:

from tortoise import fields
from tortoise.models import Model


class User(Model):
    id = fields.IntField(pk=True)
    name = fields.TextField()
from tortoise import Model, fields

MAX_VERSION_LENGTH = 255


class Aerich(Model):
    version = fields.CharField(max_length=MAX_VERSION_LENGTH)
    app = fields.CharField(max_length=20)

    class Meta:
        ordering = ["-id"]

And if you forget to add an empty new line in the module, then line from tortoise import Model, fields joins the previous and breaks syntax

mahenzon avatar Sep 12 '20 05:09 mahenzon