aerich icon indicating copy to clipboard operation
aerich copied to clipboard

Guide: Integrate to zalando postgres operator and FastAPI in Kubernetes cluster

Open caniko opened this issue 2 years ago • 5 comments

I have a zalando postgres-operator based database cluster on my k8 cluster. I have a separate FastAPI + tortoise ORM app. Tortoise uses the postgres db generated by the operator.

How do I integrate aerich to this workflow?

I was thinking of just having a startup script that runs and applies migrations at the during pod/container startup:

aerich init -t <some path>
aerich init-db
aerich migrate
aerich upgrade

<run WSGI or ASGI server command>

Any improvements or better ideas alltogether?

caniko avatar Aug 10 '22 08:08 caniko

What about this https://github.com/tortoise/aerich#use-aerich-in-application?

long2ice avatar Aug 10 '22 08:08 long2ice

What about this https://github.com/tortoise/aerich#use-aerich-in-application?

Should I keep this as test? Or just blank -> update?

await command.migrate("test")

caniko avatar Aug 10 '22 09:08 caniko

What about this https://github.com/tortoise/aerich#use-aerich-in-application?

Should I keep this as test? Or just blank -> update?

await command.migrate("test")

@caniko

Migrate.migrate just reads models to generate a new migration file.

You could use await command.upgrade() instead, in order to apply existing migrations. This way your database will be in the expected state after a new migration is submitted.

isaquealves avatar Aug 10 '22 14:08 isaquealves

Can you guys activate discussions? This issue should probably become a thread. Closing it makes no sense.

caniko avatar Aug 10 '22 15:08 caniko

You can migrate use aerich migrate command local, and use Command to do auto upgrade when application startup, just call the init and upgrade method

long2ice avatar Aug 11 '22 00:08 long2ice