Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli) created pg setting auto explain format #2991

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 topic = 'pg'
sbosio marked this conversation as resolved.
Show resolved Hide resolved
static description = heredoc(`
Selects the EXPLAIN output format to be used.
brahyt-sf marked this conversation as resolved.
Show resolved Hide resolved
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.
`))
})
})
Loading