Is it Possible to Alias Config Variables on Heroku?

Maybe I'll just say something stupid, but why not just do this:

heroku config:set DATABASE_URL=CLEARDB_DATABASE_URL

In code: ENV[ENV['DATABASE_URL']]


It's not possible to alias an config var or refer to one from another. I asked a similar question and this is what they said:

I'm afraid that Config Variables can't refer to each other in this way, as they are simple a collection of Names and Values, with no interpolation or calculation available to the values.

You might like try a profile file...


I've had a similar issue - where I'm trying to use an app in a pipeline connected to 2 different heroku DB's - in order to keep all he environments consistent in code, I did the following:

Heroku Configs:

DATABASE_URL=XXXXXXXX  - this was the first DB that heroku attached
HEROKU_POSTGRESQL_JADE_URL=XXXX - this was the second DB that heroku attached (the key name changes in each environment)
SECOND_DB_KEY_NAME=HEROKU_POSTGRESQL_JADE_URL

(ie. after each environment was set up - I added a reference to the new key)

This second DB key name, does not change if the DB credentials refresh.

In code, I then did the following at start up:

const databaseUrlKey = process.env.SECOND_DB_KEY_NAME
process.env['SECOND_DATABASE_URL'] = process.env[databaseUrlKey]

Tags:

Heroku