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

standard --fix #186

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions commands/bloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const cli = require('heroku-cli-util')
const pg = require('@heroku-cli/plugin-pg-v5')

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)

let query = `
const query = `
WITH constants AS (
SELECT current_setting('block_size')::numeric AS bs, 23 AS hdr, 4 AS ma
), bloat_info AS (
Expand Down Expand Up @@ -70,7 +70,7 @@ FROM
ORDER BY raw_waste DESC, bloat DESC
`

let output = yield pg.psql.exec(db, query)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -79,10 +79,10 @@ const cmd = {
description: 'show table and index bloat in your database ordered by most wasteful',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
run: cli.command({preauth: true}, co.wrap(run))
args: [{ name: 'database', optional: true }],
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'bloat'}, cmd)
Object.assign({ command: 'bloat' }, cmd)
]
10 changes: 5 additions & 5 deletions commands/blocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ WHERE NOT bl.granted
`

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
let output = yield pg.psql.exec(db, query)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -32,10 +32,10 @@ const cmd = {
description: 'display queries holding locks other queries are waiting to be released',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
run: cli.command({preauth: true}, co.wrap(run))
args: [{ name: 'database', optional: true }],
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'blocking'}, cmd)
Object.assign({ command: 'blocking' }, cmd)
]
12 changes: 6 additions & 6 deletions commands/cache_hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ FROM pg_statio_user_tables;
`

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
let output = yield pg.psql.exec(db, query)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -27,11 +27,11 @@ const cmd = {
description: 'show index and table hit rate',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
run: cli.command({preauth: true}, co.wrap(run))
args: [{ name: 'database', optional: true }],
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'cache-hit'}, cmd),
Object.assign({command: 'cache_hit', hidden: true}, cmd)
Object.assign({ command: 'cache-hit' }, cmd),
Object.assign({ command: 'cache_hit', hidden: true }, cmd)
]
24 changes: 12 additions & 12 deletions commands/calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ const pg = require('@heroku-cli/plugin-pg-v5')
const util = require('../lib/util')

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)

yield util.ensurePGStatStatement(db)

let truncatedQueryString = context.flags.truncate
const truncatedQueryString = context.flags.truncate
? 'CASE WHEN length(query) <= 40 THEN query ELSE substr(query, 0, 39) || \'…\' END'
: 'query'

let newTotalExecTimeField = yield util.newTotalExecTimeField(db)
let totalExecTimeField = ``
const newTotalExecTimeField = yield util.newTotalExecTimeField(db)
let totalExecTimeField = ''
if (newTotalExecTimeField) {
totalExecTimeField = "total_exec_time"
totalExecTimeField = 'total_exec_time'
} else {
totalExecTimeField = "total_time"
totalExecTimeField = 'total_time'
}

let query = `
const query = `
SELECT ${truncatedQueryString} AS qry,
interval '1 millisecond' * ${totalExecTimeField} AS exec_time,
to_char((${totalExecTimeField}/sum(${totalExecTimeField}) OVER()) * 100, 'FM90D0') || '%' AS prop_exec_time,
Expand All @@ -32,7 +32,7 @@ FROM pg_stat_statements WHERE userid = (SELECT usesysid FROM pg_user WHERE usena
ORDER BY calls DESC LIMIT 10
`

let output = yield pg.psql.exec(db, query)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -41,13 +41,13 @@ const cmd = {
description: 'show 10 queries that have longest execution time in aggregate',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
args: [{ name: 'database', optional: true }],
flags: [
{name: 'truncate', char: 't', description: 'truncate queries to 40 characters'}
{ name: 'truncate', char: 't', description: 'truncate queries to 40 characters' }
],
run: cli.command({preauth: true}, co.wrap(run))
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'calls'}, cmd)
Object.assign({ command: 'calls' }, cmd)
]
12 changes: 6 additions & 6 deletions commands/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const cli = require('heroku-cli-util')
const pg = require('@heroku-cli/plugin-pg-v5')

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)

let query = `
const query = `
SELECT * FROM pg_available_extensions WHERE name IN (SELECT unnest(string_to_array(current_setting('extwlist.extensions'), ',')))
`

let output = yield pg.psql.exec(db, query)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -20,10 +20,10 @@ const cmd = {
description: 'list available and installed extensions',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
run: cli.command({preauth: true}, co.wrap(run))
args: [{ name: 'database', optional: true }],
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'extensions'}, cmd)
Object.assign({ command: 'extensions' }, cmd)
]
14 changes: 7 additions & 7 deletions commands/fdwsql.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ ORDER BY c.relname;

function * run (context, heroku) {
const app = context.app
const {prefix, database} = context.args
const { prefix, database } = context.args

let db = yield pg.fetcher(heroku).database(app, database)
let addon = yield pg.fetcher(heroku).addon(app, database)
const db = yield pg.fetcher(heroku).database(app, database)
const addon = yield pg.fetcher(heroku).addon(app, database)
yield util.ensureNonStarterPlan(addon)
cli.log('CREATE EXTENSION IF NOT EXISTS postgres_fdw;')
cli.log(`DROP SERVER IF EXISTS ${prefix}_db;`)
Expand All @@ -58,12 +58,12 @@ const cmd = {
needsApp: true,
needsAuth: true,
args: [
{name: 'prefix'},
{name: 'database', optional: true}
{ name: 'prefix' },
{ name: 'database', optional: true }
],
run: cli.command({preauth: true}, co.wrap(run))
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'fdwsql'}, cmd)
Object.assign({ command: 'fdwsql' }, cmd)
]
14 changes: 7 additions & 7 deletions commands/index_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const cli = require('heroku-cli-util')
const pg = require('@heroku-cli/plugin-pg-v5')

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)

let query = `
const query = `
SELECT c.relname AS name,
pg_size_pretty(sum(c.relpages::bigint*8192)::bigint) AS size
FROM pg_class c
Expand All @@ -19,7 +19,7 @@ GROUP BY c.relname
ORDER BY sum(c.relpages) DESC;
`

let output = yield pg.psql.exec(db, query)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -28,11 +28,11 @@ const cmd = {
description: 'show the size of indexes, descending by size',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
run: cli.command({preauth: true}, co.wrap(run))
args: [{ name: 'database', optional: true }],
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'index-size'}, cmd),
Object.assign({command: 'index_size', hidden: true}, cmd)
Object.assign({ command: 'index-size' }, cmd),
Object.assign({ command: 'index_size', hidden: true }, cmd)
]
12 changes: 6 additions & 6 deletions commands/index_usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ SELECT relname,
`

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
let output = yield pg.psql.exec(db, query)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -28,11 +28,11 @@ const cmd = {
description: 'calculates your index hit rate (effective databases are at 99% and up)',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
run: cli.command({preauth: true}, co.wrap(run))
args: [{ name: 'database', optional: true }],
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'index-usage'}, cmd),
Object.assign({command: 'index_usage', hidden: true}, cmd)
Object.assign({ command: 'index-usage' }, cmd),
Object.assign({ command: 'index_usage', hidden: true }, cmd)
]
18 changes: 9 additions & 9 deletions commands/locks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ const cli = require('heroku-cli-util')
const pg = require('@heroku-cli/plugin-pg-v5')

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)

let truncatedQueryString = prefix => {
let column = `${prefix}query`
const truncatedQueryString = prefix => {
const column = `${prefix}query`
if (context.flags.truncate) {
return `CASE WHEN length(${column}) <= 40 THEN ${column} ELSE substr(${column}, 0, 39) || '…' END`
} else {
return column
}
}

let query = `
const query = `
SELECT
pg_stat_activity.pid,
pg_class.relname,
Expand All @@ -33,7 +33,7 @@ function * run (context, heroku) {
AND pg_stat_activity.pid <> pg_backend_pid() order by query_start;
`

let output = yield pg.psql.exec(db, query)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -42,11 +42,11 @@ const cmd = {
description: 'display queries with active locks',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
flags: [{name: 'truncate', char: 't', description: 'truncates queries to 40 charaters'}],
run: cli.command({preauth: true}, co.wrap(run))
args: [{ name: 'database', optional: true }],
flags: [{ name: 'truncate', char: 't', description: 'truncates queries to 40 charaters' }],
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'locks'}, cmd)
Object.assign({ command: 'locks' }, cmd)
]
14 changes: 7 additions & 7 deletions commands/long_running_queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const cli = require('heroku-cli-util')
const pg = require('@heroku-cli/plugin-pg-v5')

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)

let query = `
const query = `
SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
Expand All @@ -22,7 +22,7 @@ ORDER BY
now() - pg_stat_activity.query_start DESC;
`

let output = yield pg.psql.exec(db, query)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -31,11 +31,11 @@ const cmd = {
description: 'show all queries longer than five minutes by descending duration',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
run: cli.command({preauth: true}, co.wrap(run))
args: [{ name: 'database', optional: true }],
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'long-running-queries'}, cmd),
Object.assign({command: 'long_running_queries', hidden: true}, cmd)
Object.assign({ command: 'long-running-queries' }, cmd),
Object.assign({ command: 'long_running_queries', hidden: true }, cmd)
]
12 changes: 6 additions & 6 deletions commands/mandelbrot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const cli = require('heroku-cli-util')
const pg = require('@heroku-cli/plugin-pg-v5')

function * run (context, heroku) {
let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
const db = yield pg.fetcher(heroku).database(context.app, context.args.database)

let query = `
const query = `
WITH RECURSIVE Z(IX, IY, CX, CY, X, Y, I) AS (
SELECT IX, IY, X::float, Y::float, X::float, Y::float, 0
FROM (select -2.2 + 0.031 * i, i from generate_series(0,101) as i) as xgen(x,ix),
Expand All @@ -29,7 +29,7 @@ GROUP BY IY
ORDER BY IY
`

let output = yield pg.psql.exec(db, query)
const output = yield pg.psql.exec(db, query)
process.stdout.write(output)
}

Expand All @@ -38,10 +38,10 @@ const cmd = {
description: 'show the mandelbrot set',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
run: cli.command({preauth: true}, co.wrap(run))
args: [{ name: 'database', optional: true }],
run: cli.command({ preauth: true }, co.wrap(run))
}

module.exports = [
Object.assign({command: 'mandelbrot'}, cmd)
Object.assign({ command: 'mandelbrot' }, cmd)
]
Loading