Skip to content

Commit

Permalink
add explain postgres data connectors setting
Browse files Browse the repository at this point in the history
  • Loading branch information
brahyt-sf committed Aug 23, 2024
1 parent d46786a commit 7fc396a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {flags} from '@heroku-cli/command'
import {Args} from '@oclif/core'
import heredoc from 'tsheredoc'
import {type BooleanAsString, booleanConverter, PGSettingsCommand} from '../../../lib/pg/setter'
import type {Setting, SettingKey} from '../../../lib/pg/types'

export default class ExplainDataConnectorDetails extends PGSettingsCommand {
static topic = 'pg'
static description = heredoc(`
UNICORN, do things
`)

static flags = {
app: flags.app({required: true}),
remote: flags.remote(),
}

static args = {
database: Args.string(),
value: Args.string(),
}

protected settingKey:SettingKey = 'explain_data_connector_details'

protected convertValue(val: BooleanAsString): boolean {
return booleanConverter(val)
}

protected explain(setting: Setting<boolean>): string {
if (setting?.value) {
return 'SETTING ON DOES THINGS'
}

return 'SETTING OFF DOES THINGS'
}
}
1 change: 1 addition & 0 deletions packages/cli/src/lib/pg/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export type SettingKey =
| 'pgbouncer_max_client_conn'
| 'pg_bouncer_max_db_conns'
| 'pg_bouncer_default_pool_size'
| 'explain_data_connector_details'
| 'auto_explain'
| 'auto_explain.log_min_duration'
| 'auto_explain.log_analyze'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {expect} from '@oclif/test'
import * as nock from 'nock'
import {stdout} from 'stdout-stderr'
import heredoc from 'tsheredoc'
import runCommand from '../../../../helpers/runCommand'
import Cmd from '../../../../../src/commands/pg/settings/explain-data-connector-details'
import * as fixtures from '../../../../fixtures/addons/fixtures'

describe('pg:explain-data-connector-details', function () {
const addon = fixtures.addons['dwh-db']

beforeEach(function () {
nock('https://api.heroku.com')
.post('/actions/addons/resolve', {
app: 'myapp',
addon: 'test-database',
}).reply(200, [addon])
})

afterEach(function () {
nock.cleanAll()
})

it('shows settings for auto_explain with value', async function () {
nock('https://api.data.heroku.com')
.get(`/postgres/v0/databases/${addon.id}/config`).reply(200, {explain_data_connector_details: {value: 'on'}})
await runCommand(Cmd, ['--app', 'myapp', 'test-database'])
expect(stdout.output).to.equal(heredoc(`
explain-data-connector-details is set to on for ${addon.name}.
SETTING ON DOES THINGS
`))
})
})

0 comments on commit 7fc396a

Please sign in to comment.