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

Best way to integrate aerich with an app that specifies the db_url dynamically #218

Closed chobeat closed 1 year ago

chobeat commented 2 years ago

Greetings.

We are trying to integrate aerich in an app that can specify the db_url through a settings_file from CLI to override the default one.

In this case, aerich would take the default settings file (I have a function at import time that returns the tortoise info including the db_url like this:


    return {
        "connections": {"default": get_db_url()},
       ...
        },
    }```

The problem is that there's no way to let the user either try to:
* override the setting we need through aerich CLI (I tried doing a weird trick because both tools use `click`, but I cannot pass the arguments properly so I gave up)
* specify the connection through the CLI and implement something like this on my side `my_app get-db-url --settings-file "my_file.toml"`. With this I could retrieve the db_url and handle everything at CLI level, providing some example in the docs that is better than nothing.

I don't know if I'm trying this from the wrong perspective, but it's really not clear how to approach this.