heroku 11.12.1-beta.1 → 11.13.0-beta.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.
- package/CHANGELOG.md +13 -1
- package/dist/commands/data/pg/info.d.ts +0 -1
- package/dist/commands/data/pg/info.js +3 -11
- package/dist/commands/data/pg/migrate.d.ts +10 -1
- package/dist/commands/data/pg/migrate.js +219 -136
- package/dist/commands/pg/pull.js +1 -5
- package/dist/commands/pg/push.js +1 -5
- package/dist/lib/analytics-telemetry/worker-client.js +24 -13
- package/dist/lib/config/util.js +315 -20
- package/dist/lib/data/types.d.ts +7 -0
- package/dist/lib/data/types.js +1 -0
- package/dist/lib/data/utils.d.ts +6 -0
- package/dist/lib/data/utils.js +9 -0
- package/dist/lib/npm-auth.d.ts +2 -2
- package/dist/lib/npm-auth.js +8 -8
- package/dist/lib/pg/push-pull.d.ts +1 -2
- package/dist/lib/pg/push-pull.js +4 -5
- package/dist/lib/process-shutdown.d.ts +5 -0
- package/dist/lib/process-shutdown.js +117 -0
- package/dist/lib/ps-exec/exec.js +1 -1
- package/dist/lib/ps-exec/ssh.js +15 -9
- package/oclif.manifest.json +1810 -1811
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,19 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
## [11.
|
|
7
|
+
## [11.13.0-beta.0](https://github.com/heroku/cli/compare/v11.12.1...v11.13.0-beta.0) (2026-11-10)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add migration details view ([#4034](https://github.com/heroku/cli/issues/4034)) ([d9ae0c1](https://github.com/heroku/cli/commit/d9ae0c15fdc251eb46263d029ff520d78063cbd5))
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **config:** clean up editor temp files on signals ([#4018](https://github.com/heroku/cli/issues/4018)) ([dfdf9f1](https://github.com/heroku/cli/commit/dfdf9f17e782191e7a1d71d479855f74a1807d3c))
|
|
16
|
+
* **ps:** avoid shell when adding exec buildpack ([#4039](https://github.com/heroku/cli/issues/4039)) ([e30613f](https://github.com/heroku/cli/commit/e30613fd12b2de993fdf42d4b052ac29e80a8877))
|
|
17
|
+
* **security:** eliminate shell injection in database and SSH commands ([#4038](https://github.com/heroku/cli/issues/4038)) ([5ba1e69](https://github.com/heroku/cli/commit/5ba1e69cdc2c7977ab349594cd315bb175cc6484)), references [#4040](https://github.com/heroku/cli/issues/4040)
|
|
18
|
+
|
|
19
|
+
## [11.12.1](https://github.com/heroku/cli/compare/v11.12.0...v11.12.1) (2026-10-22)
|
|
8
20
|
|
|
9
21
|
### Bug Fixes
|
|
10
22
|
|
|
@@ -5,6 +5,7 @@ import tsheredoc from 'tsheredoc';
|
|
|
5
5
|
import BaseCommand from '../../../lib/data/base-command.js';
|
|
6
6
|
import { formatQuotaStatus } from '../../../lib/data/display-quota.js';
|
|
7
7
|
import { parseAttachmentFactors } from '../../../lib/data/parse-attachment-factors.js';
|
|
8
|
+
import { renderTimestamp } from '../../../lib/data/utils.js';
|
|
8
9
|
const heredoc = tsheredoc;
|
|
9
10
|
const poolStatusRenderMap = {
|
|
10
11
|
available: color.success('✓ Available'),
|
|
@@ -47,7 +48,7 @@ export default class DataPgInfo extends BaseCommand {
|
|
|
47
48
|
: color.warning(hux.toTitleCase(status));
|
|
48
49
|
const rollbackInfo = features.rollback.enabled
|
|
49
50
|
? (features.rollback.earliest_time
|
|
50
|
-
? `earliest from ${
|
|
51
|
+
? `earliest from ${renderTimestamp(features.rollback.earliest_time)}`
|
|
51
52
|
: 'Unavailable')
|
|
52
53
|
: 'Unsupported';
|
|
53
54
|
/* eslint-disable perfectionist/sort-objects */
|
|
@@ -66,7 +67,7 @@ export default class DataPgInfo extends BaseCommand {
|
|
|
66
67
|
}
|
|
67
68
|
Object.assign(infoObject, {
|
|
68
69
|
...infoObject,
|
|
69
|
-
Created:
|
|
70
|
+
Created: renderTimestamp(createdAt),
|
|
70
71
|
Quotas: ' ',
|
|
71
72
|
});
|
|
72
73
|
const quotasInfo = this.renderQuotasInfo(quotas);
|
|
@@ -92,15 +93,6 @@ export default class DataPgInfo extends BaseCommand {
|
|
|
92
93
|
}
|
|
93
94
|
return `${hux.toHumanReadableDataSize(storageLimit.current)} / ${hux.toHumanReadableDataSize(storageLimit.limit)}`;
|
|
94
95
|
}
|
|
95
|
-
renderDateInfo(dateStr) {
|
|
96
|
-
const date = new Date(dateStr);
|
|
97
|
-
const year = date.getUTCFullYear();
|
|
98
|
-
const month = String(date.getUTCMonth() + 1).padStart(2, '0');
|
|
99
|
-
const day = String(date.getUTCDate()).padStart(2, '0');
|
|
100
|
-
const hours = String(date.getUTCHours()).padStart(2, '0');
|
|
101
|
-
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
|
|
102
|
-
return `${year}-${month}-${day} ${hours}:${minutes} UTC`;
|
|
103
|
-
}
|
|
104
96
|
renderQuotasInfo(quotas) {
|
|
105
97
|
const quotaInfo = {};
|
|
106
98
|
for (const quota of quotas) {
|
|
@@ -21,11 +21,20 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
21
21
|
createAddon(...args: Parameters<typeof createAddon>): Promise<Heroku.AddOn>;
|
|
22
22
|
prompt<T extends inquirer.Answers>(...args: Parameters<typeof inquirer.prompt<T>>): Promise<T>;
|
|
23
23
|
run(): Promise<void>;
|
|
24
|
-
private actOnReadyMigration;
|
|
25
24
|
private configureMigration;
|
|
25
|
+
private confirmMigrationAction;
|
|
26
26
|
private createTargetDatabase;
|
|
27
|
+
private databaseDetails;
|
|
28
|
+
private databaseName;
|
|
27
29
|
private getAppDatabases;
|
|
28
30
|
private getMigrationTargetsAndInfo;
|
|
29
31
|
private isActiveMigration;
|
|
30
32
|
private loopMainMenu;
|
|
33
|
+
private majorVersion;
|
|
34
|
+
private manageMigration;
|
|
35
|
+
private methodLabel;
|
|
36
|
+
private printMigrationDetails;
|
|
37
|
+
private printVersionChangeWarning;
|
|
38
|
+
private refreshDatabasesAndMigrations;
|
|
39
|
+
private versionLabel;
|
|
31
40
|
}
|
|
@@ -8,18 +8,26 @@ import createAddon from '../../../lib/addons/create-addon.js';
|
|
|
8
8
|
import BaseCommand from '../../../lib/data/base-command.js';
|
|
9
9
|
import PoolConfig from '../../../lib/data/pool-config.js';
|
|
10
10
|
import { DatabaseStatus, MigrationMethod, MigrationStatus, } from '../../../lib/data/types.js';
|
|
11
|
-
import { fetchLevelsAndPricing } from '../../../lib/data/utils.js';
|
|
11
|
+
import { fetchLevelsAndPricing, renderTimestamp } from '../../../lib/data/utils.js';
|
|
12
12
|
import { getAttachmentNamesByAddon } from '../../../lib/pg/util.js';
|
|
13
13
|
import { huxTableNoWrapOptions } from '../../../lib/utils/table-utils.js';
|
|
14
14
|
const heredoc = tsheredoc;
|
|
15
15
|
const { prompt, Separator } = inquirer;
|
|
16
|
+
// Labels for the transfer strategies a migration can use
|
|
17
|
+
const migrationMethodLabels = {
|
|
18
|
+
dms_assess_only: 'Assessment',
|
|
19
|
+
dms_migrate: 'Snapshot',
|
|
20
|
+
dms_migrate_cdc: 'Streaming',
|
|
21
|
+
dump_restore: 'Snapshot',
|
|
22
|
+
pgcopydb_migrate: 'Snapshot',
|
|
23
|
+
};
|
|
16
24
|
export default class DataPgMigrate extends BaseCommand {
|
|
17
25
|
static description = 'migrate an existing classic Postgres database to an Advanced database';
|
|
18
26
|
static flags = {
|
|
19
27
|
app: Flags.app({ required: true }),
|
|
20
28
|
method: Flags.string({
|
|
21
29
|
hidden: true,
|
|
22
|
-
options: ['snapshot'
|
|
30
|
+
options: ['snapshot'],
|
|
23
31
|
}),
|
|
24
32
|
'no-wrap': Flags.noWrap(),
|
|
25
33
|
remote: Flags.remote(),
|
|
@@ -47,7 +55,7 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
47
55
|
// came from the flag so the interactive selection step is skipped throughout.
|
|
48
56
|
if (method !== undefined) {
|
|
49
57
|
this.methodProvidedViaFlag = true;
|
|
50
|
-
this.selectedMigrationMethod =
|
|
58
|
+
this.selectedMigrationMethod = MigrationMethod.FULL_LOAD;
|
|
51
59
|
}
|
|
52
60
|
ux.stdout(heredoc `
|
|
53
61
|
|
|
@@ -58,12 +66,12 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
58
66
|
do {
|
|
59
67
|
action = await this.loopMainMenu(app);
|
|
60
68
|
switch (action) {
|
|
61
|
-
case '__cancel_migration': {
|
|
62
|
-
await this.actOnReadyMigration('cancel');
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
69
|
case '__configure_migration': {
|
|
66
|
-
await this.configureMigration();
|
|
70
|
+
const migrationId = await this.configureMigration();
|
|
71
|
+
if (migrationId) {
|
|
72
|
+
await this.refreshDatabasesAndMigrations();
|
|
73
|
+
await this.manageMigration(migrationId);
|
|
74
|
+
}
|
|
67
75
|
break;
|
|
68
76
|
}
|
|
69
77
|
case '__exit': {
|
|
@@ -72,89 +80,14 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
72
80
|
case '__refresh': {
|
|
73
81
|
break;
|
|
74
82
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
default: {
|
|
84
|
+
// Any other choice is the ID of a migration to manage
|
|
85
|
+
await this.manageMigration(action);
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
88
|
} while (action !== '__exit');
|
|
81
89
|
}
|
|
82
|
-
//
|
|
83
|
-
async actOnReadyMigration(migrationAction) {
|
|
84
|
-
const readyMigrations = this.migrationTargets.filter(migration => migration.status === MigrationStatus.READY);
|
|
85
|
-
let currentStep = '__select_migration';
|
|
86
|
-
let selectedMigrationId;
|
|
87
|
-
while (currentStep !== '__exit') {
|
|
88
|
-
switch (currentStep) {
|
|
89
|
-
case '__confirm_action': {
|
|
90
|
-
const selectedMigration = readyMigrations.find(migration => migration.id === selectedMigrationId);
|
|
91
|
-
const sourceDatabase = this.classicDatabases.find(db => db.id === selectedMigration.source_id);
|
|
92
|
-
const targetDatabase = this.advancedDatabases.find(db => db.id === selectedMigration.target_id);
|
|
93
|
-
if (migrationAction === 'start') {
|
|
94
|
-
ux.stdout(color.info(heredoc `
|
|
95
|
-
|
|
96
|
-
Your database ${color.datastore(sourceDatabase?.name ?? color.gray('unknown'))} will be unavailable after starting the migration until the migration is complete.
|
|
97
|
-
If there are any issues during the migration, we end the migration and make the source database available again.
|
|
98
|
-
The database ${color.datastore(sourceDatabase?.name ?? color.gray('unknown'))} can be offline for several hours during the migration.
|
|
99
|
-
You'll receive an email when the migration is complete.
|
|
100
|
-
You can't cancel the migration after starting it.
|
|
101
|
-
|
|
102
|
-
`));
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
ux.stdout(color.info(heredoc `
|
|
106
|
-
|
|
107
|
-
After canceling, you must create a new migration configuration and wait for the migration tooling to finish preparing to
|
|
108
|
-
migrate ${color.datastore(sourceDatabase?.name ?? color.gray('unknown'))} again.
|
|
109
|
-
|
|
110
|
-
`));
|
|
111
|
-
}
|
|
112
|
-
const { action } = await this.prompt({
|
|
113
|
-
choices: [
|
|
114
|
-
{ name: 'Confirm', value: '__confirm' },
|
|
115
|
-
{ name: 'Go back', value: '__go_back' },
|
|
116
|
-
],
|
|
117
|
-
message: `Confirm to ${migrationAction} migration:`,
|
|
118
|
-
name: 'action',
|
|
119
|
-
type: 'list',
|
|
120
|
-
});
|
|
121
|
-
if (action === '__go_back') {
|
|
122
|
-
currentStep = '__select_migration';
|
|
123
|
-
}
|
|
124
|
-
else if (action === '__confirm') {
|
|
125
|
-
ux.stdout();
|
|
126
|
-
ux.action.start(`${migrationAction === 'start' ? 'Starting' : 'Canceling'} migration of ${color.datastore(sourceDatabase?.name ?? color.gray('unknown'))} `
|
|
127
|
-
+ `to ${color.datastore(targetDatabase?.name ?? color.gray('unknown'))}`);
|
|
128
|
-
await this.dataApi.post(`/data/postgres/v1/${selectedMigration.target_id}/migrations/${migrationAction === 'start' ? 'run' : 'cancel'}`);
|
|
129
|
-
ux.action.stop();
|
|
130
|
-
currentStep = '__exit';
|
|
131
|
-
}
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case '__select_migration': {
|
|
135
|
-
const choices = [];
|
|
136
|
-
for (const migration of readyMigrations) {
|
|
137
|
-
const sourceDatabase = this.classicDatabases.find(db => db.id === migration.source_id);
|
|
138
|
-
const targetDatabase = this.advancedDatabases.find(db => db.id === migration.target_id);
|
|
139
|
-
const name = `From ${color.datastore(sourceDatabase?.name ?? color.gray('unknown'))} to ${color.datastore(targetDatabase?.name ?? color.gray('unknown'))}`;
|
|
140
|
-
choices.push({
|
|
141
|
-
name,
|
|
142
|
-
value: migration.id,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
choices.push(new Separator(), { name: 'Go back', value: '__go_back' });
|
|
146
|
-
selectedMigrationId = (await this.prompt({
|
|
147
|
-
choices,
|
|
148
|
-
message: `Select the migration to ${migrationAction}:`,
|
|
149
|
-
name: 'migration',
|
|
150
|
-
type: 'list',
|
|
151
|
-
})).migration;
|
|
152
|
-
currentStep = selectedMigrationId === '__go_back' ? '__exit' : '__confirm_action';
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
90
|
+
// Returns the ID of the configured migration, or undefined if the user went back
|
|
158
91
|
async configureMigration() {
|
|
159
92
|
// When the method wasn't provided via the --method flag, clear any method
|
|
160
93
|
// selected during a previous migration in this session so a stale value can
|
|
@@ -166,6 +99,7 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
166
99
|
let sourceDatabaseId;
|
|
167
100
|
let targetDatabaseId;
|
|
168
101
|
let targetDatabaseName;
|
|
102
|
+
let targetDatabaseVersion;
|
|
169
103
|
const confirmMigration = async () => {
|
|
170
104
|
ux.stdout(color.info(heredoc `
|
|
171
105
|
|
|
@@ -176,6 +110,7 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
176
110
|
Preparing the migration deletes all the data on the destination database ${color.datastore(targetDatabaseName)}.
|
|
177
111
|
|
|
178
112
|
`));
|
|
113
|
+
this.printVersionChangeWarning(this.classicDatabases.find(db => db.id === sourceDatabaseId)?.version, targetDatabaseVersion);
|
|
179
114
|
const { action } = await this.prompt({
|
|
180
115
|
choices: [
|
|
181
116
|
{ name: 'Confirm', value: '__confirm' },
|
|
@@ -190,15 +125,13 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
190
125
|
const selectMethod = async () => {
|
|
191
126
|
ux.stdout(color.info(heredoc `
|
|
192
127
|
|
|
193
|
-
Migration
|
|
128
|
+
Migration Methods:
|
|
194
129
|
· Snapshot: Copies the data from the source database to the destination database. Requires downtime on the source database depending on the size. Best for smaller databases or when a maintenance window is acceptable.
|
|
195
|
-
· Streaming: Replicates changes from the source database to the destination database continuously until you start the migration. Requires minimal downtime. Best for larger databases or when you need near-zero downtime.
|
|
196
130
|
|
|
197
131
|
`));
|
|
198
132
|
const { method } = await this.prompt({
|
|
199
133
|
choices: [
|
|
200
134
|
{ name: 'Snapshot', value: '__snapshot' },
|
|
201
|
-
{ name: 'Streaming', value: '__streaming' },
|
|
202
135
|
new Separator(),
|
|
203
136
|
{ name: 'Go back', value: '__go_back' },
|
|
204
137
|
],
|
|
@@ -211,7 +144,8 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
211
144
|
const selectSource = async () => {
|
|
212
145
|
const choices = [];
|
|
213
146
|
for (const database of this.classicDatabases) {
|
|
214
|
-
const name = `${color.datastore(database.name)}
|
|
147
|
+
const name = `${color.datastore(database.name)}${this.versionLabel(database.version)} `
|
|
148
|
+
+ `as ${database.attachment_names.map(name => color.attachment(name)).join(', ')}`;
|
|
215
149
|
if (this.migrationTargets.some(migration => migration.source_id === database.id && this.isActiveMigration(migration))) {
|
|
216
150
|
choices.push({
|
|
217
151
|
disabled: 'already a source database for an active migration',
|
|
@@ -238,7 +172,8 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
238
172
|
const selectTarget = async () => {
|
|
239
173
|
const choices = [];
|
|
240
174
|
for (const database of this.advancedDatabases) {
|
|
241
|
-
const name = `${color.datastore(database.name)}
|
|
175
|
+
const name = `${color.datastore(database.name)}${this.versionLabel(database.info?.version)} `
|
|
176
|
+
+ `as ${database.attachment_names.map(name => color.attachment(name)).join(', ')}`;
|
|
242
177
|
if (this.migrationTargets.some(migration => migration.target_id === database.id && this.isActiveMigration(migration))) {
|
|
243
178
|
choices.push({
|
|
244
179
|
disabled: 'already a destination database for an active migration',
|
|
@@ -246,7 +181,7 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
246
181
|
value: database.id,
|
|
247
182
|
});
|
|
248
183
|
}
|
|
249
|
-
else if (database.info?.status === DatabaseStatus.AVAILABLE) {
|
|
184
|
+
else if (database.info?.status === DatabaseStatus.AVAILABLE || database.info?.status === DatabaseStatus.PROVISIONING) {
|
|
250
185
|
choices.push({
|
|
251
186
|
name,
|
|
252
187
|
value: database.id,
|
|
@@ -274,7 +209,9 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
274
209
|
name: 'database',
|
|
275
210
|
type: 'list',
|
|
276
211
|
})).database;
|
|
277
|
-
|
|
212
|
+
const targetDatabase = this.advancedDatabases.find(db => db.id === targetDatabaseId);
|
|
213
|
+
targetDatabaseName = targetDatabase?.name;
|
|
214
|
+
targetDatabaseVersion = targetDatabase?.info?.version;
|
|
278
215
|
return targetDatabaseId;
|
|
279
216
|
};
|
|
280
217
|
while (currentStep !== '__exit') {
|
|
@@ -287,14 +224,14 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
287
224
|
else if (action === '__confirm') {
|
|
288
225
|
ux.stdout('');
|
|
289
226
|
ux.action.start('Configuring migration');
|
|
290
|
-
await this.dataApi.post(`/data/postgres/v1/${targetDatabaseId}/migrations`, {
|
|
227
|
+
const { body: migration } = await this.dataApi.post(`/data/postgres/v1/${targetDatabaseId}/migrations`, {
|
|
291
228
|
body: {
|
|
292
229
|
method: this.selectedMigrationMethod,
|
|
293
230
|
source_id: sourceDatabaseId,
|
|
294
231
|
},
|
|
295
232
|
});
|
|
296
233
|
ux.action.stop();
|
|
297
|
-
|
|
234
|
+
return migration.id;
|
|
298
235
|
}
|
|
299
236
|
break;
|
|
300
237
|
}
|
|
@@ -304,7 +241,7 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
304
241
|
currentStep = '__select_target';
|
|
305
242
|
}
|
|
306
243
|
else {
|
|
307
|
-
this.selectedMigrationMethod =
|
|
244
|
+
this.selectedMigrationMethod = MigrationMethod.FULL_LOAD;
|
|
308
245
|
currentStep = '__confirm_migration';
|
|
309
246
|
}
|
|
310
247
|
break;
|
|
@@ -337,6 +274,54 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
337
274
|
}
|
|
338
275
|
}
|
|
339
276
|
}
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
// Returns whether the user confirmed the action
|
|
280
|
+
async confirmMigrationAction(migration, migrationAction) {
|
|
281
|
+
const sourceDatabase = this.classicDatabases.find(db => db.id === migration.source_id);
|
|
282
|
+
const targetDatabase = this.advancedDatabases.find(db => db.id === migration.target_id);
|
|
283
|
+
if (migrationAction === 'start') {
|
|
284
|
+
ux.stdout(color.info(heredoc `
|
|
285
|
+
|
|
286
|
+
Your database ${this.databaseName(sourceDatabase)} will be unavailable after starting the migration until the migration is complete.
|
|
287
|
+
If there are any issues during the migration, we end the migration and make the source database available again.
|
|
288
|
+
The database ${this.databaseName(sourceDatabase)} can be offline for several hours during the migration.
|
|
289
|
+
You'll receive an email when the migration is complete.
|
|
290
|
+
|
|
291
|
+
`));
|
|
292
|
+
this.printVersionChangeWarning(sourceDatabase?.version, targetDatabase?.info?.version);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
ux.stdout();
|
|
296
|
+
if (migration.status === MigrationStatus.MIGRATING) {
|
|
297
|
+
ux.stdout(color.info(heredoc `
|
|
298
|
+
Canceling stops the running migration and makes ${this.databaseName(sourceDatabase)} available again.
|
|
299
|
+
You'll receive an email when ${this.databaseName(sourceDatabase)} is available.
|
|
300
|
+
`.trimEnd()));
|
|
301
|
+
}
|
|
302
|
+
ux.stdout(color.info(heredoc `
|
|
303
|
+
After canceling, you must create a new migration configuration and wait for the migration tooling to finish preparing to
|
|
304
|
+
migrate ${this.databaseName(sourceDatabase)} again.
|
|
305
|
+
|
|
306
|
+
`));
|
|
307
|
+
}
|
|
308
|
+
const { action } = await this.prompt({
|
|
309
|
+
choices: [
|
|
310
|
+
{ name: 'Confirm', value: '__confirm' },
|
|
311
|
+
{ name: 'Go back', value: '__go_back' },
|
|
312
|
+
],
|
|
313
|
+
message: `Confirm to ${migrationAction} migration:`,
|
|
314
|
+
name: 'action',
|
|
315
|
+
type: 'list',
|
|
316
|
+
});
|
|
317
|
+
if (action === '__confirm') {
|
|
318
|
+
ux.stdout();
|
|
319
|
+
ux.action.start(`${migrationAction === 'start' ? 'Starting' : 'Canceling'} migration of ${this.databaseName(sourceDatabase)} `
|
|
320
|
+
+ `to ${this.databaseName(targetDatabase)}`);
|
|
321
|
+
await this.dataApi.post(`/data/postgres/v1/${migration.target_id}/migrations/${migrationAction === 'start' ? 'run' : 'cancel'}`);
|
|
322
|
+
ux.action.stop();
|
|
323
|
+
}
|
|
324
|
+
return action === '__confirm';
|
|
340
325
|
}
|
|
341
326
|
async createTargetDatabase(sourceDatabaseId) {
|
|
342
327
|
let networking;
|
|
@@ -364,10 +349,13 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
364
349
|
}
|
|
365
350
|
// Database cluster provisioning (leader pool)
|
|
366
351
|
const config = {
|
|
367
|
-
from: sourceDatabaseId,
|
|
368
352
|
'high-availability': highAvailability,
|
|
369
353
|
level: leaderLevel,
|
|
370
354
|
};
|
|
355
|
+
const version = this.majorVersion(sourceDatabase.version);
|
|
356
|
+
if (version) {
|
|
357
|
+
config.version = version;
|
|
358
|
+
}
|
|
371
359
|
let addon;
|
|
372
360
|
try {
|
|
373
361
|
addon = await this.createAddon(this.heroku, sourceDatabase.app.name, servicePlan, undefined, false, {
|
|
@@ -382,6 +370,18 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
382
370
|
}
|
|
383
371
|
return addon;
|
|
384
372
|
}
|
|
373
|
+
// e.g. ⛁ postgresql-name (DATABASE_URL) - Postgres 17.6 - Available
|
|
374
|
+
databaseDetails(database, version, status) {
|
|
375
|
+
const attachments = database?.attachment_names?.map(name => color.attachment(name)).join(', ');
|
|
376
|
+
return [
|
|
377
|
+
this.databaseName(database) + (attachments ? ` (${attachments})` : ''),
|
|
378
|
+
version && `Postgres ${version}`,
|
|
379
|
+
status,
|
|
380
|
+
].filter(Boolean).join(' - ');
|
|
381
|
+
}
|
|
382
|
+
databaseName(database) {
|
|
383
|
+
return color.datastore(database?.name ?? color.gray('unknown'));
|
|
384
|
+
}
|
|
385
385
|
async getAppDatabases(app) {
|
|
386
386
|
const { body: appAttachments } = await this.heroku.get(`/apps/${app}/addon-attachments`, {
|
|
387
387
|
headers: {
|
|
@@ -403,10 +403,17 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
403
403
|
this.classicDatabases = ownedDatabaseAddons.filter(db => utils.pg.isLegacyDatabase(db) && !utils.pg.isEssentialDatabase(db));
|
|
404
404
|
this.advancedDatabases = ownedDatabaseAddons.filter(db => utils.pg.isAdvancedDatabase(db));
|
|
405
405
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
const
|
|
409
|
-
const
|
|
406
|
+
// Loads the migrations and info of the given databases, every database on the app by default
|
|
407
|
+
async getMigrationTargetsAndInfo(advancedDatabases = this.advancedDatabases, classicDatabases = this.classicDatabases) {
|
|
408
|
+
const migrationPromises = Promise.allSettled(advancedDatabases.map(db => this.dataApi.get(`/data/postgres/v1/${db.id}/migrations`)));
|
|
409
|
+
const infoPromises = Promise.allSettled(advancedDatabases.map(db => this.dataApi.get(`/data/postgres/v1/${db.id}/info`)));
|
|
410
|
+
// The source database version and status are only informational, so failures fetching them are ignored
|
|
411
|
+
const sourceInfoPromises = Promise.allSettled(classicDatabases.map(async (db) => {
|
|
412
|
+
const { body } = await this.dataApi.get(`/client/v11/databases/${db.id}`);
|
|
413
|
+
db.version = body.postgres_version || undefined;
|
|
414
|
+
db.status = body.info?.find(info => info.name === 'Status')?.values[0];
|
|
415
|
+
}));
|
|
416
|
+
const [migrationResults, infoResults] = await Promise.all([migrationPromises, infoPromises, sourceInfoPromises]);
|
|
410
417
|
// 404 errors are expected for Advanced databases that are not a migration target (at least not yet)
|
|
411
418
|
const unexpectedError = [...migrationResults, ...infoResults]
|
|
412
419
|
.filter(queryResult => queryResult.status === 'rejected')
|
|
@@ -428,12 +435,19 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
428
435
|
}
|
|
429
436
|
}
|
|
430
437
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
438
|
+
// Keep the migrations of databases that weren't loaded
|
|
439
|
+
const loadedDatabaseIds = new Set(advancedDatabases.map(db => db.id));
|
|
440
|
+
this.migrationTargets = [
|
|
441
|
+
...this.migrationTargets.filter(migration => !loadedDatabaseIds.has(migration.target_id)),
|
|
442
|
+
...migrationResults
|
|
443
|
+
.filter(queryResult => queryResult.status === 'fulfilled')
|
|
444
|
+
.map(queryResult => queryResult.value.body),
|
|
445
|
+
];
|
|
434
446
|
}
|
|
447
|
+
// A canceling migration keeps its databases until the cancellation finishes cleaning up
|
|
435
448
|
isActiveMigration(migration) {
|
|
436
|
-
return migration.status === MigrationStatus.
|
|
449
|
+
return migration.status === MigrationStatus.CANCELLING
|
|
450
|
+
|| migration.status === MigrationStatus.CREATING_TARGET
|
|
437
451
|
|| migration.status === MigrationStatus.PREPARING
|
|
438
452
|
|| migration.status === MigrationStatus.MIGRATING
|
|
439
453
|
|| migration.status === MigrationStatus.PROMOTING
|
|
@@ -441,21 +455,24 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
441
455
|
}
|
|
442
456
|
async loopMainMenu(app) {
|
|
443
457
|
// Update our database lists
|
|
444
|
-
await this.
|
|
445
|
-
await this.getMigrationTargetsAndInfo();
|
|
458
|
+
await this.refreshDatabasesAndMigrations();
|
|
446
459
|
const pendingMigrations = this.classicDatabases.filter(db => !this.migrationTargets.some(migration => migration.source_id === db.id && this.isActiveMigration(migration)));
|
|
447
460
|
hux.styledHeader('Configured Migrations');
|
|
448
461
|
if (this.migrationTargets.length > 0) {
|
|
449
462
|
/* eslint-disable perfectionist/sort-objects */
|
|
450
463
|
hux.table(this.migrationTargets, {
|
|
451
464
|
source: {
|
|
452
|
-
get: (migration) =>
|
|
465
|
+
get: (migration) => this.databaseName(this.classicDatabases.find(db => db.id === migration.source_id)),
|
|
453
466
|
header: 'Source Database',
|
|
454
467
|
},
|
|
455
468
|
destination: {
|
|
456
|
-
get: (migration) =>
|
|
469
|
+
get: (migration) => this.databaseName(this.advancedDatabases.find(db => db.id === migration.target_id)),
|
|
457
470
|
header: 'Destination Database',
|
|
458
471
|
},
|
|
472
|
+
method: {
|
|
473
|
+
get: (migration) => this.methodLabel(migration) ?? '',
|
|
474
|
+
header: 'Method',
|
|
475
|
+
},
|
|
459
476
|
status: {
|
|
460
477
|
get: (migration) => migration.status_description,
|
|
461
478
|
header: 'Status',
|
|
@@ -466,48 +483,114 @@ export default class DataPgMigrate extends BaseCommand {
|
|
|
466
483
|
else {
|
|
467
484
|
ux.stdout(`You haven't configured any migrations for ${color.app(app)} yet.\n`);
|
|
468
485
|
}
|
|
469
|
-
const choices =
|
|
486
|
+
const choices = this.migrationTargets.map(migration => ({
|
|
487
|
+
name: `Manage migration from ${this.databaseName(this.classicDatabases.find(db => db.id === migration.source_id))} `
|
|
488
|
+
+ `to ${this.databaseName(this.advancedDatabases.find(db => db.id === migration.target_id))}`,
|
|
489
|
+
value: migration.id,
|
|
490
|
+
}));
|
|
470
491
|
if (pendingMigrations.length > 0) {
|
|
471
492
|
choices.push({
|
|
472
|
-
name: 'Configure a database migration',
|
|
493
|
+
name: 'Configure a new database migration',
|
|
473
494
|
value: '__configure_migration',
|
|
474
495
|
});
|
|
475
496
|
}
|
|
476
497
|
else {
|
|
477
498
|
choices.push({
|
|
478
|
-
disabled:
|
|
479
|
-
|
|
499
|
+
disabled: this.classicDatabases.length === 0
|
|
500
|
+
? `no classic Postgres databases on ${color.app(app)}`
|
|
501
|
+
: `all classic Postgres databases on ${color.app(app)} have an active migration`,
|
|
502
|
+
name: color.gray('Configure a new database migration'),
|
|
480
503
|
value: '__configure_migration',
|
|
481
504
|
});
|
|
482
505
|
}
|
|
483
|
-
if (this.migrationTargets.some(migration => migration.status === 'ready')) {
|
|
484
|
-
choices.push({
|
|
485
|
-
name: 'Start a migration',
|
|
486
|
-
value: '__start_migration',
|
|
487
|
-
}, {
|
|
488
|
-
name: 'Cancel a migration',
|
|
489
|
-
value: '__cancel_migration',
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
const disabledReason = `no ready migrations on ${color.app(app)}`;
|
|
494
|
-
choices.push({
|
|
495
|
-
disabled: disabledReason,
|
|
496
|
-
name: color.gray('Start a migration'),
|
|
497
|
-
value: '__start_migration',
|
|
498
|
-
}, {
|
|
499
|
-
disabled: disabledReason,
|
|
500
|
-
name: color.gray('Cancel a migration'),
|
|
501
|
-
value: '__cancel_migration',
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
506
|
choices.push(new Separator(), { name: 'Refresh', value: '__refresh' }, { name: 'Exit', value: '__exit' });
|
|
505
507
|
const { action } = await this.prompt({
|
|
506
508
|
choices,
|
|
507
|
-
message: 'What do you want to do
|
|
509
|
+
message: 'What do you want to do?',
|
|
508
510
|
name: 'action',
|
|
509
511
|
type: 'list',
|
|
510
512
|
});
|
|
511
513
|
return action;
|
|
512
514
|
}
|
|
515
|
+
// Versions can include the minor version (e.g. '16.4'), but we only compare and provision by major version
|
|
516
|
+
majorVersion(version) {
|
|
517
|
+
return version?.split('.')[0];
|
|
518
|
+
}
|
|
519
|
+
async manageMigration(migrationId) {
|
|
520
|
+
let action;
|
|
521
|
+
do {
|
|
522
|
+
const migration = this.migrationTargets.find(migration => migration.id === migrationId);
|
|
523
|
+
if (!migration) {
|
|
524
|
+
ux.stdout(color.warning('\nThe migration is no longer available. Either a newer migration replaced it or its destination database no longer exists.\n'));
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
this.printMigrationDetails(migration);
|
|
528
|
+
// Disabled choices without a reason show the default "(Disabled)"
|
|
529
|
+
const actionChoice = (name, value, enabled, disabledReason) => (enabled ? { name, value } : { disabled: disabledReason || true, name: color.gray(name), value });
|
|
530
|
+
action = (await this.prompt({
|
|
531
|
+
choices: [
|
|
532
|
+
{ name: 'Refresh', value: '__refresh' },
|
|
533
|
+
// The API decides whether a migration can be started or canceled, and why not
|
|
534
|
+
actionChoice('Start', '__start_migration', migration.can_start, migration.start_disabled_reason),
|
|
535
|
+
actionChoice('Cancel', '__cancel_migration', migration.can_cancel, migration.cancel_disabled_reason),
|
|
536
|
+
new Separator(),
|
|
537
|
+
{ name: 'Go back', value: '__go_back' },
|
|
538
|
+
],
|
|
539
|
+
message: 'What do you want to do?',
|
|
540
|
+
name: 'action',
|
|
541
|
+
type: 'list',
|
|
542
|
+
})).action;
|
|
543
|
+
// Going back from the confirmation changes nothing, so there's nothing to refresh
|
|
544
|
+
let refresh = action === '__refresh';
|
|
545
|
+
if (action === '__start_migration' || action === '__cancel_migration') {
|
|
546
|
+
refresh = await this.confirmMigrationAction(migration, action === '__start_migration' ? 'start' : 'cancel');
|
|
547
|
+
}
|
|
548
|
+
if (refresh) {
|
|
549
|
+
// The details only show this migration and its databases
|
|
550
|
+
await this.getMigrationTargetsAndInfo(this.advancedDatabases.filter(db => db.id === migration.target_id), this.classicDatabases.filter(db => db.id === migration.source_id));
|
|
551
|
+
}
|
|
552
|
+
} while (action !== '__go_back');
|
|
553
|
+
}
|
|
554
|
+
methodLabel(migration) {
|
|
555
|
+
return migration.migration_strategy ? migrationMethodLabels[migration.migration_strategy] : undefined;
|
|
556
|
+
}
|
|
557
|
+
printMigrationDetails(migration) {
|
|
558
|
+
const sourceDatabase = this.classicDatabases.find(db => db.id === migration.source_id);
|
|
559
|
+
const targetDatabase = this.advancedDatabases.find(db => db.id === migration.target_id);
|
|
560
|
+
// Details without a value are omitted
|
|
561
|
+
/* eslint-disable perfectionist/sort-objects */
|
|
562
|
+
const details = {
|
|
563
|
+
Source: this.databaseDetails(sourceDatabase, sourceDatabase?.version, sourceDatabase?.status),
|
|
564
|
+
Destination: this.databaseDetails(targetDatabase, targetDatabase?.info?.version, hux.toTitleCase(targetDatabase?.info?.status)),
|
|
565
|
+
Method: this.methodLabel(migration),
|
|
566
|
+
'Configured at': migration.created_at ? renderTimestamp(migration.created_at) : undefined,
|
|
567
|
+
Status: migration.status_description,
|
|
568
|
+
};
|
|
569
|
+
/* eslint-enable perfectionist/sort-objects */
|
|
570
|
+
ux.stdout();
|
|
571
|
+
hux.styledHeader('Migration Details');
|
|
572
|
+
hux.styledObject(details);
|
|
573
|
+
ux.stdout();
|
|
574
|
+
}
|
|
575
|
+
printVersionChangeWarning(sourceVersion, targetVersion) {
|
|
576
|
+
const sourceMajorVersion = Number(this.majorVersion(sourceVersion));
|
|
577
|
+
const targetMajorVersion = Number(this.majorVersion(targetVersion));
|
|
578
|
+
// Only upgrades: the API rejects migrations to an older major version
|
|
579
|
+
if (!sourceMajorVersion || !targetMajorVersion || targetMajorVersion <= sourceMajorVersion) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
ux.stdout(color.warning(heredoc `
|
|
583
|
+
Warning: The destination database runs Postgres ${targetVersion}, but the source database runs Postgres ${sourceVersion}. Migrating the database also upgrades the Postgres version.
|
|
584
|
+
|
|
585
|
+
`));
|
|
586
|
+
}
|
|
587
|
+
async refreshDatabasesAndMigrations() {
|
|
588
|
+
await this.getAppDatabases(this.appName);
|
|
589
|
+
// Drops the migrations of databases that are no longer on the app
|
|
590
|
+
this.migrationTargets = [];
|
|
591
|
+
await this.getMigrationTargetsAndInfo();
|
|
592
|
+
}
|
|
593
|
+
versionLabel(version) {
|
|
594
|
+
return version ? ` ${color.gray(`v${version}`)}` : '';
|
|
595
|
+
}
|
|
513
596
|
}
|