diff --git a/packages/cli/src/commands/pg/settings/auto-explain/log-format.ts b/packages/cli/src/commands/pg/settings/auto-explain/log-format.ts new file mode 100644 index 0000000000..4c9981a9a2 --- /dev/null +++ b/packages/cli/src/commands/pg/settings/auto-explain/log-format.ts @@ -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) { + return `Auto explain log output will log in ${setting.value} format.` + } + + protected convertValue(val: string): string { + return val + } +} diff --git a/packages/cli/src/lib/pg/types.ts b/packages/cli/src/lib/pg/types.ts index 3c356f311d..3cf10d8094 100644 --- a/packages/cli/src/lib/pg/types.ts +++ b/packages/cli/src/lib/pg/types.ts @@ -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 = { value: T values: Record diff --git a/packages/cli/test/unit/commands/pg/settings/auto-explain/log-format.unit.test.ts b/packages/cli/test/unit/commands/pg/settings/auto-explain/log-format.unit.test.ts new file mode 100644 index 0000000000..37689ec5fe --- /dev/null +++ b/packages/cli/test/unit/commands/pg/settings/auto-explain/log-format.unit.test.ts @@ -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. + `)) + }) +})