jackc / tern

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

Config file merging #77

Closed abs3ntdev closed 1 year ago

abs3ntdev commented 1 year ago

This PR enables config file merging. Which allows a user to have a base.tern.conf and a prod.tern.conf where prod.tern.conf can only have updated authentication information and not any duplicate info from base.tern.conf. The behavior is similar to passing command line arguments overwriting config file values, but being able to store that information in a config file is a lot more usable than remembering all the arguments needed to pass.

config files will overwrite in order they are passed

tern status -c tern.conf -c next.tern.conf -c other.tern.conf

tern.conf will be read then next.tern.conf will overwrite then other.tern.conf will overwrite

Example

base.tern.conf:

[database]
host = localhost
port = 5432
database = localdb
user = postgres
password = postgres
version_table = public.schema_version

sslmode=prefer

[data]
rw_user = writer
ro_user = reader

employees.tern.conf

[database]
user = bossman
password = 1234
database = employees

tern status -c base.tern.conf would produce

status:   up to date
version:  17 of 17
host:     localhost
database: localdb

tern status -c base.tern.conf -c employees.tern.conf would produce

status:   up to date
version:  17 of 17
host:     localhost
database: employees
jackc commented 1 year ago

LGTM