-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move 'pg:settings:auto-explain:log-triggers' to CLI
- Loading branch information
Showing
5 changed files
with
85 additions
and
48 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/cli/src/commands/pg/settings/auto-explain/log-triggers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {Args} from '@oclif/core' | ||
import heredoc from 'tsheredoc' | ||
import {PGSettingsCommand, booleanConverter, BooleanAsString} from '../../../../lib/pg/setter' | ||
import {SettingKey, Setting} from '../../../../lib/pg/types' | ||
|
||
export default class LogTriggers extends PGSettingsCommand { | ||
static topic = 'pg' | ||
static description = heredoc(` | ||
Includes trigger execution statistics in execution plan logs. | ||
This parameter can only be used in conjunction with pg:settings:auto-explain:log-analyze turned on. | ||
`) | ||
|
||
static args = { | ||
database: Args.string(), | ||
value: Args.string(), | ||
} | ||
|
||
protected settingKey = 'auto_explain.log_triggers' as SettingKey | ||
|
||
protected convertValue(val: BooleanAsString): boolean { | ||
return booleanConverter(val) | ||
} | ||
|
||
protected explain(setting: Setting<boolean>) { | ||
if (setting.value) { | ||
return 'Trigger execution statistics have been enabled for auto-explain.' | ||
} | ||
|
||
return 'Trigger execution statistics have been disabled for auto-explain.' | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/cli/test/unit/commands/pg/settings/auto-explain/log-triggers.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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-triggers' | ||
import * as fixtures from '../../../../../fixtures/addons/fixtures' | ||
|
||
describe('pg:settings:auto-explain:log-triggers', () => { | ||
const addon = fixtures.addons['dwh-db'] | ||
let api: nock.Scope | ||
|
||
beforeEach(() => { | ||
api = nock('https://api.heroku.com') | ||
.post('/actions/addons/resolve', { | ||
app: 'myapp', | ||
addon: 'test-database', | ||
}).reply(200, [addon]) | ||
}) | ||
|
||
afterEach(() => { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('updates settings for auto_explain.log_triggers with value', async () => { | ||
const pg = nock('https://api.data.heroku.com') | ||
.patch(`/postgres/v0/databases/${addon.id}/config`).reply(200, {'auto_explain.log_triggers': {value: true}}) | ||
|
||
await runCommand(Cmd, ['--app', 'myapp', 'test-database', 'true']) | ||
|
||
api.done() | ||
pg.done() | ||
|
||
expect(stdout.output).to.equal(heredoc(` | ||
auto-explain.log-triggers has been set to true for ${addon.name}. | ||
Trigger execution statistics have been enabled for auto-explain. | ||
`)) | ||
}) | ||
|
||
it('shows settings for auto_explain.log_triggers with no value', async () => { | ||
const pg = nock('https://api.data.heroku.com') | ||
.get(`/postgres/v0/databases/${addon.id}/config`).reply(200, {'auto_explain.log_triggers': {value: false}}) | ||
|
||
await runCommand(Cmd, ['--app', 'myapp', 'test-database']) | ||
|
||
api.done() | ||
pg.done() | ||
|
||
expect(stdout.output).to.equal(heredoc(` | ||
auto-explain.log-triggers is set to false for ${addon.name}. | ||
Trigger execution statistics have been disabled for auto-explain. | ||
`)) | ||
}) | ||
}) |
23 changes: 0 additions & 23 deletions
23
packages/pg-v5/commands/settings/auto_explain_log_triggers.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters