Skip to content

Commit

Permalink
fix(pg-v5): add an environment variable for which addon service to re…
Browse files Browse the repository at this point in the history
…solve
  • Loading branch information
coreypurcell authored Jul 12, 2021
1 parent 7f28cc4 commit 40d212d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/pg-v5/lib/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module.exports = heroku => {

debug(`fetching ${db} on ${app}`)

return resolve.appAttachment(heroku, app, db, { addon_service: 'heroku-postgresql', namespace: namespace })
let addonService = process.env.HEROKU_POSTGRESQL_ADDON_NAME || 'heroku-postgresql'
debug(`addon service: ${addonService}`)
return resolve.appAttachment(heroku, app, db, { addon_service: addonService, namespace: namespace })
.then(attached => ({ matches: [attached] }))
.catch(function (err) {
if (err.statusCode === 422 && err.body && err.body.id === 'multiple_matches' && err.matches) {
Expand Down
10 changes: 10 additions & 0 deletions packages/pg-v5/test/lib/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('fetcher', () => {

afterEach(() => {
api.done()
delete process.env.HEROKU_POSTGRESQL_ADDON_NAME
})

describe('addon', () => {
Expand All @@ -41,6 +42,15 @@ describe('fetcher', () => {
expect(addon.name).to.equal('postgres-1')
})
})

it('returns addon attached to app in another shogun', () => {
stub.withArgs(sinon.match.any, 'myapp', 'DATABASE_URL', { addon_service: 'heroku-postgresql-meta', namespace: null }).returns(Promise.resolve({ addon: { name: 'postgres-1' } }))
process.env.HEROKU_POSTGRESQL_ADDON_NAME = 'heroku-postgresql-meta'
return fetcher(new Heroku()).addon('myapp', 'DATABASE_URL')
.then(addon => {
expect(addon.name).to.equal('postgres-1')
})
})
})

describe('database', () => {
Expand Down

0 comments on commit 40d212d

Please sign in to comment.