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 Sep 12, 2024
1 parent 6e4f307 commit 0b48234
Show file tree
Hide file tree
Showing 3 changed files with 80 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(`
Displays stats on replication slots on your database. The default value is "off".
`)

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 'Data replication slot details will be logged.'
}

return 'Data replication slot details will no longer be logged.'
}
}
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,43 @@
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('turns on explain-data-connector-details option', 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}.
Data replication slot details will be logged.
`))
})

it('turns off explain-data-connector-details option', async function () {
nock('https://api.data.heroku.com')
.get(`/postgres/v0/databases/${addon.id}/config`).reply(200, {explain_data_connector_details: {value: ''}})
await runCommand(Cmd, ['--app', 'myapp', 'test-database'])
expect(stdout.output).to.equal(heredoc(`
explain-data-connector-details is set to for ${addon.name}.
Data replication slot details will no longer be logged.
`))
})
})

0 comments on commit 0b48234

Please sign in to comment.