heroku 10.13.2 → 10.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/lib/commands/pg/backups/cancel.js +4 -4
  2. package/lib/commands/pg/backups/capture.js +5 -5
  3. package/lib/commands/pg/backups/delete.js +2 -2
  4. package/lib/commands/pg/backups/download.js +3 -3
  5. package/lib/commands/pg/backups/index.js +2 -2
  6. package/lib/commands/pg/backups/info.js +3 -3
  7. package/lib/commands/pg/backups/restore.js +5 -5
  8. package/lib/commands/pg/backups/schedule.js +7 -7
  9. package/lib/commands/pg/backups/schedules.js +2 -2
  10. package/lib/commands/pg/backups/unschedule.js +6 -5
  11. package/lib/commands/pg/backups/url.js +3 -3
  12. package/lib/commands/pg/bloat.js +5 -4
  13. package/lib/commands/pg/blocking.js +5 -4
  14. package/lib/commands/pg/connection-pooling/attach.js +5 -6
  15. package/lib/commands/pg/copy.js +6 -7
  16. package/lib/commands/pg/credentials/create.js +4 -4
  17. package/lib/commands/pg/credentials/destroy.js +4 -4
  18. package/lib/commands/pg/credentials/repair-default.js +4 -4
  19. package/lib/commands/pg/credentials/rotate.js +4 -4
  20. package/lib/commands/pg/credentials/url.js +4 -4
  21. package/lib/commands/pg/credentials.js +4 -4
  22. package/lib/commands/pg/diagnose.js +6 -5
  23. package/lib/commands/pg/info.js +5 -3
  24. package/lib/commands/pg/kill.js +6 -5
  25. package/lib/commands/pg/killall.js +4 -4
  26. package/lib/commands/pg/links/create.js +10 -8
  27. package/lib/commands/pg/links/destroy.js +4 -4
  28. package/lib/commands/pg/links/index.js +14 -8
  29. package/lib/commands/pg/locks.js +5 -4
  30. package/lib/commands/pg/maintenance/index.js +4 -4
  31. package/lib/commands/pg/maintenance/run.js +4 -4
  32. package/lib/commands/pg/maintenance/window.js +4 -4
  33. package/lib/commands/pg/outliers.d.ts +2 -2
  34. package/lib/commands/pg/outliers.js +9 -7
  35. package/lib/commands/pg/promote.js +5 -4
  36. package/lib/commands/pg/ps.js +6 -5
  37. package/lib/commands/pg/psql.js +6 -4
  38. package/lib/commands/pg/pull.d.ts +1 -1
  39. package/lib/commands/pg/pull.js +4 -4
  40. package/lib/commands/pg/push.d.ts +1 -1
  41. package/lib/commands/pg/push.js +4 -4
  42. package/lib/commands/pg/reset.js +4 -4
  43. package/lib/commands/pg/settings/index.js +2 -2
  44. package/lib/commands/pg/unfollow.js +5 -5
  45. package/lib/commands/pg/upgrade/cancel.js +5 -5
  46. package/lib/commands/pg/upgrade/dryrun.js +5 -5
  47. package/lib/commands/pg/upgrade/index.js +5 -5
  48. package/lib/commands/pg/upgrade/prepare.js +5 -5
  49. package/lib/commands/pg/upgrade/run.js +5 -5
  50. package/lib/commands/pg/upgrade/wait.js +9 -4
  51. package/lib/commands/pg/vacuum-stats.js +5 -4
  52. package/lib/commands/pg/wait.js +6 -4
  53. package/lib/commands/run/detached.d.ts +1 -0
  54. package/lib/commands/run/detached.js +5 -1
  55. package/lib/commands/run/index.d.ts +1 -0
  56. package/lib/commands/run/index.js +7 -2
  57. package/lib/commands/run/inside.js +1 -6
  58. package/lib/lib/addons/resolve.d.ts +6 -7
  59. package/lib/lib/pg/backups.js +4 -4
  60. package/lib/lib/pg/fetcher.d.ts +3 -34
  61. package/lib/lib/pg/fetcher.js +3 -92
  62. package/lib/lib/pg/psql.d.ts +5 -36
  63. package/lib/lib/pg/psql.js +17 -195
  64. package/lib/lib/pg/push_pull.d.ts +2 -7
  65. package/lib/lib/pg/push_pull.js +9 -7
  66. package/lib/lib/pg/setter.js +3 -3
  67. package/lib/lib/pg/types.d.ts +10 -15
  68. package/lib/lib/pg/util.d.ts +6 -32
  69. package/lib/lib/pg/util.js +3 -70
  70. package/lib/lib/run/helpers.d.ts +10 -0
  71. package/lib/lib/run/helpers.js +22 -1
  72. package/oclif.manifest.json +430 -418
  73. package/package.json +4 -6
  74. package/lib/lib/pg/bastion.d.ts +0 -29
  75. package/lib/lib/pg/bastion.js +0 -121
  76. package/lib/lib/pg/config.d.ts +0 -2
  77. package/lib/lib/pg/config.js +0 -13
  78. package/lib/lib/pg/host.d.ts +0 -1
  79. package/lib/lib/pg/host.js +0 -6
@@ -5,8 +5,8 @@ const core_1 = require("@oclif/core");
5
5
  const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
6
6
  const util_1 = require("@oclif/core/lib/util");
7
7
  const tsheredoc_1 = require("tsheredoc");
8
- const fetcher_1 = require("../../lib/pg/fetcher");
9
- const host_1 = require("../../lib/pg/host");
8
+ const heroku_cli_util_2 = require("@heroku/heroku-cli-util");
9
+ const host_1 = require("@heroku/heroku-cli-util/dist/utils/pg/host");
10
10
  const util_2 = require("../../lib/pg/util");
11
11
  const color_1 = require("@heroku-cli/color");
12
12
  const uuid_validate_1 = require("../../lib/utils/uuid-validate");
@@ -82,11 +82,12 @@ class Diagnose extends command_1.Command {
82
82
  return base_params;
83
83
  }
84
84
  async generateReport(database, app) {
85
- const attachment = await (0, fetcher_1.getAttachment)(this.heroku, app, database);
85
+ const dbResolver = new heroku_cli_util_2.utils.pg.DatabaseResolver(this.heroku);
86
+ const attachment = await dbResolver.getAttachment(app, database);
86
87
  const { addon: db } = attachment;
87
88
  const { body: config } = await this.heroku.get(`/apps/${app}/config-vars`);
88
- const { url } = (0, util_2.getConnectionDetails)(attachment, config);
89
- const dbName = (0, util_2.getConfigVarNameFromAttachment)(attachment, config);
89
+ const { url } = dbResolver.getConnectionDetails(attachment, config);
90
+ const dbName = heroku_cli_util_2.utils.pg.psql.getConfigVarNameFromAttachment(attachment, config);
90
91
  const body = await this.generateParams(url, db, dbName);
91
92
  const { body: report } = await this.heroku.post('/reports', { hostname: PGDIAGNOSE_HOST, body });
92
93
  return report;
@@ -4,10 +4,10 @@ const color_1 = require("@heroku-cli/color");
4
4
  const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
6
  const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
7
- const host_1 = require("../../lib/pg/host");
8
7
  const fetcher_1 = require("../../lib/pg/fetcher");
9
8
  const util_1 = require("../../lib/pg/util");
10
9
  const nls_1 = require("../../nls");
10
+ const heroku_cli_util_2 = require("@heroku/heroku-cli-util");
11
11
  function displayDB(db, app) {
12
12
  var _a, _b, _c, _d, _e;
13
13
  if (db.addon.attachment_names) {
@@ -47,7 +47,9 @@ class Info extends command_1.Command {
47
47
  let addons;
48
48
  const { body: config } = await this.heroku.get(`/apps/${app}/config-vars`);
49
49
  if (db) {
50
- addons = await Promise.all([(0, fetcher_1.getAddon)(this.heroku, app, db)]);
50
+ const dbResolver = new heroku_cli_util_2.utils.pg.DatabaseResolver(this.heroku);
51
+ const { addon } = await dbResolver.getAttachment(app, db);
52
+ addons = [addon];
51
53
  }
52
54
  else {
53
55
  addons = await (0, fetcher_1.all)(this.heroku, app);
@@ -58,7 +60,7 @@ class Info extends command_1.Command {
58
60
  }
59
61
  let dbs = await Promise.all(addons.map(async (addon) => {
60
62
  const pgResponse = await this.heroku.get(`/client/v11/databases/${addon.id}`, {
61
- hostname: (0, host_1.default)(),
63
+ hostname: heroku_cli_util_2.utils.pg.host(),
62
64
  })
63
65
  .catch(error => {
64
66
  if (error.statusCode !== 404)
@@ -2,20 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@heroku-cli/command");
4
4
  const core_1 = require("@oclif/core");
5
- const fetcher_1 = require("../../lib/pg/fetcher");
6
- const psql_1 = require("../../lib/pg/psql");
5
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
7
6
  const tsheredoc_1 = require("tsheredoc");
8
7
  const nls_1 = require("../../nls");
9
8
  class Kill extends command_1.Command {
10
9
  async run() {
11
10
  const { flags, args } = await this.parse(Kill);
12
11
  const { app, force } = flags;
13
- const { pid } = args;
14
- const db = await (0, fetcher_1.database)(this.heroku, app, args.database);
12
+ const { pid, database } = args;
13
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
14
+ const db = await dbResolver.getDatabase(app, database);
15
+ const psqlService = new heroku_cli_util_1.utils.pg.PsqlService(db);
15
16
  const query = (0, tsheredoc_1.default) `
16
17
  SELECT ${force ? 'pg_terminate_backend' : 'pg_cancel_backend'}(${Number.parseInt(pid, 10)});
17
18
  `;
18
- const output = await (0, psql_1.exec)(db, query);
19
+ const output = await psqlService.execQuery(query);
19
20
  core_1.ux.log(output);
20
21
  }
21
22
  }
@@ -2,16 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@heroku-cli/command");
4
4
  const core_1 = require("@oclif/core");
5
- const fetcher_1 = require("../../lib/pg/fetcher");
6
- const host_1 = require("../../lib/pg/host");
5
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
7
6
  const nls_1 = require("../../nls");
8
7
  class Killall extends command_1.Command {
9
8
  async run() {
10
9
  const { flags, args } = await this.parse(Killall);
11
10
  const { app } = flags;
12
11
  core_1.ux.action.start('Terminating connections for all credentials');
13
- const database = await (0, fetcher_1.getAddon)(this.heroku, app, args.database);
14
- await this.heroku.post(`/client/v11/databases/${database.id}/connection_reset`, { hostname: (0, host_1.default)() });
12
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
13
+ const { addon } = await dbResolver.getAttachment(app, args.database);
14
+ await this.heroku.post(`/client/v11/databases/${addon.id}/connection_reset`, { hostname: heroku_cli_util_1.utils.pg.host() });
15
15
  core_1.ux.action.stop();
16
16
  }
17
17
  }
@@ -5,8 +5,7 @@ const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
6
  const tsheredoc_1 = require("tsheredoc");
7
7
  const resolve_1 = require("../../../lib/addons/resolve");
8
- const fetcher_1 = require("../../../lib/pg/fetcher");
9
- const host_1 = require("../../../lib/pg/host");
8
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
10
9
  const util_1 = require("../../../lib/pg/util");
11
10
  const nls_1 = require("../../../nls");
12
11
  class Create extends command_1.Command {
@@ -19,8 +18,9 @@ class Create extends command_1.Command {
19
18
  throw new Error('Remote database must be heroku-redis or heroku-postgresql');
20
19
  return addon;
21
20
  };
22
- const [db, target] = await Promise.all([
23
- (0, fetcher_1.getAddon)(this.heroku, app, args.database),
21
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
22
+ const [{ addon: db }, target] = await Promise.all([
23
+ dbResolver.getAttachment(app, args.database),
24
24
  service(args.remote),
25
25
  ]);
26
26
  if ((0, util_1.essentialPlan)(db))
@@ -33,11 +33,13 @@ class Create extends command_1.Command {
33
33
  target: target.name,
34
34
  as: flags.as,
35
35
  },
36
- hostname: (0, host_1.default)(),
36
+ hostname: heroku_cli_util_1.utils.pg.host(),
37
37
  });
38
- if (link.message) {
39
- throw new Error(link.message);
40
- }
38
+ // This doesn't exist according to Shogun's link serializer. May it be that the original idea was to use to catch
39
+ // a Data API error and then show an re-throw the error here?
40
+ // if (link.message) {
41
+ // throw new Error(link.message)
42
+ // }
41
43
  core_1.ux.action.stop(`done, ${color_1.default.cyan(link.name)}`);
42
44
  }
43
45
  }
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const color_1 = require("@heroku-cli/color");
4
4
  const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
- const fetcher_1 = require("../../../lib/pg/fetcher");
6
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
7
7
  const util_1 = require("../../../lib/pg/util");
8
8
  const confirmCommand_1 = require("../../../lib/confirmCommand");
9
9
  const tsheredoc_1 = require("tsheredoc");
10
- const host_1 = require("../../../lib/pg/host");
11
10
  const nls_1 = require("../../../nls");
12
11
  class Destroy extends command_1.Command {
13
12
  async run() {
14
13
  const { flags, args } = await this.parse(Destroy);
15
14
  const { app, confirm } = flags;
16
15
  const { database, link } = args;
17
- const db = await (0, fetcher_1.getAddon)(this.heroku, app, database);
16
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
17
+ const { addon: db } = await dbResolver.getAttachment(app, database);
18
18
  if ((0, util_1.essentialPlan)(db))
19
19
  throw new Error('pg:links isn’t available for Essential-tier databases.');
20
20
  await (0, confirmCommand_1.default)(app, confirm, (0, tsheredoc_1.default)(`
@@ -24,7 +24,7 @@ class Destroy extends command_1.Command {
24
24
  This may have adverse effects for software written against the ${color_1.default.cyan(link)} schema.
25
25
  `));
26
26
  core_1.ux.action.start(`Destroying link ${color_1.default.cyan(link)} from ${color_1.default.yellow(db.name)}`);
27
- await this.heroku.delete(`/client/v11/databases/${db.id}/links/${encodeURIComponent(link)}`, { hostname: (0, host_1.default)() });
27
+ await this.heroku.delete(`/client/v11/databases/${db.id}/links/${encodeURIComponent(link)}`, { hostname: heroku_cli_util_1.utils.pg.host() });
28
28
  core_1.ux.action.stop();
29
29
  }
30
30
  }
@@ -5,7 +5,6 @@ const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
6
  const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
7
7
  const fetcher_1 = require("../../../lib/pg/fetcher");
8
- const host_1 = require("../../../lib/pg/host");
9
8
  const nls_1 = require("../../../nls");
10
9
  class Index extends command_1.Command {
11
10
  async run() {
@@ -13,29 +12,36 @@ class Index extends command_1.Command {
13
12
  const { app } = flags;
14
13
  const { database } = args;
15
14
  let dbs;
16
- if (database)
17
- dbs = await Promise.all([(0, fetcher_1.getAddon)(this.heroku, app, database)]);
15
+ if (database) {
16
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
17
+ const { addon } = await dbResolver.getAttachment(app, database);
18
+ dbs = [addon];
19
+ }
18
20
  else
19
21
  dbs = await (0, fetcher_1.all)(this.heroku, app);
20
22
  if (dbs.length === 0)
21
23
  throw new Error(`No databases on ${color_1.default.app(app)}`);
22
24
  dbs = await Promise.all(dbs.map(async (db) => {
23
- const { body: links } = await this.heroku.get(`/client/v11/databases/${db.id}/links`, { hostname: (0, host_1.default)() });
25
+ const { body: links } = await this.heroku.get(`/client/v11/databases/${db.id}/links`, { hostname: heroku_cli_util_1.utils.pg.host() });
24
26
  db.links = links;
25
27
  return db;
26
28
  }));
27
29
  let once;
28
30
  dbs.forEach(db => {
31
+ var _a, _b;
29
32
  if (once)
30
33
  core_1.ux.log();
31
34
  else
32
35
  once = true;
33
36
  heroku_cli_util_1.hux.styledHeader(color_1.default.yellow(db.name));
34
- if (db.links.message)
35
- return core_1.ux.log(db.links.message);
36
- if (db.links.length === 0)
37
+ // This doesn't exist according to Shogun's link serializer. May it be that the original idea was to use Promise.allSettled
38
+ // and capture here and show only the error message if an error was returned for some database? Currently a CLI error is
39
+ // thrown instead, because Promise.all will reject if any of the promises reject and there's no catch block for that.
40
+ // if (db.links?.message)
41
+ // return ux.log(db.links.message)
42
+ if (((_a = db.links) === null || _a === void 0 ? void 0 : _a.length) === 0)
37
43
  return core_1.ux.log('No data sources are linked into this database');
38
- db.links.forEach((link) => {
44
+ (_b = db.links) === null || _b === void 0 ? void 0 : _b.forEach((link) => {
39
45
  var _a, _b;
40
46
  core_1.ux.log(` * ${color_1.default.cyan(link.name)}`);
41
47
  const remoteAttachmentName = ((_a = link.remote) === null || _a === void 0 ? void 0 : _a.attachment_name) || '';
@@ -2,15 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@heroku-cli/command");
4
4
  const core_1 = require("@oclif/core");
5
- const fetcher_1 = require("../../lib/pg/fetcher");
6
- const psql_1 = require("../../lib/pg/psql");
5
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
7
6
  const tsheredoc_1 = require("tsheredoc");
8
7
  const nls_1 = require("../../nls");
9
8
  class Locks extends command_1.Command {
10
9
  async run() {
11
10
  const { flags, args } = await this.parse(Locks);
12
11
  const { app, truncate } = flags;
13
- const db = await (0, fetcher_1.database)(this.heroku, app, args.database);
12
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
13
+ const db = await dbResolver.getDatabase(app, args.database);
14
+ const psqlService = new heroku_cli_util_1.utils.pg.PsqlService(db);
14
15
  const query = (0, tsheredoc_1.default) `
15
16
  SELECT
16
17
  pg_stat_activity.pid,
@@ -30,7 +31,7 @@ class Locks extends command_1.Command {
30
31
  AND pg_locks.mode = 'ExclusiveLock'
31
32
  AND pg_stat_activity.pid <> pg_backend_pid() order by query_start;
32
33
  `;
33
- const output = await (0, psql_1.exec)(db, query);
34
+ const output = await psqlService.execQuery(query);
34
35
  core_1.ux.log(output);
35
36
  }
36
37
  truncatedQueryString(truncate) {
@@ -2,19 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@heroku-cli/command");
4
4
  const core_1 = require("@oclif/core");
5
- const fetcher_1 = require("../../../lib/pg/fetcher");
5
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
6
6
  const util_1 = require("../../../lib/pg/util");
7
- const host_1 = require("../../../lib/pg/host");
8
7
  const nls_1 = require("../../../nls");
9
8
  class Index extends command_1.Command {
10
9
  async run() {
11
10
  const { flags, args } = await this.parse(Index);
12
11
  const { app } = flags;
13
12
  const { database } = args;
14
- const db = await (0, fetcher_1.getAddon)(this.heroku, app, database);
13
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
14
+ const { addon: db } = await dbResolver.getAttachment(app, database);
15
15
  if ((0, util_1.essentialPlan)(db))
16
16
  core_1.ux.error('pg:maintenance isn’t available for Essential-tier databases.');
17
- const { body: info } = await this.heroku.get(`/client/v11/databases/${db.id}/maintenance`, { hostname: (0, host_1.default)() });
17
+ const { body: info } = await this.heroku.get(`/client/v11/databases/${db.id}/maintenance`, { hostname: heroku_cli_util_1.utils.pg.host() });
18
18
  core_1.ux.log(info.message);
19
19
  }
20
20
  }
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const color_1 = require("@heroku-cli/color");
4
4
  const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
- const fetcher_1 = require("../../../lib/pg/fetcher");
6
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
7
7
  const util_1 = require("../../../lib/pg/util");
8
- const host_1 = require("../../../lib/pg/host");
9
8
  const nls_1 = require("../../../nls");
10
9
  class Run extends command_1.Command {
11
10
  async run() {
12
11
  const { flags, args } = await this.parse(Run);
13
12
  const { app, force } = flags;
14
13
  const { database } = args;
15
- const db = await (0, fetcher_1.getAddon)(this.heroku, app, database);
14
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
15
+ const { addon: db } = await dbResolver.getAttachment(app, database);
16
16
  if ((0, util_1.essentialPlan)(db))
17
17
  core_1.ux.error("pg:maintenance isn't available for Essential-tier databases.");
18
18
  core_1.ux.action.start(`Starting maintenance for ${color_1.default.yellow(db.name)}`);
@@ -21,7 +21,7 @@ class Run extends command_1.Command {
21
21
  if (!appInfo.maintenance)
22
22
  core_1.ux.error('Application must be in maintenance mode or run with --force');
23
23
  }
24
- const { body: response } = await this.heroku.post(`/client/v11/databases/${db.id}/maintenance`, { hostname: (0, host_1.default)() });
24
+ const { body: response } = await this.heroku.post(`/client/v11/databases/${db.id}/maintenance`, { hostname: heroku_cli_util_1.utils.pg.host() });
25
25
  core_1.ux.action.stop(response.message || 'done');
26
26
  }
27
27
  }
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const color_1 = require("@heroku-cli/color");
4
4
  const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
- const host_1 = require("../../../lib/pg/host");
7
6
  const util_1 = require("../../../lib/pg/util");
8
- const fetcher_1 = require("../../../lib/pg/fetcher");
7
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
9
8
  const tsheredoc_1 = require("tsheredoc");
10
9
  const nls_1 = require("../../../nls");
11
10
  class Window extends command_1.Command {
@@ -13,14 +12,15 @@ class Window extends command_1.Command {
13
12
  const { args, flags } = await this.parse(Window);
14
13
  const { database, window } = args;
15
14
  const { app } = flags;
16
- const db = await (0, fetcher_1.getAddon)(this.heroku, app, database);
15
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
16
+ const { addon: db } = await dbResolver.getAttachment(app, database);
17
17
  if ((0, util_1.essentialPlan)(db))
18
18
  core_1.ux.error("pg:maintenance isn't available for Essential-tier databases.");
19
19
  if (!window.match(/^[A-Za-z]{2,10} \d\d?:[03]0$/))
20
20
  core_1.ux.error('Window must be "Day HH:MM" where MM is 00 or 30');
21
21
  core_1.ux.action.start(`Setting maintenance window for ${color_1.default.yellow(db.name)} to ${color_1.default.cyan(window)}`);
22
22
  const { body: response } = await this.heroku.put(`/client/v11/databases/${db.id}/maintenance_window`, {
23
- body: { description: window }, hostname: (0, host_1.default)(),
23
+ body: { description: window }, hostname: heroku_cli_util_1.utils.pg.host(),
24
24
  });
25
25
  core_1.ux.action.stop(response.message || 'done');
26
26
  }
@@ -1,5 +1,4 @@
1
1
  import { Command } from '@heroku-cli/command';
2
- import { getConnectionDetails } from '../../lib/pg/util';
3
2
  export default class Outliers extends Command {
4
3
  static topic: string;
5
4
  static description: string;
@@ -13,7 +12,8 @@ export default class Outliers extends Command {
13
12
  static args: {
14
13
  database: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
15
14
  };
15
+ private psqlService;
16
16
  run(): Promise<void>;
17
- protected ensurePGStatStatement(db: ReturnType<typeof getConnectionDetails>): Promise<void>;
17
+ protected ensurePGStatStatement(): Promise<void>;
18
18
  protected outliersQuery(version: string | undefined, limit: number, truncate: boolean): string;
19
19
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@heroku-cli/command");
4
4
  const core_1 = require("@oclif/core");
5
- const fetcher_1 = require("../../lib/pg/fetcher");
5
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
6
6
  const psql_1 = require("../../lib/pg/psql");
7
7
  const tsheredoc_1 = require("tsheredoc");
8
8
  const nls_1 = require("../../nls");
@@ -10,11 +10,13 @@ class Outliers extends command_1.Command {
10
10
  async run() {
11
11
  const { flags, args } = await this.parse(Outliers);
12
12
  const { app, reset, truncate, num } = flags;
13
- const db = await (0, fetcher_1.database)(this.heroku, app, args.database);
13
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
14
+ const db = await dbResolver.getDatabase(app, args.database);
15
+ this.psqlService = new heroku_cli_util_1.utils.pg.PsqlService(db);
14
16
  const version = await (0, psql_1.fetchVersion)(db);
15
- await this.ensurePGStatStatement(db);
17
+ await this.ensurePGStatStatement();
16
18
  if (reset) {
17
- await (0, psql_1.exec)(db, 'SELECT pg_stat_statements_reset();');
19
+ await this.psqlService.execQuery('SELECT pg_stat_statements_reset();');
18
20
  return;
19
21
  }
20
22
  let limit = 10;
@@ -27,10 +29,10 @@ class Outliers extends command_1.Command {
27
29
  }
28
30
  }
29
31
  const query = this.outliersQuery(version, limit, truncate);
30
- const output = await (0, psql_1.exec)(db, query);
32
+ const output = await this.psqlService.execQuery(query);
31
33
  core_1.ux.log(output);
32
34
  }
33
- async ensurePGStatStatement(db) {
35
+ async ensurePGStatStatement() {
34
36
  const query = (0, tsheredoc_1.default) `
35
37
  SELECT exists(
36
38
  SELECT 1
@@ -39,7 +41,7 @@ class Outliers extends command_1.Command {
39
41
  WHERE e.extname = 'pg_stat_statements' AND n.nspname IN ('public', 'heroku_ext')
40
42
  ) AS available;
41
43
  `;
42
- const output = await (0, psql_1.exec)(db, query);
44
+ const output = await this.psqlService.execQuery(query);
43
45
  if (!output.includes('t')) {
44
46
  core_1.ux.error((0, tsheredoc_1.default) `
45
47
  pg_stat_statements extension need to be installed first.
@@ -5,8 +5,8 @@ const color_1 = require("@heroku-cli/color");
5
5
  const command_1 = require("@heroku-cli/command");
6
6
  const core_1 = require("@oclif/core");
7
7
  const tsheredoc_1 = require("tsheredoc");
8
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
8
9
  const fetcher_1 = require("../../lib/pg/fetcher");
9
- const host_1 = require("../../lib/pg/host");
10
10
  const nls_1 = require("../../nls");
11
11
  class Promote extends command_1.Command {
12
12
  async run() {
@@ -14,7 +14,8 @@ class Promote extends command_1.Command {
14
14
  const { flags, args } = await this.parse(Promote);
15
15
  const { force, app } = flags;
16
16
  const { database } = args;
17
- const attachment = await (0, fetcher_1.getAttachment)(this.heroku, app, database);
17
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
18
+ const attachment = await dbResolver.getAttachment(app, database);
18
19
  core_1.ux.action.start(`Ensuring an alternate alias for existing ${color_1.default.green('DATABASE_URL')}`);
19
20
  const { body: attachments } = await this.heroku.get(`/apps/${app}/addon-attachments`);
20
21
  const current = attachments.find(a => a.name === 'DATABASE');
@@ -50,7 +51,7 @@ class Promote extends command_1.Command {
50
51
  }
51
52
  if (!force) {
52
53
  const { body: status } = await this.heroku.get(`/client/v11/databases/${attachment.addon.id}/wait_status`, {
53
- hostname: (0, host_1.default)(),
54
+ hostname: heroku_cli_util_1.utils.pg.host(),
54
55
  });
55
56
  if (status['waiting?']) {
56
57
  core_1.ux.error((0, tsheredoc_1.default)(`
@@ -95,7 +96,7 @@ class Promote extends command_1.Command {
95
96
  core_1.ux.action.stop();
96
97
  }
97
98
  const { body: promotedDatabaseDetails } = await this.heroku.get(`/client/v11/databases/${attachment.addon.id}`, {
98
- hostname: (0, host_1.default)(),
99
+ hostname: heroku_cli_util_1.utils.pg.host(),
99
100
  });
100
101
  if (promotedDatabaseDetails.following) {
101
102
  const unfollowLeaderCmd = `heroku pg:unfollow ${attachment.addon.name}`;
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@heroku-cli/command");
4
4
  const core_1 = require("@oclif/core");
5
5
  const tsheredoc_1 = require("tsheredoc");
6
- const fetcher_1 = require("../../lib/pg/fetcher");
7
- const psql_1 = require("../../lib/pg/psql");
6
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
8
7
  const nls_1 = require("../../nls");
9
8
  class Ps extends command_1.Command {
10
9
  async run() {
11
10
  const { flags, args } = await this.parse(Ps);
12
11
  const { database: databaseName } = args;
13
12
  const { verbose, app } = flags;
14
- const db = await (0, fetcher_1.database)(this.heroku, app, databaseName);
13
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
14
+ const db = await dbResolver.getDatabase(app, databaseName);
15
+ const psqlService = new heroku_cli_util_1.utils.pg.PsqlService(db);
15
16
  const num = Math.random();
16
17
  const waitingMarker = `${num}${num}`;
17
18
  const waitingQuery = (0, tsheredoc_1.default)(`
@@ -23,7 +24,7 @@ class Ps extends command_1.Command {
23
24
  AND TABLE_NAME = 'pg_stat_activity'
24
25
  AND COLUMN_NAME = 'waiting')
25
26
  `);
26
- const waitingOutput = await (0, psql_1.exec)(db, waitingQuery);
27
+ const waitingOutput = await psqlService.execQuery(waitingQuery);
27
28
  const waiting = waitingOutput.includes(waitingMarker) ? 'waiting' : 'wait_event IS NOT NULL AS waiting';
28
29
  const query = (0, tsheredoc_1.default)(`SELECT pid,
29
30
  state,
@@ -36,7 +37,7 @@ class Ps extends command_1.Command {
36
37
  AND pid <> pg_backend_pid()
37
38
  ORDER BY query_start DESC
38
39
  `);
39
- const output = await (0, psql_1.exec)(db, query);
40
+ const output = await psqlService.execQuery(query);
40
41
  process.stdout.write(output);
41
42
  }
42
43
  }
@@ -3,17 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const color_1 = require("@heroku-cli/color");
4
4
  const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
- const fetcher_1 = require("../../lib/pg/fetcher");
7
- const psql_1 = require("../../lib/pg/psql");
6
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
8
7
  const nls_1 = require("../../nls");
8
+ const psql_1 = require("../../lib/pg/psql");
9
9
  class Psql extends command_1.Command {
10
10
  async run() {
11
11
  const { flags, args } = await this.parse(Psql);
12
12
  const { app, command, credential, file } = flags;
13
13
  const namespace = credential ? `credential:${credential}` : undefined;
14
14
  let db;
15
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
15
16
  try {
16
- db = await (0, fetcher_1.database)(this.heroku, app, args.database, namespace);
17
+ db = await dbResolver.getDatabase(app, args.database, namespace);
17
18
  }
18
19
  catch (error) {
19
20
  if (namespace && error instanceof Error && error.message === "Couldn't find that addon.") {
@@ -21,9 +22,10 @@ class Psql extends command_1.Command {
21
22
  }
22
23
  throw error;
23
24
  }
25
+ const psqlService = new heroku_cli_util_1.utils.pg.PsqlService(db);
24
26
  console.error(`--> Connecting to ${color_1.default.yellow(db.attachment.addon.name)}`);
25
27
  if (command) {
26
- const output = await (0, psql_1.exec)(db, command);
28
+ const output = await psqlService.execQuery(command);
27
29
  process.stdout.write(output);
28
30
  }
29
31
  else if (file) {
@@ -1,5 +1,5 @@
1
1
  import { Command } from '@heroku-cli/command';
2
- import { ConnectionDetails } from '../../lib/pg/util';
2
+ import { ConnectionDetails } from '@heroku/heroku-cli-util';
3
3
  export default class Pull extends Command {
4
4
  static topic: string;
5
5
  static description: string;
@@ -4,8 +4,7 @@ const color_1 = require("@heroku-cli/color");
4
4
  const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
6
  const tsheredoc_1 = require("tsheredoc");
7
- const fetcher_1 = require("../../lib/pg/fetcher");
8
- const util_1 = require("../../lib/pg/util");
7
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
9
8
  const push_pull_1 = require("../../lib/pg/push_pull");
10
9
  const node_child_process_1 = require("node:child_process");
11
10
  const nls_1 = require("../../nls");
@@ -15,8 +14,9 @@ class Pull extends command_1.Command {
15
14
  const { flags, args } = await this.parse(Pull);
16
15
  const { app, 'exclude-table-data': excludeTableData } = flags;
17
16
  const exclusions = (0, push_pull_1.parseExclusions)(excludeTableData);
18
- const source = await (0, fetcher_1.database)(this.heroku, app, args.source);
19
- const target = (0, util_1.parsePostgresConnectionString)(args.target);
17
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
18
+ const source = await dbResolver.getDatabase(app, args.source);
19
+ const target = heroku_cli_util_1.utils.pg.DatabaseResolver.parsePostgresConnectionString(args.target);
20
20
  core_1.ux.log(`Pulling ${color_1.default.cyan(source.attachment.addon.name)} to ${color_1.default.addon(args.target)}`);
21
21
  await this.pull(source, target, exclusions);
22
22
  core_1.ux.log('Pulling complete.');
@@ -1,5 +1,5 @@
1
1
  import { Command } from '@heroku-cli/command';
2
- import { ConnectionDetails } from '../../lib/pg/util';
2
+ import { ConnectionDetails } from '@heroku/heroku-cli-util';
3
3
  export default class Push extends Command {
4
4
  static topic: string;
5
5
  static description: string;
@@ -4,8 +4,7 @@ const color_1 = require("@heroku-cli/color");
4
4
  const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
6
  const tsheredoc_1 = require("tsheredoc");
7
- const fetcher_1 = require("../../lib/pg/fetcher");
8
- const util_1 = require("../../lib/pg/util");
7
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
9
8
  const push_pull_1 = require("../../lib/pg/push_pull");
10
9
  const node_child_process_1 = require("node:child_process");
11
10
  const nls_1 = require("../../nls");
@@ -15,8 +14,9 @@ class Push extends command_1.Command {
15
14
  const { flags, args } = await this.parse(Push);
16
15
  const { app, 'exclude-table-data': excludeTableData } = flags;
17
16
  const exclusions = (0, push_pull_1.parseExclusions)(excludeTableData);
18
- const source = (0, util_1.parsePostgresConnectionString)(args.source);
19
- const target = await (0, fetcher_1.database)(this.heroku, app, args.target);
17
+ const source = heroku_cli_util_1.utils.pg.DatabaseResolver.parsePostgresConnectionString(args.source);
18
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
19
+ const target = await dbResolver.getDatabase(app, args.target);
20
20
  core_1.ux.log(`Pushing ${color_1.default.cyan(args.source)} to ${color_1.default.addon(target.attachment.addon.name)}`);
21
21
  await this.push(source, target, exclusions);
22
22
  core_1.ux.log('Pushing complete.');
@@ -4,15 +4,15 @@ const color_1 = require("@heroku-cli/color");
4
4
  const command_1 = require("@heroku-cli/command");
5
5
  const core_1 = require("@oclif/core");
6
6
  const confirmCommand_1 = require("../../lib/confirmCommand");
7
- const host_1 = require("../../lib/pg/host");
8
- const fetcher_1 = require("../../lib/pg/fetcher");
7
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
9
8
  const tsheredoc_1 = require("tsheredoc");
10
9
  const nls_1 = require("../../nls");
11
10
  class Reset extends command_1.Command {
12
11
  async run() {
13
12
  const { flags, args } = await this.parse(Reset);
14
13
  const { app, confirm, extensions } = flags;
15
- const db = await (0, fetcher_1.getAddon)(this.heroku, app, args.database);
14
+ const dbResolver = new heroku_cli_util_1.utils.pg.DatabaseResolver(this.heroku);
15
+ const { addon: db } = await dbResolver.getAttachment(app, args.database);
16
16
  let extensionsArray;
17
17
  if (extensions) {
18
18
  extensionsArray = extensions.split(',')
@@ -26,7 +26,7 @@ class Reset extends command_1.Command {
26
26
  `));
27
27
  core_1.ux.action.start(`Resetting ${color_1.default.addon(db.name)}`);
28
28
  await this.heroku.put(`/client/v11/databases/${db.id}/reset`, {
29
- body: { extensions: extensionsArray }, hostname: (0, host_1.default)(),
29
+ body: { extensions: extensionsArray }, hostname: heroku_cli_util_1.utils.pg.host(),
30
30
  });
31
31
  core_1.ux.action.stop();
32
32
  }