Skip to content

Commit

Permalink
feat(cli) created pg setting auto explain format (#2991)
Browse files Browse the repository at this point in the history
* created pg setting auto explain format

* Update packages/cli/src/commands/pg/settings/auto-explain/log-format.ts

Co-authored-by: Santiago Bosio <santiago.bosio@gmail.com>

* removed un-needed topic

---------

Co-authored-by: Santiago Bosio <santiago.bosio@gmail.com>
  • Loading branch information
brahyt-sf and sbosio committed Sep 20, 2024
1 parent 6e4f307 commit ce086ef
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/cli/src/commands/pg/settings/auto-explain/log-format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Args} from '@oclif/core'
import {PGSettingsCommand} from '../../../../lib/pg/setter'
import {Setting, SettingKey} from '../../../../lib/pg/types'
import heredoc from 'tsheredoc'

export default class LogFormat extends PGSettingsCommand {
static description = heredoc(`
selects the EXPLAIN output format to be used
The allowed values are text, xml, json, and yaml. The default is text.
`)

static args = {
database: Args.string(),
value: Args.string({options: ['text', 'json', 'yaml', 'xml']}),
}

protected settingKey: SettingKey = 'auto_explain.log_format'

protected explain(setting: Setting<string>) {
return `Auto explain log output will log in ${setting.value} format.`
}

protected convertValue(val: string): string {
return val
}
}
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 @@ -222,6 +222,7 @@ export type SettingKey =
| 'auto_explain.log_buffers'
| 'auto_explain.log_verbose'
| 'auto_explain.log_nested_statements'
| 'auto_explain.log_format'
export type Setting<T> = {
value: T
values: Record<string, string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

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-format'
import * as fixtures from '../../../../../fixtures/addons/fixtures'

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

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

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

it('updates settings for auto_explain.log_format with value', async function () {
const pg = nock('https://api.data.heroku.com')
.patch(`/postgres/v0/databases/${addon.id}/config`).reply(200, {'auto_explain.log_format': {value: 'json'}})

await runCommand(Cmd, ['--app', 'myapp', 'test-database', 'json'])

api.done()
pg.done()

expect(stdout.output).to.equal(heredoc(`
auto-explain.log-format has been set to json for ${addon.name}.
Auto explain log output will log in json format.
`))
})
})

0 comments on commit ce086ef

Please sign in to comment.