tortoise / aerich

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

Datamigrations #243

Open liminspace opened 2 years ago

liminspace commented 2 years ago

Is aerich going to support datamigrations? I mean when you can write your migration logic in python, not only SQL. Django and alembic support them, but aerich not :(

long2ice commented 2 years ago

That'a a good feature, I will consider it

liminspace commented 2 years ago

@long2ice I see there is a closed issue #148. But looks like it was closed mistakenly. The main idea of that issue was using python code in migrations files, but not executing aerich upgrade command from python code.

I thinks you should reopen that ticket or join it with current one.

And also look at the fork version of the author and his a proof of concept. It looks good to me.

I'd just add a new command aerich datamigration --name "another_change" that would be equivalent to cat template.py > migrations/app/"2_$(date +%Y%m%d%H%M%S)_another_change.py" (from PoC) that creates a new file of data migration using template:

from tortoise.backends.base.client import BaseDBAsyncClient

async def upgrade(conn: BaseDBAsyncClient):
    pass

async def downgrade(conn: BaseDBAsyncClient):
    pass
GamePad64 commented 2 years ago

Actually, we are trying to migrate from SQLAlchemy and Alembic and we use data migrations very extensively.