Skip to content

Commit

Permalink
migrate(W-14179873): pg-v5: Upgrade pg:settings:auto-explain:log-verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Apr 5, 2024
1 parent f455e4f commit 9593543
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 48 deletions.
35 changes: 35 additions & 0 deletions packages/cli/src/commands/pg/settings/auto-explain/log-verbose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {flags} from '@heroku-cli/command'
import {Args} from '@oclif/core'
import heredoc from 'tsheredoc'
import {booleanConverter, PGSettingsCommand, type Setting, type SettingKey} from '../../../../lib/pg/setter'

export default class AutoExplainLogVerbose extends PGSettingsCommand {
static topic = 'pg'
static description = heredoc(
`Include verbose details in execution plans.
This is equivalent to calling EXPLAIN VERBOSE.`)

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

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

protected settingKey: SettingKey = 'auto_explain.log_verbose'

protected explain(setting: Setting) {
if (setting.value) {
return 'Verbose execution plan logging has been enabled for auto_explain.'
}

return 'Verbose execution plan logging has been disabled for auto_explain.'
}

protected convertValue(val: boolean): boolean {
return booleanConverter(val)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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/auto-explain/log-verbose'
import * as fixtures from '../../../../../fixtures/addons/fixtures'

describe('pg:settings:auto-explain:log-verbose', () => {
let api: nock.Scope
let pg: nock.Scope
const addon = fixtures.addons['dwh-db']

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

pg = nock('https://api.data.heroku.com')
})

afterEach(() => {
api.done()
pg.done()
})

it('shows settings for auto_explain_log_verbose with value', async () => {
pg.get(`/postgres/v0/databases/${addon.id}/config`).reply(200, {'auto_explain.log_verbose': {value: 'test_value'}})
await runCommand(Cmd, ['--app', 'myapp', 'test-database'])
expect(stdout.output).to.equal(heredoc(`
auto-explain.log-verbose is set to test_value for ${addon.name}.
Verbose execution plan logging has been enabled for auto_explain.
`))
})

it('shows settings for auto_explain_log_verbose with no value', async () => {
pg.get(`/postgres/v0/databases/${addon.id}/config`).reply(200, {'auto_explain.log_verbose': {value: ''}})
await runCommand(Cmd, ['--app', 'myapp', 'test-database'])
expect(stdout.output).to.equal(heredoc(`
auto-explain.log-verbose is set to for ${addon.name}.
Verbose execution plan logging has been disabled for auto_explain.
`))
})
})
23 changes: 0 additions & 23 deletions packages/pg-v5/commands/settings/auto_explain_log_verbose.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/pg-v5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ exports.commands = flatten([
require('./commands/settings/auto_explain_log_analyze'),
require('./commands/settings/auto_explain_log_nested_statements'),
require('./commands/settings/auto_explain_log_triggers'),
require('./commands/settings/auto_explain_log_verbose'),
require('./commands/settings/log_lock_waits'),
require('./commands/settings/log_min_duration_statement'),
require('./commands/settings/log_statement'),
Expand Down
24 changes: 0 additions & 24 deletions packages/pg-v5/test/unit/commands/settings/settings.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,30 +204,6 @@ describe('pg:settings', () => {
.then(() => expect(cli.stdout).to.equal('auto-explain.log-triggers is set to for postgres-1.\nTrigger execution statistics have been disabled for auto_explain.\n'))
})

it('shows settings for auto_explain_log_verbose with value', () => {
setupSettingsMockData('auto_explain.log_verbose')
cmd = proxyquire('../../../../commands/settings/auto_explain_log_verbose', {
settings: proxyquire.noCallThru().load('../../../../lib/setter', {
'./fetcher': fetcher,
}),
})
pg.get('/postgres/v0/databases/1/config').reply(200, settingsResult)
return cmd.run({args: {database: 'test-database', value: ''}, flags: {}})
.then(() => expect(cli.stdout).to.equal('auto-explain.log-verbose is set to test_value for postgres-1.\nVerbose execution plan logging has been enabled for auto_explain.\n'))
})

it('shows settings for auto_explain_log_verbose with no value', () => {
setupSettingsMockData('auto_explain.log_verbose', '')
cmd = proxyquire('../../../../commands/settings/auto_explain_log_verbose', {
settings: proxyquire.noCallThru().load('../../../../lib/setter', {
'./fetcher': fetcher,
}),
})
pg.get('/postgres/v0/databases/1/config').reply(200, settingsResult)
return cmd.run({args: {database: 'test-database', value: ''}, flags: {}})
.then(() => expect(cli.stdout).to.equal('auto-explain.log-verbose is set to for postgres-1.\nVerbose execution plan logging has been disabled for auto_explain.\n'))
})

it('shows settings for log_lock_waits with value', () => {
setupSettingsMockData('log_lock_waits')
cmd = proxyquire('../../../../commands/settings/log_lock_waits', {
Expand Down

0 comments on commit 9593543

Please sign in to comment.