jackc / tern

The SQL Fan's Migrator
MIT License
850 stars 66 forks source link

Add migrations path to config #64

Open seregayoga opened 1 year ago

seregayoga commented 1 year ago

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?

jackc commented 1 year ago

I've found that inconvenient as well.

In the v2-dev branch I've https://github.com/jackc/tern/commit/4bdf795348f76a9a8905f0aab8fb66fb2abc5380 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?

seregayoga commented 1 year ago

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.

jackc commented 1 year ago

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
jrschumacher commented 1 month ago

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 
iamwavecut commented 1 month ago

Concider documenting it