jackc / tern

The SQL Fan's Migrator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add migrations path to config

seregayoga opened this issue · comments

My use case: I always run tern <command> --migrations ./migrations ... so the config is in the root of the project and migrations are in ./migrations.
So I would like to omit --migrations ./migrations when calling commands. What if we can have it in the config?

I've found that inconvenient as well.

In the v2-dev branch I've 4bdf795 added TERN_CONFIG and TERN_MIGRATIONS environment variables to eliminate the need to specify the config path or migrations path. Combine that with https://direnv.net/ and you shouldn't have to specify paths again.

As far as also putting it in the config, it's possible. But one annoying issue is how to handle relative paths. Is it relative to the config file or the working directory tern is run from?

But one annoying issue is how to handle relative paths. Is it relative to the config file or the working directory tern is run from?

Is it allowed to have relative path for config in TERN_CONFIG? I would say relative to the working directory as how I typically run migrations in the terminal open in the root of the project. But it would be nice to hear other opinions.

Is it allowed to have relative path for config in TERN_CONFIG?

Yes. That's exactly what I do. My .envrc has this in it:

export TERN_CONFIG=postgresql/tern.conf
export TERN_MIGRATIONS=postgresql/migrations

Given that tern must be run in the same directory as the config file (when not using --config) I would think that the relative paths would resolve to being relative to the config.

The direnv approach is nice for my local setup, but I won't be able to convince my team to install yet another dev tool. Currently, to make migrations friendly to the team, I am mapping tern in our make file make tern ARG="new init".

Would this work:

[migrations]
# path to migrations (default: current directory)
# path = 
# resolve path based on config or command (default: config)
# path_resolver = config 

Concider documenting it