@revoengine/cli 1.0.11 → 1.0.13

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 (81) hide show
  1. package/README.md +275 -479
  2. package/dist/src/cli.js +71 -5
  3. package/dist/src/client.d.ts +28 -12
  4. package/dist/src/client.js +234 -66
  5. package/dist/src/commands/component.d.ts +67 -0
  6. package/dist/src/commands/component.js +299 -27
  7. package/dist/src/commands/database-tables.d.ts +2 -0
  8. package/dist/src/commands/{database-schemas.js → database-tables.js} +21 -40
  9. package/dist/src/commands/database-views.js +21 -18
  10. package/dist/src/commands/endpoints.js +26 -16
  11. package/dist/src/commands/events.js +18 -20
  12. package/dist/src/commands/groups.js +13 -22
  13. package/dist/src/commands/index.d.ts +2 -1
  14. package/dist/src/commands/index.js +2 -1
  15. package/dist/src/commands/job-templates.js +21 -15
  16. package/dist/src/commands/metadata.js +58 -15
  17. package/dist/src/commands/migrate.d.ts +6 -0
  18. package/dist/src/commands/migrate.js +658 -0
  19. package/dist/src/commands/project.js +4 -4
  20. package/dist/src/commands/role-groups.js +14 -25
  21. package/dist/src/commands/schedules.js +19 -20
  22. package/dist/src/commands/terminal-browser.d.ts +16 -0
  23. package/dist/src/commands/terminal-browser.js +92 -0
  24. package/dist/src/commands/terminal-image.d.ts +7 -0
  25. package/dist/src/commands/terminal-image.js +40 -0
  26. package/dist/src/commands/terminal-patch-worker.d.ts +1 -0
  27. package/dist/src/commands/terminal-patch-worker.js +24 -0
  28. package/dist/src/commands/terminal-patch.d.ts +2 -0
  29. package/dist/src/commands/terminal-patch.js +156 -0
  30. package/dist/src/commands/terminal-sandbox.d.ts +8 -0
  31. package/dist/src/commands/terminal-sandbox.js +87 -0
  32. package/dist/src/commands/terminal-service.js +2 -2
  33. package/dist/src/commands/terminal.d.ts +31 -4
  34. package/dist/src/commands/terminal.js +360 -45
  35. package/dist/src/component-lock.d.ts +12 -2
  36. package/dist/src/component-lock.js +60 -1
  37. package/dist/src/diff-details.d.ts +8 -0
  38. package/dist/src/diff-details.js +152 -0
  39. package/dist/src/env-sync.js +8 -6
  40. package/dist/src/http-trace.d.ts +94 -0
  41. package/dist/src/http-trace.js +226 -0
  42. package/dist/src/metadata-backfill.d.ts +5 -4
  43. package/dist/src/metadata-backfill.js +82 -158
  44. package/dist/src/migration.d.ts +141 -0
  45. package/dist/src/migration.js +1632 -0
  46. package/dist/src/resource-inventory.d.ts +28 -0
  47. package/dist/src/resource-inventory.js +85 -0
  48. package/dist/src/resource-syncs/{database-schema-sync.d.ts → database-table-sync.d.ts} +13 -3
  49. package/dist/src/resource-syncs/{database-schema-sync.js → database-table-sync.js} +147 -62
  50. package/dist/src/resource-syncs/database-view-sync.d.ts +24 -2
  51. package/dist/src/resource-syncs/database-view-sync.js +156 -68
  52. package/dist/src/resource-syncs/endpoint-sync.d.ts +27 -0
  53. package/dist/src/resource-syncs/endpoint-sync.js +362 -82
  54. package/dist/src/resource-syncs/event-sync.d.ts +27 -0
  55. package/dist/src/resource-syncs/event-sync.js +123 -26
  56. package/dist/src/resource-syncs/group-sync.d.ts +7 -0
  57. package/dist/src/resource-syncs/group-sync.js +60 -14
  58. package/dist/src/resource-syncs/job-template-sync.d.ts +21 -0
  59. package/dist/src/resource-syncs/job-template-sync.js +91 -30
  60. package/dist/src/resource-syncs/role-group-sync.d.ts +7 -0
  61. package/dist/src/resource-syncs/role-group-sync.js +47 -9
  62. package/dist/src/resource-syncs/schedule-sync.d.ts +30 -1
  63. package/dist/src/resource-syncs/schedule-sync.js +114 -20
  64. package/dist/src/resource-syncs/util.d.ts +3 -0
  65. package/dist/src/resource-syncs/util.js +8 -6
  66. package/dist/src/resource-target.d.ts +11 -0
  67. package/dist/src/resource-target.js +48 -0
  68. package/dist/src/sync-output.d.ts +29 -1
  69. package/dist/src/sync-output.js +139 -2
  70. package/dist/src/tracked-resources.d.ts +1 -1
  71. package/dist/src/tracked-resources.js +8 -6
  72. package/dist/src/types.d.ts +3 -0
  73. package/dist/src/ui.js +18 -9
  74. package/dist/src/utils.d.ts +2 -0
  75. package/dist/src/utils.js +17 -0
  76. package/dist/src/workspace-diff.d.ts +25 -0
  77. package/dist/src/workspace-diff.js +75 -0
  78. package/package.json +9 -6
  79. package/dist/src/commands/database-schemas.d.ts +0 -2
  80. /package/dist/src/{database-schema-artifacts.d.ts → database-table-artifacts.d.ts} +0 -0
  81. /package/dist/src/{database-schema-artifacts.js → database-table-artifacts.js} +0 -0
@@ -0,0 +1,1632 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { RevoClient } from "./client.js";
5
+ import { REVO_LOCK_FILE, readComponentLock } from "./component-lock.js";
6
+ import { withHttpTraceContext } from "./http-trace.js";
7
+ import { buildComponentPlan, pullAllComponents, pushAllComponents, } from "./commands/component.js";
8
+ import { resolveRuntimeConfig } from "./config.js";
9
+ import { REVO_METADATA_FILE, readProjectComponentIdentity, readProjectMetadata, readProjectStableKeyName, resolveProjectRoot, resolveProjectWorkspace, } from "./project.js";
10
+ import { DATABASE_SCHEMAS_DIRECTORY, buildDatabaseSchemasPlan, pullDatabaseSchemasToWorkspace, pushDatabaseSchemas, readWorkspaceDatabaseSchemas, } from "./resource-syncs/database-table-sync.js";
11
+ import { DATABASE_VIEWS_DIRECTORY, buildDatabaseViewsPlan, pullDatabaseViewsToWorkspace, pushDatabaseViews, readWorkspaceDatabaseViews, } from "./resource-syncs/database-view-sync.js";
12
+ import { ENDPOINTS_DIRECTORY, buildEndpointsPlan, pullEndpointsToWorkspace, pushEndpoints, } from "./resource-syncs/endpoint-sync.js";
13
+ import { EVENTS_DIRECTORY, buildEventsPlan, pullEventsToWorkspace, pushEvents, } from "./resource-syncs/event-sync.js";
14
+ import { GROUPS_DIRECTORY, buildGroupsPlan, pullGroupsToWorkspace, pushGroups, } from "./resource-syncs/group-sync.js";
15
+ import { JOB_TEMPLATES_DIRECTORY, buildJobTemplatesPlan, pullJobTemplatesToWorkspace, pushJobTemplates, } from "./resource-syncs/job-template-sync.js";
16
+ import { SCHEDULES_DIRECTORY, buildSchedulesPlan, pullSchedulesToWorkspace, pushSchedules, } from "./resource-syncs/schedule-sync.js";
17
+ import { ROLE_GROUPS_DIRECTORY, buildRoleGroupsPlan, pullRoleGroupsToWorkspace, pushRoleGroups, } from "./resource-syncs/role-group-sync.js";
18
+ const RESOURCE_ORDER = [
19
+ 'database-table',
20
+ 'database-view',
21
+ 'component',
22
+ 'job-template',
23
+ 'endpoint',
24
+ 'schedule',
25
+ 'event',
26
+ 'group',
27
+ 'role-group',
28
+ ];
29
+ const BLOCKING_SCHEMA_STATUSES = new Set([
30
+ 'collision',
31
+ 'manual-schema-migration-required',
32
+ 'access-policy-required',
33
+ 'previously-deleted-partition',
34
+ 'replacement-requires-two-phases',
35
+ ]);
36
+ function selectedResources(input) {
37
+ const requested = new Set(input.resources?.length ? input.resources : RESOURCE_ORDER);
38
+ return RESOURCE_ORDER.filter((resource) => requested.has(resource));
39
+ }
40
+ async function runMigrationStage(stage, resource, envName, operation) {
41
+ try {
42
+ return await withHttpTraceContext({
43
+ stage: stage.replace(' ', '-'),
44
+ resource,
45
+ environment: envName,
46
+ }, operation);
47
+ }
48
+ catch (error) {
49
+ const message = error instanceof Error ? error.message : String(error);
50
+ throw new Error(`Migration ${stage} failed for ${resource} in environment "${envName}": ${message}`, { cause: error });
51
+ }
52
+ }
53
+ function migrationPolicy(input) {
54
+ return {
55
+ sourceWins: true,
56
+ allowDestructive: input.allowDestructive === true,
57
+ };
58
+ }
59
+ function viewMigrationPolicy(input, deferPreview = false) {
60
+ return {
61
+ ...migrationPolicy(input),
62
+ allowActiveScheduleDependencies: true,
63
+ ...(deferPreview ? { deferPreview: true } : {}),
64
+ };
65
+ }
66
+ function emptyOperations() {
67
+ return { noop: 0, create: 0, update: 0, adopt: 0, excluded: 0, blocked: 0 };
68
+ }
69
+ function schemaItemAction(item) {
70
+ if (BLOCKING_SCHEMA_STATUSES.has(item.status)) {
71
+ return 'blocked';
72
+ }
73
+ if (item.status === 'create') {
74
+ return 'create';
75
+ }
76
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
77
+ return 'update';
78
+ }
79
+ if (item.status === 'missing-lock') {
80
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
81
+ }
82
+ if (item.status === 'reconciled') {
83
+ return 'adopt';
84
+ }
85
+ if (item.status === 'orphan-root'
86
+ || item.status === 'orphan-partition'
87
+ || item.status === 'delete-partition'
88
+ || item.status === 'unmanaged') {
89
+ return 'excluded';
90
+ }
91
+ return 'noop';
92
+ }
93
+ function viewItemIsBlocked(item) {
94
+ return item.status === 'collision'
95
+ || item.status === 'validation-failed'
96
+ || (item.status === 'conflict' && Boolean(item.reason));
97
+ }
98
+ function viewItemAction(item) {
99
+ if (viewItemIsBlocked(item)) {
100
+ return 'blocked';
101
+ }
102
+ if (item.status === 'create') {
103
+ return 'create';
104
+ }
105
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
106
+ return 'update';
107
+ }
108
+ if (item.status === 'missing-lock') {
109
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
110
+ }
111
+ if (item.status === 'orphan' || item.status === 'skipped') {
112
+ return 'excluded';
113
+ }
114
+ return 'noop';
115
+ }
116
+ function componentItemAction(item) {
117
+ if (item.blocked === true || item.status === 'blocked') {
118
+ return 'blocked';
119
+ }
120
+ if (item.status === 'clean'
121
+ && item.lockHash === null
122
+ && item.localHash !== null
123
+ && item.localHash === item.remoteHash) {
124
+ return 'adopt';
125
+ }
126
+ if (item.status === 'create') {
127
+ return 'create';
128
+ }
129
+ if (item.status === 'local-changed'
130
+ || item.status === 'remote-changed'
131
+ || item.status === 'conflict'
132
+ || item.status === 'missing-lock') {
133
+ return 'update';
134
+ }
135
+ if (item.status === 'safe-update') {
136
+ return 'excluded';
137
+ }
138
+ return 'noop';
139
+ }
140
+ function jobTemplateItemAction(item) {
141
+ if (item.status === 'collision' || (item.status === 'conflict' && !item.desiredHash)) {
142
+ return 'blocked';
143
+ }
144
+ if (item.status === 'create') {
145
+ return 'create';
146
+ }
147
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
148
+ return 'update';
149
+ }
150
+ if (item.status === 'missing-lock') {
151
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
152
+ }
153
+ if (item.status === 'orphan' || item.status === 'skipped') {
154
+ return 'excluded';
155
+ }
156
+ return 'noop';
157
+ }
158
+ function endpointItemAction(item) {
159
+ if (item.status === 'restore-blocked' || item.status === 'collision') {
160
+ return 'blocked';
161
+ }
162
+ if (item.status === 'create') {
163
+ return 'create';
164
+ }
165
+ if (item.status === 'restore' || item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
166
+ return 'update';
167
+ }
168
+ if (item.status === 'missing-lock') {
169
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
170
+ }
171
+ if (item.status === 'orphan' || item.status === 'skipped') {
172
+ return 'excluded';
173
+ }
174
+ return 'noop';
175
+ }
176
+ function scheduleItemAction(item) {
177
+ if (item.blocked === true || item.status === 'collision') {
178
+ return 'blocked';
179
+ }
180
+ if (item.status === 'create') {
181
+ return 'create';
182
+ }
183
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
184
+ return 'update';
185
+ }
186
+ if (item.status === 'missing-lock') {
187
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
188
+ }
189
+ if (item.status === 'orphan' || item.status === 'skipped') {
190
+ return 'excluded';
191
+ }
192
+ return 'noop';
193
+ }
194
+ function eventItemAction(item) {
195
+ if (item.blocked === true || item.status === 'collision') {
196
+ return 'blocked';
197
+ }
198
+ if (item.status === 'create') {
199
+ return 'create';
200
+ }
201
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
202
+ return 'update';
203
+ }
204
+ if (item.status === 'missing-lock') {
205
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
206
+ }
207
+ if (item.status === 'orphan' || item.status === 'skipped' || item.status === 'activation-drift') {
208
+ return 'excluded';
209
+ }
210
+ return 'noop';
211
+ }
212
+ function groupItemAction(item) {
213
+ if (item.status === 'collision'
214
+ || ((item.status === 'conflict' || item.status === 'missing-lock') && !item.currentHash)) {
215
+ return 'blocked';
216
+ }
217
+ if (item.status === 'create') {
218
+ return 'create';
219
+ }
220
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
221
+ return 'update';
222
+ }
223
+ if (item.status === 'missing-lock') {
224
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
225
+ }
226
+ if (item.status === 'manual-owner' || item.status === 'orphan' || item.status === 'skipped') {
227
+ return 'excluded';
228
+ }
229
+ return 'noop';
230
+ }
231
+ function roleGroupItemAction(item) {
232
+ if (item.status === 'collision' || (item.status === 'conflict' && !item.currentHash)) {
233
+ return 'blocked';
234
+ }
235
+ if (item.status === 'create') {
236
+ return 'create';
237
+ }
238
+ if (item.status === 'safe-update' || item.status === 'remote-changed' || item.status === 'conflict') {
239
+ return 'update';
240
+ }
241
+ if (item.status === 'missing-lock') {
242
+ return item.desiredHash === item.currentHash ? 'adopt' : 'update';
243
+ }
244
+ if (item.status === 'orphan' || item.status === 'skipped') {
245
+ return 'excluded';
246
+ }
247
+ return 'noop';
248
+ }
249
+ function phaseVerdict(blockers, warnings) {
250
+ if (blockers.length > 0) {
251
+ return 'blocked';
252
+ }
253
+ return warnings.length > 0 ? 'ready-with-warnings' : 'ready';
254
+ }
255
+ function summarizeSchemaPhase(plan) {
256
+ const operations = emptyOperations();
257
+ for (const item of plan.items) {
258
+ operations[schemaItemAction(item)] += 1;
259
+ }
260
+ const itemBlockers = plan.items
261
+ .filter((item) => BLOCKING_SCHEMA_STATUSES.has(item.status) && Boolean(item.desiredHash))
262
+ .map((item) => `Database Table "${item.stableKey || item.name}" is blocked: ${item.reason || item.status}.`);
263
+ const blockers = [...new Set([...plan.blockers, ...itemBlockers])];
264
+ const warnings = [...new Set([
265
+ ...plan.warnings,
266
+ ...plan.exclusions.map((exclusion) => `Excluded: ${exclusion}.`),
267
+ ])];
268
+ return {
269
+ order: 1,
270
+ resource: 'database-table',
271
+ needsChanges: operations.create + operations.update > 0,
272
+ readyToMigrate: blockers.length === 0,
273
+ verdict: phaseVerdict(blockers, warnings),
274
+ operations,
275
+ warnings,
276
+ blockers,
277
+ };
278
+ }
279
+ function summarizeViewPhase(plan) {
280
+ const operations = emptyOperations();
281
+ for (const item of plan.items) {
282
+ operations[viewItemAction(item)] += 1;
283
+ }
284
+ const itemBlockers = plan.items.flatMap((item) => {
285
+ const identity = item.stableKey || item.name;
286
+ const blockers = [];
287
+ if (viewItemIsBlocked(item)) {
288
+ blockers.push(`Database View "${identity}" is blocked: ${item.reason || item.status}.`);
289
+ }
290
+ return blockers;
291
+ });
292
+ const blockers = [...new Set([...plan.blockers, ...plan.globalBlockers, ...itemBlockers])];
293
+ const warnings = [...new Set([
294
+ ...plan.warnings,
295
+ ...plan.exclusions.map((exclusion) => `Excluded: ${exclusion}`),
296
+ ...plan.items.flatMap((item) => item.risks || []),
297
+ ...plan.items
298
+ .filter((item) => Boolean(item.scheduleDependencies?.length))
299
+ .map((item) => `Database View "${item.stableKey || item.name}" has active refresh Schedule dependencies (${item.scheduleDependencies?.join(', ')}); source-wins migration will continue and verify the view afterward.`),
300
+ ...plan.items
301
+ .filter((item) => item.status === 'create' && Boolean(item.desiredHash))
302
+ .map((item) => `Database View "${item.stableKey || item.name}" will be created private; target-local ACL assignment is deferred.`),
303
+ ])];
304
+ return {
305
+ order: 2,
306
+ resource: 'database-view',
307
+ needsChanges: operations.create + operations.update > 0,
308
+ readyToMigrate: blockers.length === 0,
309
+ verdict: phaseVerdict(blockers, warnings),
310
+ operations,
311
+ warnings,
312
+ blockers,
313
+ };
314
+ }
315
+ function summarizeComponentPhase(plan) {
316
+ const operations = emptyOperations();
317
+ for (const item of plan.items) {
318
+ operations[componentItemAction(item)] += 1;
319
+ }
320
+ const warnings = [...new Set([
321
+ ...(plan.unmanaged.local > 0
322
+ ? [`${plan.unmanaged.local} local Component(s) have no Stable Key and remain unmanaged.`]
323
+ : []),
324
+ ...(plan.unmanaged.remote > 0
325
+ ? [`${plan.unmanaged.remote} target Component(s) have no Stable Key and remain unmanaged.`]
326
+ : []),
327
+ ...plan.items
328
+ .filter((item) => item.status === 'safe-update')
329
+ .map((item) => `Target-only Component "${item.stableKey || item.componentName}" is outside source-wins upsert scope and will be preserved.`),
330
+ ...plan.items
331
+ .filter((item) => item.status === 'remote-changed' || item.status === 'conflict')
332
+ .map((item) => `Component "${item.stableKey || item.componentName}" has target drift; source-wins migration will overwrite its portable definition.`),
333
+ ...plan.items
334
+ .filter((item) => item.status === 'missing-lock')
335
+ .map((item) => `Component "${item.stableKey || item.componentName}" has no target lock baseline; source-wins migration will align and verify it.`),
336
+ ])];
337
+ const blockers = [...new Set(plan.blockers)];
338
+ return {
339
+ order: 3,
340
+ resource: 'component',
341
+ needsChanges: operations.create + operations.update > 0,
342
+ readyToMigrate: blockers.length === 0,
343
+ verdict: phaseVerdict(blockers, warnings),
344
+ operations,
345
+ warnings,
346
+ blockers,
347
+ };
348
+ }
349
+ function summarizeJobTemplatePhase(plan) {
350
+ const operations = emptyOperations();
351
+ for (const item of plan.items) {
352
+ operations[jobTemplateItemAction(item)] += 1;
353
+ }
354
+ const warnings = [...new Set([
355
+ ...plan.warnings,
356
+ ...plan.exclusions.map((exclusion) => `Excluded: ${exclusion}.`),
357
+ ...plan.items
358
+ .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && Boolean(item.desiredHash)))
359
+ .map((item) => `Job Template "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
360
+ ...plan.items
361
+ .filter((item) => item.status === 'missing-lock')
362
+ .map((item) => `Job Template "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
363
+ ])];
364
+ const blockers = [...new Set(plan.blockers)];
365
+ return {
366
+ order: 4,
367
+ resource: 'job-template',
368
+ needsChanges: operations.create + operations.update > 0,
369
+ readyToMigrate: blockers.length === 0,
370
+ verdict: phaseVerdict(blockers, warnings),
371
+ operations,
372
+ warnings,
373
+ blockers,
374
+ };
375
+ }
376
+ function summarizeEndpointPhase(plan) {
377
+ const operations = emptyOperations();
378
+ for (const item of plan.items) {
379
+ operations[endpointItemAction(item)] += 1;
380
+ }
381
+ const warnings = [...new Set([
382
+ ...plan.warnings,
383
+ ...plan.exclusions.map((exclusion) => `Excluded: ${exclusion}.`),
384
+ ...plan.items
385
+ .filter((item) => item.status === 'remote-changed' || item.status === 'conflict')
386
+ .map((item) => `Endpoint "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
387
+ ...plan.items
388
+ .filter((item) => item.status === 'missing-lock')
389
+ .map((item) => `Endpoint "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
390
+ ])];
391
+ const blockers = [...new Set(plan.blockers)];
392
+ return {
393
+ order: 5,
394
+ resource: 'endpoint',
395
+ needsChanges: operations.create + operations.update > 0,
396
+ readyToMigrate: blockers.length === 0,
397
+ verdict: phaseVerdict(blockers, warnings),
398
+ operations,
399
+ warnings,
400
+ blockers,
401
+ };
402
+ }
403
+ function summarizeSchedulePhase(plan) {
404
+ const operations = emptyOperations();
405
+ for (const item of plan.items) {
406
+ operations[scheduleItemAction(item)] += 1;
407
+ }
408
+ const warnings = [...new Set([
409
+ ...plan.warnings,
410
+ ...plan.exclusions.map((exclusion) => `Excluded: ${exclusion}.`),
411
+ ...plan.items
412
+ .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && item.blocked !== true))
413
+ .map((item) => `Schedule "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
414
+ ...plan.items
415
+ .filter((item) => item.status === 'missing-lock')
416
+ .map((item) => `Schedule "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
417
+ ])];
418
+ const blockers = [...new Set(plan.blockers)];
419
+ return {
420
+ order: 6,
421
+ resource: 'schedule',
422
+ needsChanges: operations.create + operations.update > 0,
423
+ readyToMigrate: blockers.length === 0,
424
+ verdict: phaseVerdict(blockers, warnings),
425
+ operations,
426
+ warnings,
427
+ blockers,
428
+ };
429
+ }
430
+ function summarizeEventPhase(plan) {
431
+ const operations = emptyOperations();
432
+ for (const item of plan.items) {
433
+ operations[eventItemAction(item)] += 1;
434
+ }
435
+ const warnings = [...new Set([
436
+ ...plan.warnings,
437
+ ...plan.exclusions.map((exclusion) => `Excluded: ${exclusion}.`),
438
+ ...plan.items
439
+ .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && item.blocked !== true))
440
+ .map((item) => `Event "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
441
+ ...plan.items
442
+ .filter((item) => item.status === 'missing-lock')
443
+ .map((item) => `Event "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
444
+ ...plan.items
445
+ .filter((item) => item.status === 'activation-drift')
446
+ .map((item) => `Event "${item.stableKey || item.name}" has activation drift; migration syncs its portable configuration but keeps activation as an explicit operational step.`),
447
+ ])];
448
+ const blockers = [...new Set(plan.blockers)];
449
+ return {
450
+ order: 7,
451
+ resource: 'event',
452
+ needsChanges: operations.create + operations.update > 0,
453
+ readyToMigrate: blockers.length === 0,
454
+ verdict: phaseVerdict(blockers, warnings),
455
+ operations,
456
+ warnings,
457
+ blockers,
458
+ };
459
+ }
460
+ function summarizeGroupPhase(plan) {
461
+ const operations = emptyOperations();
462
+ for (const item of plan.items) {
463
+ operations[groupItemAction(item)] += 1;
464
+ }
465
+ const warnings = [...new Set([
466
+ ...plan.warnings,
467
+ ...plan.exclusions.map((exclusion) => `Excluded: ${exclusion}.`),
468
+ ...plan.items
469
+ .filter((item) => item.status === 'manual-owner')
470
+ .map((item) => `Group "${item.stableKey || item.name}" requires a target-local USER owner and remains excluded from automatic migration.`),
471
+ ...plan.items
472
+ .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && Boolean(item.currentHash)))
473
+ .map((item) => `Group "${item.stableKey || item.name}" has target drift; source-wins migration will overwrite its portable definition.`),
474
+ ...plan.items
475
+ .filter((item) => item.status === 'missing-lock' && Boolean(item.currentHash))
476
+ .map((item) => `Group "${item.stableKey || item.name}" has no target lock baseline; source-wins migration will align or adopt it.`),
477
+ ])];
478
+ const blockers = [...new Set(plan.blockers)];
479
+ return {
480
+ order: 8,
481
+ resource: 'group',
482
+ needsChanges: operations.create + operations.update > 0,
483
+ readyToMigrate: blockers.length === 0,
484
+ verdict: phaseVerdict(blockers, warnings),
485
+ operations,
486
+ warnings,
487
+ blockers,
488
+ };
489
+ }
490
+ function summarizeRoleGroupPhase(plan) {
491
+ const operations = emptyOperations();
492
+ for (const item of plan.items) {
493
+ operations[roleGroupItemAction(item)] += 1;
494
+ }
495
+ const warnings = [...new Set([
496
+ ...plan.exclusions.map((exclusion) => `Excluded: ${exclusion}.`),
497
+ ...plan.items
498
+ .filter((item) => item.status === 'create' || item.status === 'safe-update')
499
+ .map((item) => `Role Group "${item.stableKey || item.name}" changes target authorization and will be applied in the final migration phase.`),
500
+ ...plan.items
501
+ .filter((item) => item.status === 'remote-changed' || (item.status === 'conflict' && Boolean(item.currentHash)))
502
+ .map((item) => `Role Group "${item.stableKey || item.name}" has target drift; the final source-wins phase will overwrite its portable definition and role assignments.`),
503
+ ...plan.items
504
+ .filter((item) => item.status === 'missing-lock')
505
+ .map((item) => `Role Group "${item.stableKey || item.name}" has no target lock baseline; the final phase will align or adopt it.`),
506
+ ])];
507
+ const blockers = [...new Set(plan.blockers)];
508
+ return {
509
+ order: 9,
510
+ resource: 'role-group',
511
+ needsChanges: operations.create + operations.update > 0,
512
+ readyToMigrate: blockers.length === 0,
513
+ verdict: phaseVerdict(blockers, warnings),
514
+ operations,
515
+ warnings,
516
+ blockers,
517
+ };
518
+ }
519
+ function summarizePulls(mode, pulls) {
520
+ const byResource = {};
521
+ if (pulls.databaseSchemas) {
522
+ byResource['database-table'] = {
523
+ pulled: pulls.databaseSchemas.pulled.length,
524
+ pruned: pulls.databaseSchemas.pruned.length,
525
+ skipped: pulls.databaseSchemas.skipped.length,
526
+ };
527
+ }
528
+ if (pulls.databaseViews) {
529
+ byResource['database-view'] = {
530
+ pulled: pulls.databaseViews.pulled.length,
531
+ pruned: pulls.databaseViews.pruned.length,
532
+ skipped: pulls.databaseViews.skipped.length,
533
+ };
534
+ }
535
+ if (pulls.components) {
536
+ byResource.component = {
537
+ pulled: pulls.components.filter((item) => item.status === 'pulled').length,
538
+ pruned: pulls.components.filter((item) => item.status === 'pruned').length,
539
+ skipped: pulls.components.filter((item) => item.status === 'skipped').length,
540
+ };
541
+ }
542
+ if (pulls.jobTemplates) {
543
+ byResource['job-template'] = {
544
+ pulled: pulls.jobTemplates.pulled.length,
545
+ pruned: pulls.jobTemplates.pruned.length,
546
+ skipped: pulls.jobTemplates.skipped.length,
547
+ };
548
+ }
549
+ if (pulls.endpoints) {
550
+ byResource.endpoint = {
551
+ pulled: pulls.endpoints.pulled.length,
552
+ pruned: pulls.endpoints.pruned.length,
553
+ skipped: pulls.endpoints.skipped.length,
554
+ };
555
+ }
556
+ if (pulls.schedules) {
557
+ byResource.schedule = {
558
+ pulled: pulls.schedules.pulled.length,
559
+ pruned: pulls.schedules.pruned.length,
560
+ skipped: pulls.schedules.warnings.length,
561
+ };
562
+ }
563
+ if (pulls.events) {
564
+ byResource.event = {
565
+ pulled: pulls.events.pulled.length,
566
+ pruned: pulls.events.pruned.length,
567
+ skipped: pulls.events.warnings.length,
568
+ };
569
+ }
570
+ if (pulls.groups) {
571
+ byResource.group = {
572
+ pulled: pulls.groups.pulled.length,
573
+ pruned: pulls.groups.pruned.length,
574
+ skipped: pulls.groups.skipped.length,
575
+ };
576
+ }
577
+ if (pulls.roleGroups) {
578
+ byResource['role-group'] = {
579
+ pulled: pulls.roleGroups.pulled.length,
580
+ pruned: pulls.roleGroups.pruned.length,
581
+ skipped: pulls.roleGroups.skipped.length,
582
+ };
583
+ }
584
+ const totals = Object.values(byResource).reduce((result, value) => ({
585
+ pulled: result.pulled + value.pulled,
586
+ pruned: result.pruned + value.pruned,
587
+ skipped: result.skipped + value.skipped,
588
+ }), { pulled: 0, pruned: 0, skipped: 0 });
589
+ return { mode, ...totals, byResource };
590
+ }
591
+ function applyWorkspaceDeploymentPolicy(input, phase, plans) {
592
+ if (input.sourceMode !== 'workspace') {
593
+ return phase;
594
+ }
595
+ const gates = [];
596
+ const forceOperations = [];
597
+ if (phase.resource === 'database-table' && plans.databaseSchemas) {
598
+ for (const item of plans.databaseSchemas.items.filter((candidate) => candidate.status === 'delete-partition')) {
599
+ const operation = {
600
+ from: 'excluded',
601
+ message: `Database partition "${item.stableKey || item.name}" was previously managed and removed from the repository; deletion requires --force.`,
602
+ };
603
+ gates.push(operation);
604
+ forceOperations.push(operation);
605
+ }
606
+ }
607
+ if (phase.resource === 'schedule' && plans.schedules) {
608
+ for (const item of plans.schedules.items) {
609
+ const action = scheduleItemAction(item);
610
+ const targetTypeTransition = item.forceRequirement === 'schedule-target-type-transition';
611
+ if ((action === 'create' || action === 'update') && (item.databaseViewStableKey || targetTypeTransition)) {
612
+ gates.push({
613
+ from: action,
614
+ message: targetTypeTransition
615
+ ? `Schedule "${item.stableKey || item.name}" target type transition requires --force for repository deployment.`
616
+ : `Materialized View Schedule "${item.stableKey || item.name}" requires --force for repository deployment.`,
617
+ });
618
+ }
619
+ }
620
+ }
621
+ if (phase.resource === 'group' && plans.groups) {
622
+ for (const item of plans.groups.items) {
623
+ const action = groupItemAction(item);
624
+ if (action === 'create' || action === 'update') {
625
+ gates.push({
626
+ from: action,
627
+ message: `Group "${item.stableKey || item.name}" can change environment access and requires --force for repository deployment.`,
628
+ });
629
+ }
630
+ }
631
+ }
632
+ if (phase.resource === 'role-group' && plans.roleGroups) {
633
+ for (const item of plans.roleGroups.items) {
634
+ const action = roleGroupItemAction(item);
635
+ if (action === 'create' || action === 'update') {
636
+ gates.push({
637
+ from: action,
638
+ message: `Role Group "${item.stableKey || item.name}" can change environment authorization and requires --force for repository deployment.`,
639
+ });
640
+ }
641
+ }
642
+ }
643
+ const operations = { ...phase.operations };
644
+ if (input.allowDestructive === true) {
645
+ for (const operation of forceOperations) {
646
+ operations[operation.from] = Math.max(0, operations[operation.from] - 1);
647
+ operations.update += 1;
648
+ }
649
+ return {
650
+ ...phase,
651
+ operations,
652
+ needsChanges: phase.needsChanges || forceOperations.length > 0,
653
+ };
654
+ }
655
+ if (gates.length === 0) {
656
+ return phase;
657
+ }
658
+ for (const gate of gates) {
659
+ operations[gate.from] = Math.max(0, operations[gate.from] - 1);
660
+ operations.blocked += 1;
661
+ }
662
+ const blockers = [...new Set([...phase.blockers, ...gates.map((gate) => gate.message)])];
663
+ return {
664
+ ...phase,
665
+ operations,
666
+ needsChanges: true,
667
+ readyToMigrate: false,
668
+ verdict: phaseVerdict(blockers, phase.warnings),
669
+ blockers,
670
+ };
671
+ }
672
+ function combinePlan(input) {
673
+ const phases = [
674
+ ...(input.databaseSchemas ? [summarizeSchemaPhase(input.databaseSchemas)] : []),
675
+ ...(input.databaseViews ? [summarizeViewPhase(input.databaseViews)] : []),
676
+ ...(input.components ? [summarizeComponentPhase(input.components)] : []),
677
+ ...(input.jobTemplates ? [summarizeJobTemplatePhase(input.jobTemplates)] : []),
678
+ ...(input.endpoints ? [summarizeEndpointPhase(input.endpoints)] : []),
679
+ ...(input.schedules ? [summarizeSchedulePhase(input.schedules)] : []),
680
+ ...(input.events ? [summarizeEventPhase(input.events)] : []),
681
+ ...(input.groups ? [summarizeGroupPhase(input.groups)] : []),
682
+ ...(input.roleGroups ? [summarizeRoleGroupPhase(input.roleGroups)] : []),
683
+ ].map((phase) => applyWorkspaceDeploymentPolicy(input.migrationInput, phase, input))
684
+ .map((phase) => {
685
+ const pullWarnings = phase.resource === 'database-table'
686
+ ? (input.pulls.databaseSchemas?.skipped || []).map((item) => `Source Database Table skipped: ${item.targetPath}: ${item.reason}.`)
687
+ : phase.resource === 'database-view'
688
+ ? (input.pulls.databaseViews?.skipped || []).map((item) => `Source Database View "${item.stableKey || item.name}" skipped: ${item.reason}.`)
689
+ : phase.resource === 'component'
690
+ ? (input.pulls.components || [])
691
+ .filter((item) => item.status === 'skipped' && item.reason !== 'no changes')
692
+ .map((item) => `Source Component skipped: ${item.targetPath}: ${item.reason || 'unknown reason'}.`)
693
+ : phase.resource === 'job-template'
694
+ ? [
695
+ ...(input.pulls.jobTemplates?.skipped || [])
696
+ .map((item) => `Source Job Template "${item.name}" skipped: ${item.reason}.`),
697
+ ...(input.pulls.jobTemplates?.warnings || [])
698
+ .map((item) => `Source Job Template "${item.stableKey}": ${item.reason}.`),
699
+ ]
700
+ : phase.resource === 'endpoint'
701
+ ? (input.pulls.endpoints?.skipped || [])
702
+ .map((item) => `Source Endpoint skipped: ${item.targetPath}: ${item.reason}.`)
703
+ : phase.resource === 'schedule'
704
+ ? [
705
+ ...(input.pulls.schedules?.warnings || [])
706
+ .map((item) => `Source Schedule "${item.stableKey}": ${item.reason}.`),
707
+ ...(input.pulls.schedules?.pulled || [])
708
+ .filter(({ manifest }) => manifest.activationCandidate === true)
709
+ .map(({ manifest }) => `Source Schedule "${manifest.stableKey}" is an activation candidate; migration syncs its portable definition but does not automatically change target activation state.`),
710
+ ]
711
+ : phase.resource === 'event'
712
+ ? [
713
+ ...(input.pulls.events?.warnings || [])
714
+ .map((item) => `Source Event "${item.stableKey}": ${item.reason}.`),
715
+ ...(input.pulls.events?.pulled || [])
716
+ .filter(({ manifest }) => manifest.active === true)
717
+ .map(({ manifest }) => `Source Event "${manifest.stableKey}" is active; migration syncs its portable configuration but does not automatically change target activation state.`),
718
+ ]
719
+ : phase.resource === 'group'
720
+ ? [
721
+ ...(input.pulls.groups?.skipped || [])
722
+ .map((item) => `Source Group "${item.name}" skipped: ${item.reason}.`),
723
+ ...(input.pulls.groups?.notices || [])
724
+ .map((item) => `Source Group "${item.stableKey}": ${item.reason}.`),
725
+ ]
726
+ : (input.pulls.roleGroups?.skipped || [])
727
+ .map((item) => `Source Role Group "${item.name}" skipped: ${item.reason}.`);
728
+ const pruneWarnings = phase.resource === 'database-table'
729
+ ? (input.pulls.databaseSchemas?.pruned || []).map((item) => `Pruned stale source workspace Database Table "${item.stableKey}".`)
730
+ : phase.resource === 'database-view'
731
+ ? (input.pulls.databaseViews?.pruned || []).map((item) => `Pruned stale source workspace Database View "${item.stableKey}".`)
732
+ : phase.resource === 'component'
733
+ ? (input.pulls.components || [])
734
+ .filter((item) => item.status === 'pruned')
735
+ .map((item) => `Pruned stale source workspace Component at "${item.targetPath}".`)
736
+ : phase.resource === 'job-template'
737
+ ? (input.pulls.jobTemplates?.pruned || [])
738
+ .map((item) => `Pruned stale source workspace Job Template "${item.stableKey}".`)
739
+ : phase.resource === 'endpoint'
740
+ ? (input.pulls.endpoints?.pruned || [])
741
+ .map((item) => `Pruned stale source workspace Endpoint "${item.stableKey}".`)
742
+ : phase.resource === 'schedule'
743
+ ? (input.pulls.schedules?.pruned || [])
744
+ .map((item) => `Pruned stale source workspace Schedule "${item.stableKey}".`)
745
+ : phase.resource === 'event'
746
+ ? (input.pulls.events?.pruned || [])
747
+ .map((item) => `Pruned stale source workspace Event "${item.stableKey}".`)
748
+ : phase.resource === 'group'
749
+ ? (input.pulls.groups?.pruned || [])
750
+ .map((item) => `Pruned stale source workspace Group "${item.stableKey}".`)
751
+ : (input.pulls.roleGroups?.pruned || [])
752
+ .map((item) => `Pruned stale source workspace Role Group "${item.stableKey}".`);
753
+ const warnings = [...new Set([...phase.warnings, ...pullWarnings, ...pruneWarnings])];
754
+ return { ...phase, warnings, verdict: phaseVerdict(phase.blockers, warnings) };
755
+ });
756
+ const operations = emptyOperations();
757
+ for (const phase of phases) {
758
+ for (const key of Object.keys(operations)) {
759
+ operations[key] += phase.operations[key];
760
+ }
761
+ }
762
+ const warnings = [...new Set(phases.flatMap((phase) => phase.warnings))];
763
+ const blockers = [...new Set(phases.flatMap((phase) => phase.blockers))];
764
+ return {
765
+ schemaVersion: 2,
766
+ command: 'plan',
767
+ from: input.migrationInput.from,
768
+ to: input.migrationInput.to,
769
+ resources: selectedResources(input.migrationInput),
770
+ policy: { ...migrationPolicy(input.migrationInput), mode: 'upsert' },
771
+ needsChanges: phases.some((phase) => phase.needsChanges),
772
+ readyToMigrate: blockers.length === 0,
773
+ verdict: phaseVerdict(blockers, warnings),
774
+ operations,
775
+ sourcePull: summarizePulls(input.sourcePullMode, input.pulls),
776
+ phases,
777
+ ...(input.databaseSchemas ? { databaseSchemas: input.databaseSchemas } : {}),
778
+ ...(input.databaseViews ? { databaseViews: input.databaseViews } : {}),
779
+ ...(input.components ? { components: input.components } : {}),
780
+ ...(input.jobTemplates ? { jobTemplates: input.jobTemplates } : {}),
781
+ ...(input.endpoints ? { endpoints: input.endpoints } : {}),
782
+ ...(input.schedules ? { schedules: input.schedules } : {}),
783
+ ...(input.events ? { events: input.events } : {}),
784
+ ...(input.groups ? { groups: input.groups } : {}),
785
+ ...(input.roleGroups ? { roleGroups: input.roleGroups } : {}),
786
+ warnings,
787
+ blockers,
788
+ };
789
+ }
790
+ function requireProject(input) {
791
+ const projectRoot = resolveProjectRoot(input.cwd);
792
+ const workspaceRoot = resolveProjectWorkspace(input.cwd);
793
+ if (!projectRoot || !workspaceRoot) {
794
+ throw new Error('Migration requires a configured Revo project. Run `revo project <path>` first.');
795
+ }
796
+ return { projectRoot, workspaceRoot };
797
+ }
798
+ function createTemporaryProject(input) {
799
+ const { projectRoot, workspaceRoot } = requireProject(input);
800
+ const temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'revo-migrate-plan-'));
801
+ const temporaryProject = path.join(temporaryRoot, 'project');
802
+ fs.mkdirSync(path.join(temporaryProject, '.revoengine'), { recursive: true });
803
+ fs.copyFileSync(path.join(projectRoot, REVO_METADATA_FILE), path.join(temporaryProject, REVO_METADATA_FILE));
804
+ const lockPath = path.join(projectRoot, REVO_LOCK_FILE);
805
+ if (fs.existsSync(lockPath)) {
806
+ fs.copyFileSync(lockPath, path.join(temporaryProject, REVO_LOCK_FILE));
807
+ }
808
+ const temporaryWorkspace = path.resolve(temporaryProject, path.relative(projectRoot, workspaceRoot));
809
+ fs.mkdirSync(temporaryWorkspace, { recursive: true });
810
+ for (const directory of [
811
+ DATABASE_SCHEMAS_DIRECTORY,
812
+ DATABASE_VIEWS_DIRECTORY,
813
+ 'Components',
814
+ JOB_TEMPLATES_DIRECTORY,
815
+ ENDPOINTS_DIRECTORY,
816
+ SCHEDULES_DIRECTORY,
817
+ EVENTS_DIRECTORY,
818
+ GROUPS_DIRECTORY,
819
+ ROLE_GROUPS_DIRECTORY,
820
+ ]) {
821
+ const sourceDirectory = path.join(workspaceRoot, directory);
822
+ if (fs.existsSync(sourceDirectory)) {
823
+ fs.cpSync(sourceDirectory, path.join(temporaryWorkspace, directory), { recursive: true, dereference: false });
824
+ }
825
+ }
826
+ return { temporaryRoot, temporaryProject };
827
+ }
828
+ function createEnvironmentClient(envName) {
829
+ return new RevoClient({
830
+ ...resolveRuntimeConfig({ envName }),
831
+ environmentName: envName,
832
+ });
833
+ }
834
+ function resolveTargetClient(input) {
835
+ return input.targetClient || createEnvironmentClient(input.to);
836
+ }
837
+ function targetKey(input) {
838
+ return input.targetKey || input.to;
839
+ }
840
+ function componentTargetEnvironment(input) {
841
+ return input.sourceMode === 'workspace' ? undefined : targetKey(input);
842
+ }
843
+ function targetLabel(input) {
844
+ return input.targetLabel || input.to;
845
+ }
846
+ function workspaceDesiredPulls(input) {
847
+ const resources = selectedResources(input);
848
+ const stableKeyName = readProjectStableKeyName(input.cwd);
849
+ return {
850
+ ...(resources.includes('database-table') ? {
851
+ databaseSchemas: {
852
+ pulled: readWorkspaceDatabaseSchemas(input.cwd, stableKeyName),
853
+ pruned: [],
854
+ skipped: [],
855
+ diagnostics: [],
856
+ },
857
+ } : {}),
858
+ ...(resources.includes('database-view') ? {
859
+ databaseViews: {
860
+ pulled: readWorkspaceDatabaseViews(input.cwd).map(({ manifest, manifestPath }) => ({
861
+ manifest,
862
+ targetPath: path.relative(input.cwd, manifestPath),
863
+ })),
864
+ pruned: [],
865
+ skipped: [],
866
+ },
867
+ } : {}),
868
+ };
869
+ }
870
+ function componentCommandContext(input) {
871
+ return {
872
+ args: { _: ['component', input.operation], all: true, force: true, yes: true },
873
+ client: input.client,
874
+ componentEnvironment: input.envName,
875
+ cwd: input.cwd,
876
+ packageVersion: 'migration',
877
+ print: () => undefined,
878
+ println: () => undefined,
879
+ error: () => undefined,
880
+ };
881
+ }
882
+ function requireStableComponentIdentity(cwd) {
883
+ const projectRoot = resolveProjectRoot(cwd) || cwd;
884
+ const identity = readProjectMetadata(cwd)
885
+ ? readProjectComponentIdentity(cwd)
886
+ : readComponentLock(projectRoot).componentIdentity;
887
+ if (identity.mode !== 'stableKey') {
888
+ throw new Error('Component migration requires componentIdentity.mode "stableKey" in project metadata or the shared lock.');
889
+ }
890
+ }
891
+ export async function pullResourcesToWorkspace(input) {
892
+ requireProject(input);
893
+ const resources = selectedResources(input);
894
+ const client = input.client;
895
+ const stableKeyName = readProjectStableKeyName(input.cwd);
896
+ const pulls = {};
897
+ if (resources.includes('database-table')) {
898
+ pulls.databaseSchemas = await runMigrationStage('source pull', 'database-table', input.sourceLabel, () => pullDatabaseSchemasToWorkspace({
899
+ client,
900
+ cwd: input.cwd,
901
+ envName: input.sourceKey,
902
+ stableKeyName,
903
+ force: input.force === true,
904
+ pruneOrphans: input.pruneOrphans === true,
905
+ }));
906
+ }
907
+ if (resources.includes('database-view')) {
908
+ pulls.databaseViews = await runMigrationStage('source pull', 'database-view', input.sourceLabel, () => pullDatabaseViewsToWorkspace({
909
+ client,
910
+ cwd: input.cwd,
911
+ envName: input.sourceKey,
912
+ stableKeyName,
913
+ force: input.force === true,
914
+ pruneOrphans: input.pruneOrphans === true,
915
+ }));
916
+ }
917
+ if (resources.includes('component')) {
918
+ requireStableComponentIdentity(input.cwd);
919
+ pulls.components = await runMigrationStage('source pull', 'component', input.sourceLabel, () => pullAllComponents(componentCommandContext({
920
+ cwd: input.cwd,
921
+ envName: input.sourceKey,
922
+ client,
923
+ operation: 'pull',
924
+ }), {
925
+ force: input.force === true,
926
+ stale: input.force === true,
927
+ yes: true,
928
+ pruneOrphans: input.pruneOrphans === true,
929
+ }));
930
+ }
931
+ if (resources.includes('job-template')) {
932
+ pulls.jobTemplates = await runMigrationStage('source pull', 'job-template', input.sourceLabel, () => pullJobTemplatesToWorkspace({
933
+ client,
934
+ cwd: input.cwd,
935
+ envName: input.sourceKey,
936
+ stableKeyName,
937
+ force: input.force === true,
938
+ pruneOrphans: input.pruneOrphans === true,
939
+ }));
940
+ }
941
+ if (resources.includes('endpoint')) {
942
+ pulls.endpoints = await runMigrationStage('source pull', 'endpoint', input.sourceLabel, () => pullEndpointsToWorkspace({
943
+ client,
944
+ cwd: input.cwd,
945
+ envName: input.sourceKey,
946
+ stableKeyName,
947
+ force: input.force === true,
948
+ pruneOrphans: input.pruneOrphans === true,
949
+ }));
950
+ }
951
+ if (resources.includes('schedule')) {
952
+ pulls.schedules = await runMigrationStage('source pull', 'schedule', input.sourceLabel, () => pullSchedulesToWorkspace({
953
+ client,
954
+ cwd: input.cwd,
955
+ envName: input.sourceKey,
956
+ stableKeyName,
957
+ force: input.force === true,
958
+ pruneOrphans: input.pruneOrphans === true,
959
+ }));
960
+ }
961
+ if (resources.includes('event')) {
962
+ pulls.events = await runMigrationStage('source pull', 'event', input.sourceLabel, () => pullEventsToWorkspace({
963
+ client,
964
+ cwd: input.cwd,
965
+ envName: input.sourceKey,
966
+ stableKeyName,
967
+ force: input.force === true,
968
+ pruneOrphans: input.pruneOrphans === true,
969
+ }));
970
+ }
971
+ if (resources.includes('group')) {
972
+ pulls.groups = await runMigrationStage('source pull', 'group', input.sourceLabel, () => pullGroupsToWorkspace({
973
+ client,
974
+ cwd: input.cwd,
975
+ envName: input.sourceKey,
976
+ stableKeyName,
977
+ force: input.force === true,
978
+ pruneOrphans: input.pruneOrphans === true,
979
+ }));
980
+ }
981
+ if (resources.includes('role-group')) {
982
+ pulls.roleGroups = await runMigrationStage('source pull', 'role-group', input.sourceLabel, () => pullRoleGroupsToWorkspace({
983
+ client,
984
+ cwd: input.cwd,
985
+ envName: input.sourceKey,
986
+ stableKeyName,
987
+ force: input.force === true,
988
+ pruneOrphans: input.pruneOrphans === true,
989
+ }));
990
+ }
991
+ return {
992
+ schemaVersion: 1,
993
+ command: 'pull',
994
+ source: input.sourceLabel,
995
+ sourceKey: input.sourceKey,
996
+ resources,
997
+ summary: summarizePulls('workspace', pulls),
998
+ results: pulls,
999
+ };
1000
+ }
1001
+ async function pullSelectedResources(input) {
1002
+ return (await pullResourcesToWorkspace({
1003
+ cwd: input.cwd,
1004
+ client: createEnvironmentClient(input.from),
1005
+ sourceKey: input.from,
1006
+ sourceLabel: input.from,
1007
+ resources: selectedResources(input),
1008
+ force: true,
1009
+ pruneOrphans: true,
1010
+ })).results;
1011
+ }
1012
+ function projectedComponentDependencies(plan) {
1013
+ return plan.items.flatMap((item) => {
1014
+ if (!item.stableKey || !item.localHash || item.status === 'safe-update' || item.blocked === true) {
1015
+ return [];
1016
+ }
1017
+ const action = componentItemAction(item);
1018
+ const state = action === 'create'
1019
+ ? 'pending-create'
1020
+ : action === 'update'
1021
+ ? 'pending-update'
1022
+ : action === 'adopt'
1023
+ ? 'pending-adopt'
1024
+ : 'ready';
1025
+ return [{ stableKey: item.stableKey, desiredHash: item.localHash, state }];
1026
+ });
1027
+ }
1028
+ function projectedDependencyState(action) {
1029
+ if (action === 'create') {
1030
+ return 'pending-create';
1031
+ }
1032
+ if (action === 'update') {
1033
+ return 'pending-update';
1034
+ }
1035
+ if (action === 'adopt') {
1036
+ return 'pending-adopt';
1037
+ }
1038
+ if (action === 'noop') {
1039
+ return 'ready';
1040
+ }
1041
+ return undefined;
1042
+ }
1043
+ function projectedJobTemplateDependencies(plan) {
1044
+ return plan.items.flatMap((item) => {
1045
+ if (!item.stableKey || !item.desiredHash) {
1046
+ return [];
1047
+ }
1048
+ const state = projectedDependencyState(jobTemplateItemAction(item));
1049
+ if (!state) {
1050
+ return [];
1051
+ }
1052
+ return [{
1053
+ stableKey: item.stableKey,
1054
+ desiredHash: item.desiredHash,
1055
+ actualHash: item.currentHash || null,
1056
+ state,
1057
+ }];
1058
+ });
1059
+ }
1060
+ function projectedDatabaseViewDependencies(plan, pull) {
1061
+ const manifestByStableKey = new Map(pull.pulled.map(({ manifest }) => [manifest.stableKey, manifest]));
1062
+ return plan.items.flatMap((item) => {
1063
+ if (!item.stableKey || !item.desiredHash) {
1064
+ return [];
1065
+ }
1066
+ const state = projectedDependencyState(viewItemAction(item));
1067
+ const manifest = manifestByStableKey.get(item.stableKey);
1068
+ if (!state || !manifest) {
1069
+ return [];
1070
+ }
1071
+ return [{
1072
+ stableKey: item.stableKey,
1073
+ desiredHash: item.desiredHash,
1074
+ actualHash: item.currentHash || null,
1075
+ state,
1076
+ viewType: manifest.type,
1077
+ }];
1078
+ });
1079
+ }
1080
+ function projectedDatabaseRecords(pull) {
1081
+ return pull.pulled.map(({ manifest }, index) => ({
1082
+ databaseId: `migration-projection-${index}`,
1083
+ name: manifest.name,
1084
+ category: manifest.category,
1085
+ desc: manifest.description,
1086
+ metadata: manifest.metadata,
1087
+ type: manifest.type,
1088
+ definition: manifest.definition,
1089
+ partition: manifest.partition,
1090
+ }));
1091
+ }
1092
+ async function planWorkspace(input) {
1093
+ const resources = selectedResources(input);
1094
+ const stableKeyName = readProjectStableKeyName(input.cwd);
1095
+ const client = resolveTargetClient(input);
1096
+ const environmentKey = targetKey(input);
1097
+ const environmentLabel = targetLabel(input);
1098
+ const databaseSchemas = resources.includes('database-table')
1099
+ ? await runMigrationStage('target plan', 'database-table', environmentLabel, () => buildDatabaseSchemasPlan({
1100
+ client,
1101
+ cwd: input.cwd,
1102
+ envName: environmentKey,
1103
+ stableKeyName,
1104
+ withStats: input.withStats,
1105
+ migrationPolicy: migrationPolicy(input),
1106
+ }))
1107
+ : undefined;
1108
+ const schemaPhase = databaseSchemas
1109
+ ? applyWorkspaceDeploymentPolicy(input, summarizeSchemaPhase(databaseSchemas), { databaseSchemas })
1110
+ : undefined;
1111
+ const deferViewPreview = input.projectDependencies === true
1112
+ && Boolean(input.pulls.databaseSchemas)
1113
+ && schemaPhase?.needsChanges === true;
1114
+ const databaseViews = resources.includes('database-view')
1115
+ ? await runMigrationStage('target plan', 'database-view', environmentLabel, () => buildDatabaseViewsPlan({
1116
+ client,
1117
+ cwd: input.cwd,
1118
+ envName: environmentKey,
1119
+ stableKeyName,
1120
+ migrationPolicy: viewMigrationPolicy(input, deferViewPreview),
1121
+ ...(input.projectDependencies === true && input.pulls.databaseSchemas
1122
+ ? { dependencyDatabases: projectedDatabaseRecords(input.pulls.databaseSchemas) }
1123
+ : {}),
1124
+ }))
1125
+ : undefined;
1126
+ const components = resources.includes('component')
1127
+ ? await runMigrationStage('target plan', 'component', environmentLabel, () => buildComponentPlan(componentCommandContext({
1128
+ cwd: input.cwd,
1129
+ envName: componentTargetEnvironment(input),
1130
+ client,
1131
+ operation: 'plan',
1132
+ }), undefined, input.detailedDiff === true))
1133
+ : undefined;
1134
+ const jobTemplates = resources.includes('job-template')
1135
+ ? await runMigrationStage('target plan', 'job-template', environmentLabel, () => buildJobTemplatesPlan({
1136
+ client,
1137
+ cwd: input.cwd,
1138
+ envName: environmentKey,
1139
+ stableKeyName,
1140
+ ...(input.projectDependencies === true && components
1141
+ ? { projectedComponents: projectedComponentDependencies(components) }
1142
+ : {}),
1143
+ }))
1144
+ : undefined;
1145
+ const endpoints = resources.includes('endpoint')
1146
+ ? await runMigrationStage('target plan', 'endpoint', environmentLabel, () => buildEndpointsPlan({
1147
+ client,
1148
+ cwd: input.cwd,
1149
+ envName: environmentKey,
1150
+ stableKeyName,
1151
+ ...(input.projectDependencies === true && components
1152
+ ? { projectedComponents: projectedComponentDependencies(components) }
1153
+ : {}),
1154
+ }))
1155
+ : undefined;
1156
+ const schedules = resources.includes('schedule')
1157
+ ? await runMigrationStage('target plan', 'schedule', environmentLabel, () => buildSchedulesPlan({
1158
+ client,
1159
+ cwd: input.cwd,
1160
+ envName: environmentKey,
1161
+ stableKeyName,
1162
+ ...(input.projectDependencies === true && jobTemplates
1163
+ ? { projectedJobTemplates: projectedJobTemplateDependencies(jobTemplates) }
1164
+ : {}),
1165
+ ...(input.projectDependencies === true && databaseViews && input.pulls.databaseViews
1166
+ ? { projectedDatabaseViews: projectedDatabaseViewDependencies(databaseViews, input.pulls.databaseViews) }
1167
+ : {}),
1168
+ }))
1169
+ : undefined;
1170
+ const events = resources.includes('event')
1171
+ ? await runMigrationStage('target plan', 'event', environmentLabel, () => buildEventsPlan({
1172
+ client,
1173
+ cwd: input.cwd,
1174
+ envName: environmentKey,
1175
+ stableKeyName,
1176
+ ...(input.projectDependencies === true && jobTemplates
1177
+ ? { projectedJobTemplates: projectedJobTemplateDependencies(jobTemplates) }
1178
+ : {}),
1179
+ }))
1180
+ : undefined;
1181
+ const groups = resources.includes('group')
1182
+ ? await runMigrationStage('target plan', 'group', environmentLabel, () => buildGroupsPlan({
1183
+ client,
1184
+ cwd: input.cwd,
1185
+ envName: environmentKey,
1186
+ stableKeyName,
1187
+ }))
1188
+ : undefined;
1189
+ const roleGroups = resources.includes('role-group')
1190
+ ? await runMigrationStage('target plan', 'role-group', environmentLabel, () => buildRoleGroupsPlan({
1191
+ client,
1192
+ cwd: input.cwd,
1193
+ envName: environmentKey,
1194
+ stableKeyName,
1195
+ }))
1196
+ : undefined;
1197
+ return combinePlan({
1198
+ migrationInput: input,
1199
+ sourcePullMode: input.sourcePullMode,
1200
+ pulls: input.pulls,
1201
+ databaseSchemas,
1202
+ databaseViews,
1203
+ components,
1204
+ jobTemplates,
1205
+ endpoints,
1206
+ schedules,
1207
+ events,
1208
+ groups,
1209
+ roleGroups,
1210
+ });
1211
+ }
1212
+ export async function buildMigrationPlan(input) {
1213
+ requireProject(input);
1214
+ if (input.sourceMode === 'workspace') {
1215
+ const pulls = workspaceDesiredPulls(input);
1216
+ return planWorkspace({
1217
+ ...input,
1218
+ pulls,
1219
+ sourcePullMode: 'repository',
1220
+ projectDependencies: true,
1221
+ });
1222
+ }
1223
+ const { temporaryRoot, temporaryProject } = createTemporaryProject(input);
1224
+ try {
1225
+ const temporaryInput = { ...input, cwd: temporaryProject };
1226
+ const pulls = await pullSelectedResources(temporaryInput);
1227
+ return await planWorkspace({
1228
+ ...temporaryInput,
1229
+ pulls,
1230
+ sourcePullMode: 'temporary',
1231
+ projectDependencies: true,
1232
+ });
1233
+ }
1234
+ finally {
1235
+ fs.rmSync(temporaryRoot, { recursive: true, force: true });
1236
+ }
1237
+ }
1238
+ function resultsAreComplete(results) {
1239
+ return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
1240
+ }
1241
+ function componentResultsAreComplete(results) {
1242
+ return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
1243
+ }
1244
+ function jobTemplateResultsAreComplete(results) {
1245
+ return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
1246
+ }
1247
+ function endpointResultsAreComplete(results) {
1248
+ return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
1249
+ }
1250
+ function scheduleResultsAreComplete(results) {
1251
+ return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
1252
+ }
1253
+ function eventResultsAreComplete(results) {
1254
+ return results.every((result) => result.status === 'deployed' || result.status === 'skipped');
1255
+ }
1256
+ export async function runMigration(input) {
1257
+ requireProject(input);
1258
+ const resources = selectedResources(input);
1259
+ const stableKeyName = readProjectStableKeyName(input.cwd);
1260
+ const sourcePullMode = input.sourceMode === 'workspace' ? 'repository' : 'workspace';
1261
+ const reviewedWorkspaceChanges = input.sourceMode === 'workspace' && input.allowDestructive === true;
1262
+ const pulls = input.sourceMode === 'workspace'
1263
+ ? workspaceDesiredPulls(input)
1264
+ : await pullSelectedResources(input);
1265
+ const initialPlan = await planWorkspace({
1266
+ ...input,
1267
+ pulls,
1268
+ sourcePullMode,
1269
+ projectDependencies: true,
1270
+ });
1271
+ const base = {
1272
+ schemaVersion: 2,
1273
+ command: 'run',
1274
+ from: input.from,
1275
+ to: input.to,
1276
+ resources,
1277
+ policy: { ...migrationPolicy(input), mode: 'upsert' },
1278
+ sourcePull: pulls,
1279
+ plan: initialPlan,
1280
+ };
1281
+ if (!initialPlan.readyToMigrate) {
1282
+ return { ...base, verdict: 'blocked', results: [], phaseResults: {} };
1283
+ }
1284
+ const targetClient = resolveTargetClient(input);
1285
+ const environmentKey = targetKey(input);
1286
+ const phaseResults = {};
1287
+ const results = [];
1288
+ if (resources.includes('database-table')) {
1289
+ const pushed = await pushDatabaseSchemas({
1290
+ client: targetClient,
1291
+ cwd: input.cwd,
1292
+ envName: environmentKey,
1293
+ stableKeyName,
1294
+ force: true,
1295
+ prunePartitions: reviewedWorkspaceChanges,
1296
+ prunePartitionsConfirmed: reviewedWorkspaceChanges,
1297
+ migrationPolicy: migrationPolicy(input),
1298
+ });
1299
+ phaseResults['database-table'] = pushed.results;
1300
+ results.push(...pushed.results);
1301
+ const schemaVerification = await buildDatabaseSchemasPlan({
1302
+ client: targetClient,
1303
+ cwd: input.cwd,
1304
+ envName: environmentKey,
1305
+ stableKeyName,
1306
+ withStats: input.withStats,
1307
+ migrationPolicy: migrationPolicy(input),
1308
+ });
1309
+ const schemaPhase = applyWorkspaceDeploymentPolicy(input, summarizeSchemaPhase(schemaVerification), {
1310
+ databaseSchemas: schemaVerification,
1311
+ });
1312
+ if (!resultsAreComplete(pushed.results) || !schemaPhase.readyToMigrate || schemaPhase.needsChanges) {
1313
+ const verification = combinePlan({
1314
+ migrationInput: input,
1315
+ sourcePullMode,
1316
+ pulls,
1317
+ databaseSchemas: schemaVerification,
1318
+ databaseViews: initialPlan.databaseViews,
1319
+ components: initialPlan.components,
1320
+ jobTemplates: initialPlan.jobTemplates,
1321
+ endpoints: initialPlan.endpoints,
1322
+ schedules: initialPlan.schedules,
1323
+ events: initialPlan.events,
1324
+ groups: initialPlan.groups,
1325
+ roleGroups: initialPlan.roleGroups,
1326
+ });
1327
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1328
+ }
1329
+ }
1330
+ if (resources.includes('database-view')) {
1331
+ const liveViewPlan = await buildDatabaseViewsPlan({
1332
+ client: targetClient,
1333
+ cwd: input.cwd,
1334
+ envName: environmentKey,
1335
+ stableKeyName,
1336
+ migrationPolicy: viewMigrationPolicy(input),
1337
+ });
1338
+ const liveViewPhase = applyWorkspaceDeploymentPolicy(input, summarizeViewPhase(liveViewPlan), {
1339
+ databaseViews: liveViewPlan,
1340
+ });
1341
+ if (!liveViewPhase.readyToMigrate) {
1342
+ const verification = await planWorkspace({
1343
+ ...input,
1344
+ pulls,
1345
+ sourcePullMode,
1346
+ });
1347
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1348
+ }
1349
+ const pushed = await pushDatabaseViews({
1350
+ client: targetClient,
1351
+ cwd: input.cwd,
1352
+ envName: environmentKey,
1353
+ stableKeyName,
1354
+ force: true,
1355
+ migrationPolicy: viewMigrationPolicy(input),
1356
+ });
1357
+ phaseResults['database-view'] = pushed.results;
1358
+ results.push(...pushed.results);
1359
+ }
1360
+ if (resources.includes('component')) {
1361
+ const liveComponentPlan = await buildComponentPlan(componentCommandContext({
1362
+ cwd: input.cwd,
1363
+ envName: componentTargetEnvironment(input),
1364
+ client: targetClient,
1365
+ operation: 'plan',
1366
+ }));
1367
+ const liveComponentPhase = summarizeComponentPhase(liveComponentPlan);
1368
+ if (!liveComponentPhase.readyToMigrate) {
1369
+ const verification = await planWorkspace({
1370
+ ...input,
1371
+ pulls,
1372
+ sourcePullMode,
1373
+ });
1374
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1375
+ }
1376
+ const componentResults = await pushAllComponents(componentCommandContext({
1377
+ cwd: input.cwd,
1378
+ envName: componentTargetEnvironment(input),
1379
+ client: targetClient,
1380
+ operation: 'push',
1381
+ }), { force: true, yes: true });
1382
+ phaseResults.component = componentResults;
1383
+ results.push(...componentResults);
1384
+ if (!componentResultsAreComplete(componentResults)) {
1385
+ const verification = await planWorkspace({
1386
+ ...input,
1387
+ pulls,
1388
+ sourcePullMode,
1389
+ });
1390
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1391
+ }
1392
+ const componentVerification = await buildComponentPlan(componentCommandContext({
1393
+ cwd: input.cwd,
1394
+ envName: componentTargetEnvironment(input),
1395
+ client: targetClient,
1396
+ operation: 'plan',
1397
+ }));
1398
+ const verifiedComponentPhase = summarizeComponentPhase(componentVerification);
1399
+ if (!verifiedComponentPhase.readyToMigrate || verifiedComponentPhase.needsChanges) {
1400
+ const verification = await planWorkspace({
1401
+ ...input,
1402
+ pulls,
1403
+ sourcePullMode,
1404
+ });
1405
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1406
+ }
1407
+ }
1408
+ if (resources.includes('job-template')) {
1409
+ const liveJobTemplatePlan = await buildJobTemplatesPlan({
1410
+ client: targetClient,
1411
+ cwd: input.cwd,
1412
+ envName: environmentKey,
1413
+ stableKeyName,
1414
+ });
1415
+ const liveJobTemplatePhase = summarizeJobTemplatePhase(liveJobTemplatePlan);
1416
+ if (!liveJobTemplatePhase.readyToMigrate) {
1417
+ const verification = await planWorkspace({
1418
+ ...input,
1419
+ pulls,
1420
+ sourcePullMode,
1421
+ });
1422
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1423
+ }
1424
+ const pushed = await pushJobTemplates({
1425
+ client: targetClient,
1426
+ cwd: input.cwd,
1427
+ envName: environmentKey,
1428
+ stableKeyName,
1429
+ force: true,
1430
+ });
1431
+ phaseResults['job-template'] = pushed.results;
1432
+ results.push(...pushed.results);
1433
+ if (!jobTemplateResultsAreComplete(pushed.results)) {
1434
+ const verification = await planWorkspace({
1435
+ ...input,
1436
+ pulls,
1437
+ sourcePullMode,
1438
+ });
1439
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1440
+ }
1441
+ }
1442
+ if (resources.includes('endpoint')) {
1443
+ const liveEndpointPlan = await buildEndpointsPlan({
1444
+ client: targetClient,
1445
+ cwd: input.cwd,
1446
+ envName: environmentKey,
1447
+ stableKeyName,
1448
+ });
1449
+ const liveEndpointPhase = summarizeEndpointPhase(liveEndpointPlan);
1450
+ if (!liveEndpointPhase.readyToMigrate) {
1451
+ const verification = await planWorkspace({
1452
+ ...input,
1453
+ pulls,
1454
+ sourcePullMode,
1455
+ });
1456
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1457
+ }
1458
+ const pushed = await pushEndpoints({
1459
+ client: targetClient,
1460
+ cwd: input.cwd,
1461
+ envName: environmentKey,
1462
+ stableKeyName,
1463
+ force: true,
1464
+ });
1465
+ phaseResults.endpoint = pushed.results;
1466
+ results.push(...pushed.results);
1467
+ if (!endpointResultsAreComplete(pushed.results)) {
1468
+ const verification = await planWorkspace({
1469
+ ...input,
1470
+ pulls,
1471
+ sourcePullMode,
1472
+ });
1473
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1474
+ }
1475
+ }
1476
+ if (resources.includes('schedule')) {
1477
+ const liveSchedulePlan = await buildSchedulesPlan({
1478
+ client: targetClient,
1479
+ cwd: input.cwd,
1480
+ envName: environmentKey,
1481
+ stableKeyName,
1482
+ });
1483
+ const liveSchedulePhase = applyWorkspaceDeploymentPolicy(input, summarizeSchedulePhase(liveSchedulePlan), {
1484
+ schedules: liveSchedulePlan,
1485
+ });
1486
+ if (!liveSchedulePhase.readyToMigrate) {
1487
+ const verification = await planWorkspace({
1488
+ ...input,
1489
+ pulls,
1490
+ sourcePullMode,
1491
+ });
1492
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1493
+ }
1494
+ const pushed = await pushSchedules({
1495
+ client: targetClient,
1496
+ cwd: input.cwd,
1497
+ envName: environmentKey,
1498
+ stableKeyName,
1499
+ force: true,
1500
+ });
1501
+ phaseResults.schedule = pushed.results;
1502
+ results.push(...pushed.results);
1503
+ if (!scheduleResultsAreComplete(pushed.results)) {
1504
+ const verification = await planWorkspace({
1505
+ ...input,
1506
+ pulls,
1507
+ sourcePullMode,
1508
+ });
1509
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1510
+ }
1511
+ }
1512
+ if (resources.includes('event')) {
1513
+ const liveEventPlan = await buildEventsPlan({
1514
+ client: targetClient,
1515
+ cwd: input.cwd,
1516
+ envName: environmentKey,
1517
+ stableKeyName,
1518
+ });
1519
+ const liveEventPhase = summarizeEventPhase(liveEventPlan);
1520
+ if (!liveEventPhase.readyToMigrate) {
1521
+ const verification = await planWorkspace({
1522
+ ...input,
1523
+ pulls,
1524
+ sourcePullMode,
1525
+ });
1526
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1527
+ }
1528
+ const pushed = await pushEvents({
1529
+ client: targetClient,
1530
+ cwd: input.cwd,
1531
+ envName: environmentKey,
1532
+ stableKeyName,
1533
+ force: true,
1534
+ });
1535
+ phaseResults.event = pushed.results;
1536
+ results.push(...pushed.results);
1537
+ if (!eventResultsAreComplete(pushed.results)) {
1538
+ const verification = await planWorkspace({
1539
+ ...input,
1540
+ pulls,
1541
+ sourcePullMode,
1542
+ });
1543
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1544
+ }
1545
+ }
1546
+ if (resources.includes('group')) {
1547
+ const liveGroupPlan = await buildGroupsPlan({
1548
+ client: targetClient,
1549
+ cwd: input.cwd,
1550
+ envName: environmentKey,
1551
+ stableKeyName,
1552
+ });
1553
+ const liveGroupPhase = applyWorkspaceDeploymentPolicy(input, summarizeGroupPhase(liveGroupPlan), {
1554
+ groups: liveGroupPlan,
1555
+ });
1556
+ if (!liveGroupPhase.readyToMigrate) {
1557
+ const verification = await planWorkspace({
1558
+ ...input,
1559
+ pulls,
1560
+ sourcePullMode,
1561
+ });
1562
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1563
+ }
1564
+ const pushed = await pushGroups({
1565
+ client: targetClient,
1566
+ cwd: input.cwd,
1567
+ envName: environmentKey,
1568
+ stableKeyName,
1569
+ force: true,
1570
+ });
1571
+ phaseResults.group = pushed.results;
1572
+ results.push(...pushed.results);
1573
+ if (!resultsAreComplete(pushed.results)) {
1574
+ const verification = await planWorkspace({
1575
+ ...input,
1576
+ pulls,
1577
+ sourcePullMode,
1578
+ });
1579
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1580
+ }
1581
+ }
1582
+ if (resources.includes('role-group')) {
1583
+ const liveRoleGroupPlan = await buildRoleGroupsPlan({
1584
+ client: targetClient,
1585
+ cwd: input.cwd,
1586
+ envName: environmentKey,
1587
+ stableKeyName,
1588
+ });
1589
+ const liveRoleGroupPhase = applyWorkspaceDeploymentPolicy(input, summarizeRoleGroupPhase(liveRoleGroupPlan), {
1590
+ roleGroups: liveRoleGroupPlan,
1591
+ });
1592
+ if (!liveRoleGroupPhase.readyToMigrate) {
1593
+ const verification = await planWorkspace({
1594
+ ...input,
1595
+ pulls,
1596
+ sourcePullMode,
1597
+ });
1598
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1599
+ }
1600
+ const pushed = await pushRoleGroups({
1601
+ client: targetClient,
1602
+ cwd: input.cwd,
1603
+ envName: environmentKey,
1604
+ stableKeyName,
1605
+ force: true,
1606
+ });
1607
+ phaseResults['role-group'] = pushed.results;
1608
+ results.push(...pushed.results);
1609
+ if (!resultsAreComplete(pushed.results)) {
1610
+ const verification = await planWorkspace({
1611
+ ...input,
1612
+ pulls,
1613
+ sourcePullMode,
1614
+ });
1615
+ return { ...base, verdict: 'failed', results, phaseResults, verification };
1616
+ }
1617
+ }
1618
+ const verification = await planWorkspace({
1619
+ ...input,
1620
+ pulls,
1621
+ sourcePullMode,
1622
+ });
1623
+ return {
1624
+ ...base,
1625
+ verdict: resultsAreComplete(results) && verification.readyToMigrate && !verification.needsChanges
1626
+ ? 'succeeded'
1627
+ : 'failed',
1628
+ results,
1629
+ phaseResults,
1630
+ verification,
1631
+ };
1632
+ }