sql-migrate icon indicating copy to clipboard operation
sql-migrate copied to clipboard

Using .env file

Open mg98 opened this issue 5 years ago • 4 comments
trafficstars

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.

mg98 avatar Apr 23 '20 20:04 mg98

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

daddycarbone avatar May 31 '20 15:05 daddycarbone

@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.

mg98 avatar Jun 03 '20 07:06 mg98

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

rubenv avatar Jun 03 '20 07:06 rubenv

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.

mg98 avatar Jun 03 '20 09:06 mg98