rubenv / sql-migrate

SQL schema migration tool for Go.
MIT License
3.18k stars 270 forks source link

Using .env file #174

Open mg98 opened 4 years ago

mg98 commented 4 years ago

It is possible to reference environment variables in the dbconfig.yml. I am used to work with a .env file here. But sql-migrate is not reading from it.

daddycarbone commented 4 years ago

i hope authors would make documentation for this, how to use wit .env, i can't use .env on dbconfig.yml, and there is no documentation as well how touse envirotnment

mg98 commented 4 years ago

@daddycarbone I figured that when you strictly dockerize your application (which is always a very good thing to do!) you won't have a problem with this. My Dockerfile runs a script, that executes

export "$(< .env xargs)"
// and then you may want to run...
sql-migrate up

Since your application lives in docker, you wouldn't use the sql-migrate CLI locally anyway. You would run docker-compose exec server sql-migrate down or something like that.

While I'm satisfied with this, I still think it would be a great feature for others to have the dbconfig.yml file read from .env file.

rubenv commented 4 years ago

I would never recommend using the CLI in production. Use sql-migrate as a library and embed it into your application.

mg98 commented 4 years ago

I wasn‘t talking about production. Just using docker locally and use the CLI in the containers.

But I do the same in production. Why should I not? I need to get my migrations to apply on the production databse.