-
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.
Convert log min duration statement to oclif
- Loading branch information
1 parent
9506a9c
commit d00e226
Showing
6 changed files
with
113 additions
and
29 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/cli/src/commands/pg/settings/log-min-duration-statement.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,34 @@ | ||
import {Args} from '@oclif/core' | ||
import heredoc from 'tsheredoc' | ||
import {PGSettingsCommand, type Setting, type SettingKey} from '../../../lib/pg/setter' | ||
|
||
export default class LogMinDurationStatement extends PGSettingsCommand { | ||
static description = heredoc(` | ||
The duration of each completed statement will be logged if the statement completes after the time specified by VALUE. | ||
VALUE needs to specified as a whole number, in milliseconds. | ||
Setting log_min_duration_statement to zero prints all statement durations and -1 will disable logging statement durations. | ||
`) | ||
|
||
static args = { | ||
database: Args.string(), | ||
value: Args.integer(), | ||
} | ||
|
||
protected settingKey:SettingKey = 'log_min_duration_statement' | ||
|
||
protected convertValue(val: number): number { | ||
return val | ||
} | ||
|
||
protected explain(setting: Setting) { | ||
if (setting.value === -1) { | ||
return 'The duration of each completed statement will not be logged.' | ||
} | ||
|
||
if (setting.value === 0) { | ||
return 'The duration of each completed statement will be logged.' | ||
} | ||
|
||
return `The duration of each completed statement will be logged if the statement ran for at least ${setting.value} milliseconds.` | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
packages/cli/test/unit/commands/pg/settings/log-min-duration-statement.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,53 @@ | ||
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/log-min-duration-statement' | ||
import * as fixtures from '../../../../fixtures/addons/fixtures' | ||
|
||
describe('pg:settings:log-min-duration-statement', () => { | ||
const addon = fixtures.addons['dwh-db'] | ||
|
||
beforeEach(() => { | ||
nock('https://api.heroku.com') | ||
.post('/actions/addons/resolve', { | ||
app: 'myapp', | ||
addon: 'test-database', | ||
}).reply(200, [addon]) | ||
}) | ||
|
||
afterEach(() => { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('shows settings for auto_explain with value', async () => { | ||
nock('https://api.data.heroku.com') | ||
.get(`/postgres/v0/databases/${addon.id}/config`).reply(200, {log_min_duration_statement: {value: 'test_value'}}) | ||
await runCommand(Cmd, ['--app', 'myapp', 'test-database']) | ||
expect(stdout.output).to.equal(heredoc(` | ||
log-min-duration-statement is set to test_value for ${addon.name}. | ||
The duration of each completed statement will be logged if the statement ran for at least test_value milliseconds. | ||
`)) | ||
}) | ||
|
||
it('shows settings for auto_explain with no value', async () => { | ||
nock('https://api.data.heroku.com') | ||
.get(`/postgres/v0/databases/${addon.id}/config`).reply(200, {log_min_duration_statement: {value: -1}}) | ||
await runCommand(Cmd, ['--app', 'myapp', 'test-database']) | ||
expect(stdout.output).to.equal(heredoc(` | ||
log-min-duration-statement is set to -1 for ${addon.name}. | ||
The duration of each completed statement will not be logged. | ||
`)) | ||
}) | ||
|
||
it('shows settings for auto_explain with no value', async () => { | ||
nock('https://api.data.heroku.com') | ||
.get(`/postgres/v0/databases/${addon.id}/config`).reply(200, {log_min_duration_statement: {value: 0}}) | ||
await runCommand(Cmd, ['--app', 'myapp', 'test-database']) | ||
expect(stdout.output).to.equal(heredoc(` | ||
log-min-duration-statement is set to 0 for ${addon.name}. | ||
The duration of each completed statement will be logged. | ||
`)) | ||
}) | ||
}) |
28 changes: 0 additions & 28 deletions
28
packages/pg-v5/commands/settings/log_min_duration_statement.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