@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.
- package/README.md +275 -479
- package/dist/src/cli.js +71 -5
- package/dist/src/client.d.ts +28 -12
- package/dist/src/client.js +234 -66
- package/dist/src/commands/component.d.ts +67 -0
- package/dist/src/commands/component.js +299 -27
- package/dist/src/commands/database-tables.d.ts +2 -0
- package/dist/src/commands/{database-schemas.js → database-tables.js} +21 -40
- package/dist/src/commands/database-views.js +21 -18
- package/dist/src/commands/endpoints.js +26 -16
- package/dist/src/commands/events.js +18 -20
- package/dist/src/commands/groups.js +13 -22
- package/dist/src/commands/index.d.ts +2 -1
- package/dist/src/commands/index.js +2 -1
- package/dist/src/commands/job-templates.js +21 -15
- package/dist/src/commands/metadata.js +58 -15
- package/dist/src/commands/migrate.d.ts +6 -0
- package/dist/src/commands/migrate.js +658 -0
- package/dist/src/commands/project.js +4 -4
- package/dist/src/commands/role-groups.js +14 -25
- package/dist/src/commands/schedules.js +19 -20
- package/dist/src/commands/terminal-browser.d.ts +16 -0
- package/dist/src/commands/terminal-browser.js +92 -0
- package/dist/src/commands/terminal-image.d.ts +7 -0
- package/dist/src/commands/terminal-image.js +40 -0
- package/dist/src/commands/terminal-patch-worker.d.ts +1 -0
- package/dist/src/commands/terminal-patch-worker.js +24 -0
- package/dist/src/commands/terminal-patch.d.ts +2 -0
- package/dist/src/commands/terminal-patch.js +156 -0
- package/dist/src/commands/terminal-sandbox.d.ts +8 -0
- package/dist/src/commands/terminal-sandbox.js +87 -0
- package/dist/src/commands/terminal-service.js +2 -2
- package/dist/src/commands/terminal.d.ts +31 -4
- package/dist/src/commands/terminal.js +360 -45
- package/dist/src/component-lock.d.ts +12 -2
- package/dist/src/component-lock.js +60 -1
- package/dist/src/diff-details.d.ts +8 -0
- package/dist/src/diff-details.js +152 -0
- package/dist/src/env-sync.js +8 -6
- package/dist/src/http-trace.d.ts +94 -0
- package/dist/src/http-trace.js +226 -0
- package/dist/src/metadata-backfill.d.ts +5 -4
- package/dist/src/metadata-backfill.js +82 -158
- package/dist/src/migration.d.ts +141 -0
- package/dist/src/migration.js +1632 -0
- package/dist/src/resource-inventory.d.ts +28 -0
- package/dist/src/resource-inventory.js +85 -0
- package/dist/src/resource-syncs/{database-schema-sync.d.ts → database-table-sync.d.ts} +13 -3
- package/dist/src/resource-syncs/{database-schema-sync.js → database-table-sync.js} +147 -62
- package/dist/src/resource-syncs/database-view-sync.d.ts +24 -2
- package/dist/src/resource-syncs/database-view-sync.js +156 -68
- package/dist/src/resource-syncs/endpoint-sync.d.ts +27 -0
- package/dist/src/resource-syncs/endpoint-sync.js +362 -82
- package/dist/src/resource-syncs/event-sync.d.ts +27 -0
- package/dist/src/resource-syncs/event-sync.js +123 -26
- package/dist/src/resource-syncs/group-sync.d.ts +7 -0
- package/dist/src/resource-syncs/group-sync.js +60 -14
- package/dist/src/resource-syncs/job-template-sync.d.ts +21 -0
- package/dist/src/resource-syncs/job-template-sync.js +91 -30
- package/dist/src/resource-syncs/role-group-sync.d.ts +7 -0
- package/dist/src/resource-syncs/role-group-sync.js +47 -9
- package/dist/src/resource-syncs/schedule-sync.d.ts +30 -1
- package/dist/src/resource-syncs/schedule-sync.js +114 -20
- package/dist/src/resource-syncs/util.d.ts +3 -0
- package/dist/src/resource-syncs/util.js +8 -6
- package/dist/src/resource-target.d.ts +11 -0
- package/dist/src/resource-target.js +48 -0
- package/dist/src/sync-output.d.ts +29 -1
- package/dist/src/sync-output.js +139 -2
- package/dist/src/tracked-resources.d.ts +1 -1
- package/dist/src/tracked-resources.js +8 -6
- package/dist/src/types.d.ts +3 -0
- package/dist/src/ui.js +18 -9
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.js +17 -0
- package/dist/src/workspace-diff.d.ts +25 -0
- package/dist/src/workspace-diff.js +75 -0
- package/package.json +9 -6
- package/dist/src/commands/database-schemas.d.ts +0 -2
- /package/dist/src/{database-schema-artifacts.d.ts → database-table-artifacts.d.ts} +0 -0
- /package/dist/src/{database-schema-artifacts.js → database-table-artifacts.js} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { describeFieldChanges, unifiedLineDiff } from "../diff-details.js";
|
|
2
3
|
import { hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
3
4
|
import { readConfiguredResourceMetadataStableKey, sanitizeUserMetadata } from "../resource-metadata.js";
|
|
4
5
|
import { readJsonFile, sanitizeSegment } from "../utils.js";
|
|
5
|
-
import { findManifestFiles, isRecord, localTargetPath, requireProjectLayout, stableKeySuffix, toPortableRelativePath, unwrapData, writePulledManifest, } from "./util.js";
|
|
6
|
+
import { findManifestFiles, isRecord, localTargetPath, removeRelocatedManifest, requireProjectLayout, stableKeySuffix, toPortableRelativePath, unwrapData, writePulledManifest, } from "./util.js";
|
|
6
7
|
export const DATABASE_VIEWS_DIRECTORY = 'DatabaseViews';
|
|
7
8
|
export const DATABASE_VIEW_MANIFEST_FILE = 'database-view.json';
|
|
8
9
|
function canonicalValue(value) {
|
|
@@ -42,7 +43,7 @@ function databaseViewManifestPath(workspaceRoot, manifest) {
|
|
|
42
43
|
: 'Uncategorized';
|
|
43
44
|
return path.join(workspaceRoot, DATABASE_VIEWS_DIRECTORY, category, `${sanitizeSegment(manifest.name)}-${stableKeySuffix(manifest.stableKey)}`, DATABASE_VIEW_MANIFEST_FILE);
|
|
44
45
|
}
|
|
45
|
-
function readWorkspaceDatabaseViews(cwd) {
|
|
46
|
+
export function readWorkspaceDatabaseViews(cwd) {
|
|
46
47
|
const { workspaceRoot } = requireProjectLayout(cwd, 'Database View');
|
|
47
48
|
return findManifestFiles(path.join(workspaceRoot, DATABASE_VIEWS_DIRECTORY), DATABASE_VIEW_MANIFEST_FILE)
|
|
48
49
|
.map((manifestPath) => ({
|
|
@@ -269,23 +270,23 @@ function materializedConfiguration(record, output) {
|
|
|
269
270
|
}
|
|
270
271
|
function rawSqlSources(input) {
|
|
271
272
|
if (!Array.isArray(input.record.sourceDatabaseIds)) {
|
|
272
|
-
return `Database View "${String(input.record.name || viewIdOf(input.record) || 'unknown')}" does not expose raw SQL source Database
|
|
273
|
+
return `Database View "${String(input.record.name || viewIdOf(input.record) || 'unknown')}" does not expose raw SQL source Database Tables`;
|
|
273
274
|
}
|
|
274
275
|
const sources = [];
|
|
275
276
|
for (const sourceId of [...new Set(input.record.sourceDatabaseIds)]) {
|
|
276
277
|
const database = input.inventory.byId.get(sourceId);
|
|
277
278
|
if (!database) {
|
|
278
|
-
return `Database View "${String(input.record.name || viewIdOf(input.record) || 'unknown')}" source Database
|
|
279
|
+
return `Database View "${String(input.record.name || viewIdOf(input.record) || 'unknown')}" source Database Table "${sourceId}" is unavailable`;
|
|
279
280
|
}
|
|
280
281
|
const databaseStableKey = stableKeyOf(database, input.stableKeyName);
|
|
281
282
|
if (!databaseStableKey) {
|
|
282
|
-
return `Database View source Database
|
|
283
|
+
return `Database View source Database Table "${String(database.name || sourceId)}" is missing ${input.stableKeyName}`;
|
|
283
284
|
}
|
|
284
285
|
if (input.inventory.duplicateStableKeys.has(databaseStableKey)) {
|
|
285
|
-
return `Database View source Database
|
|
286
|
+
return `Database View source Database Table "${String(database.name || sourceId)}" has duplicate stableKey "${databaseStableKey}"`;
|
|
286
287
|
}
|
|
287
288
|
if (!isNonEmptyString(database.name)) {
|
|
288
|
-
return `Database View source Database
|
|
289
|
+
return `Database View source Database Table "${sourceId}" has no logical name`;
|
|
289
290
|
}
|
|
290
291
|
sources.push({ databaseStableKey, name: database.name });
|
|
291
292
|
}
|
|
@@ -335,24 +336,24 @@ function manifestFromRecord(input) {
|
|
|
335
336
|
return `Database View "${String(record.name || viewIdOf(record) || stableKey)}" has no valid structured request`;
|
|
336
337
|
}
|
|
337
338
|
if (!Array.isArray(record.sourceDatabaseIds) || record.sourceDatabaseIds.length === 0) {
|
|
338
|
-
return `Database View "${record.name}" has no source Database
|
|
339
|
+
return `Database View "${record.name}" has no source Database Tables`;
|
|
339
340
|
}
|
|
340
341
|
const dependencies = isRecord(record.sourceFieldDependencies) ? record.sourceFieldDependencies : {};
|
|
341
342
|
const sources = [];
|
|
342
343
|
for (const sourceId of [...new Set(record.sourceDatabaseIds)]) {
|
|
343
344
|
const database = inventory.byId.get(sourceId);
|
|
344
345
|
if (!database) {
|
|
345
|
-
return `Database View "${record.name}" source Database
|
|
346
|
+
return `Database View "${record.name}" source Database Table "${sourceId}" is unavailable`;
|
|
346
347
|
}
|
|
347
348
|
const databaseStableKey = stableKeyOf(database, stableKeyName);
|
|
348
349
|
if (!databaseStableKey) {
|
|
349
|
-
return `Database View source Database
|
|
350
|
+
return `Database View source Database Table "${String(database.name || sourceId)}" is missing ${stableKeyName}`;
|
|
350
351
|
}
|
|
351
352
|
if (inventory.duplicateStableKeys.has(databaseStableKey)) {
|
|
352
|
-
return `Database View source Database
|
|
353
|
+
return `Database View source Database Table "${String(database.name || sourceId)}" has duplicate stableKey "${databaseStableKey}"`;
|
|
353
354
|
}
|
|
354
355
|
if (!isNonEmptyString(database.name)) {
|
|
355
|
-
return `Database View source Database
|
|
356
|
+
return `Database View source Database Table "${sourceId}" has no logical name`;
|
|
356
357
|
}
|
|
357
358
|
const columns = sourceColumns({ database, dependencyFields: dependencies[sourceId], stableKeyName });
|
|
358
359
|
if (typeof columns === 'string') {
|
|
@@ -377,6 +378,7 @@ function emptyPlanCounts() {
|
|
|
377
378
|
'safe-update': 0,
|
|
378
379
|
'remote-changed': 0,
|
|
379
380
|
conflict: 0,
|
|
381
|
+
'validation-failed': 0,
|
|
380
382
|
'missing-lock': 0,
|
|
381
383
|
orphan: 0,
|
|
382
384
|
collision: 0,
|
|
@@ -434,11 +436,11 @@ function validateTargetSources(manifest, databases, stableKeyName) {
|
|
|
434
436
|
for (const source of manifest.sources) {
|
|
435
437
|
const candidates = byStableKey.get(source.databaseStableKey) || [];
|
|
436
438
|
if (candidates.length !== 1) {
|
|
437
|
-
return `source Database
|
|
439
|
+
return `source Database Table Stable Key "${source.databaseStableKey}" resolves to ${candidates.length} TARGET records`;
|
|
438
440
|
}
|
|
439
441
|
const database = candidates[0];
|
|
440
442
|
if (database.name !== source.name) {
|
|
441
|
-
return `source Database
|
|
443
|
+
return `source Database Table "${source.databaseStableKey}" has TARGET name "${String(database.name || '')}" instead of "${source.name}"`;
|
|
442
444
|
}
|
|
443
445
|
if (!('columns' in source)) {
|
|
444
446
|
continue;
|
|
@@ -466,20 +468,36 @@ function validateTargetSources(manifest, databases, stableKeyName) {
|
|
|
466
468
|
}
|
|
467
469
|
return undefined;
|
|
468
470
|
}
|
|
471
|
+
// Kept in the environment lock only; manifests remain portable. A missing or
|
|
472
|
+
// ambiguous dependency must never make an unchanged view eligible to skip preview.
|
|
473
|
+
function databaseViewDependencyHash(manifest, databases, stableKeyName) {
|
|
474
|
+
const dependencies = [];
|
|
475
|
+
for (const source of [...manifest.sources].sort((a, b) => a.databaseStableKey.localeCompare(b.databaseStableKey))) {
|
|
476
|
+
const matches = databases.filter((database) => stableKeyOf(database, stableKeyName) === source.databaseStableKey);
|
|
477
|
+
if (matches.length !== 1) {
|
|
478
|
+
return undefined;
|
|
479
|
+
}
|
|
480
|
+
const database = matches[0];
|
|
481
|
+
if (!Array.isArray(database.definition)) {
|
|
482
|
+
return undefined;
|
|
483
|
+
}
|
|
484
|
+
dependencies.push({ stableKey: source.databaseStableKey, name: database.name, definition: database.definition, version: database.version });
|
|
485
|
+
}
|
|
486
|
+
return hashStable(canonicalValue(dependencies));
|
|
487
|
+
}
|
|
469
488
|
function databaseViewPreviewPayload(manifest) {
|
|
470
|
-
const output = { take:
|
|
489
|
+
const output = { take: 1, count: false };
|
|
471
490
|
if (manifest.definitionMode === 'RAW_SQL') {
|
|
472
491
|
return {
|
|
473
492
|
definitionMode: 'RAW_SQL',
|
|
474
493
|
rawQuery: manifest.rawQuery,
|
|
475
494
|
take: 0,
|
|
476
|
-
output,
|
|
477
495
|
};
|
|
478
496
|
}
|
|
479
497
|
return {
|
|
480
498
|
definitionMode: 'STRUCTURED',
|
|
481
499
|
request: manifest.request,
|
|
482
|
-
take:
|
|
500
|
+
take: 1,
|
|
483
501
|
output,
|
|
484
502
|
};
|
|
485
503
|
}
|
|
@@ -578,6 +596,17 @@ export async function buildDatabaseViewsPlan(input) {
|
|
|
578
596
|
const entry = entries[0];
|
|
579
597
|
const desired = entry.manifest;
|
|
580
598
|
const desiredHash = hashPortableDatabaseView(desired);
|
|
599
|
+
const comparableRecords = targetByKey.get(stableKey) || [];
|
|
600
|
+
const comparableTarget = comparableRecords.length === 1
|
|
601
|
+
? supportedTargetManifest({
|
|
602
|
+
record: comparableRecords[0], stableKey, stableKeyName: input.stableKeyName, inventory: targetInventory,
|
|
603
|
+
})
|
|
604
|
+
: undefined;
|
|
605
|
+
const rawQueryDiff = comparableTarget && typeof comparableTarget !== 'string'
|
|
606
|
+
&& desired.definitionMode === 'RAW_SQL' && comparableTarget.definitionMode === 'RAW_SQL'
|
|
607
|
+
? unifiedLineDiff(comparableTarget.rawQuery, desired.rawQuery)
|
|
608
|
+
: [];
|
|
609
|
+
const rawQueryDetail = rawQueryDiff.length > 0 ? { rawQueryDiff } : {};
|
|
581
610
|
const excludedTargetReason = excludedTargetByKey.get(stableKey);
|
|
582
611
|
if (excludedTargetReason) {
|
|
583
612
|
const reason = `TARGET Database View is incompatible: ${excludedTargetReason}`;
|
|
@@ -585,30 +614,47 @@ export async function buildDatabaseViewsPlan(input) {
|
|
|
585
614
|
items.push({ status: 'collision', stableKey, name: desired.name, reason, desiredHash });
|
|
586
615
|
continue;
|
|
587
616
|
}
|
|
588
|
-
const sourceReadiness = validateTargetSources(desired, targetDatabases, input.stableKeyName);
|
|
617
|
+
const sourceReadiness = validateTargetSources(desired, input.dependencyDatabases || targetDatabases, input.stableKeyName);
|
|
589
618
|
if (sourceReadiness) {
|
|
590
619
|
blockers.push(`Database View "${stableKey}": ${sourceReadiness}.`);
|
|
591
|
-
items.push({ status: 'conflict', stableKey, name: desired.name, reason: sourceReadiness, desiredHash });
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
let preview;
|
|
595
|
-
try {
|
|
596
|
-
preview = await input.client.previewDatabaseView(databaseViewPreviewPayload(desired));
|
|
597
|
-
}
|
|
598
|
-
catch (error) {
|
|
599
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
600
|
-
warnings.push(`Database View "${stableKey}" TARGET preview failed: ${message}`);
|
|
601
|
-
items.push({ status: 'conflict', stableKey, name: desired.name, reason: `target preview failed: ${message}`, desiredHash });
|
|
620
|
+
items.push({ status: 'conflict', stableKey, name: desired.name, reason: sourceReadiness, desiredHash, ...rawQueryDetail });
|
|
602
621
|
continue;
|
|
603
622
|
}
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
623
|
+
const currentDetails = comparableTarget && typeof comparableTarget !== 'string'
|
|
624
|
+
? {
|
|
625
|
+
currentHash: hashPortableDatabaseView(comparableTarget),
|
|
626
|
+
changedFields: diffManifestFields(desired, comparableTarget),
|
|
627
|
+
fieldChanges: describeFieldChanges(desired, comparableTarget, diffManifestFields(desired, comparableTarget)),
|
|
628
|
+
}
|
|
629
|
+
: {};
|
|
630
|
+
const baseline = lock.databaseViews[stableKey]?.environments[input.envName];
|
|
631
|
+
const dependencyHash = databaseViewDependencyHash(desired, input.dependencyDatabases || targetDatabases, input.stableKeyName);
|
|
632
|
+
const unchanged = currentDetails.currentHash === desiredHash
|
|
633
|
+
&& baseline?.remoteHash === desiredHash
|
|
634
|
+
&& dependencyHash !== undefined && baseline.dependencyHash === dependencyHash;
|
|
635
|
+
if (input.migrationPolicy?.deferPreview === true) {
|
|
636
|
+
warnings.push(`Database View "${stableKey}" TARGET preview is deferred until Database Table migration completes.`);
|
|
637
|
+
}
|
|
638
|
+
else if (!unchanged) {
|
|
639
|
+
let preview;
|
|
640
|
+
try {
|
|
641
|
+
preview = await input.client.previewDatabaseView(databaseViewPreviewPayload(desired));
|
|
642
|
+
}
|
|
643
|
+
catch (error) {
|
|
644
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
645
|
+
warnings.push(`Database View "${stableKey}" TARGET preview failed: ${message}`);
|
|
646
|
+
items.push({ status: 'validation-failed', stableKey, name: desired.name, reason: `target preview failed: ${message}`, desiredHash, ...currentDetails, ...rawQueryDetail });
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
const output = previewOutput(preview);
|
|
650
|
+
if (typeof output === 'string' || hashStable(output) !== hashStable(desired.output)) {
|
|
651
|
+
const reason = typeof output === 'string' ? output : 'target preview output signature differs from the manifest';
|
|
652
|
+
blockers.push(`Database View "${stableKey}": ${reason}.`);
|
|
653
|
+
items.push({ status: 'validation-failed', stableKey, name: desired.name, reason, desiredHash, ...currentDetails, ...rawQueryDetail });
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
610
656
|
}
|
|
611
|
-
const records =
|
|
657
|
+
const records = comparableRecords;
|
|
612
658
|
if (duplicateTargetKeys.has(stableKey)) {
|
|
613
659
|
continue;
|
|
614
660
|
}
|
|
@@ -624,7 +670,7 @@ export async function buildDatabaseViewsPlan(input) {
|
|
|
624
670
|
continue;
|
|
625
671
|
}
|
|
626
672
|
const record = records[0];
|
|
627
|
-
const current = supportedTargetManifest({ record, stableKey, stableKeyName: input.stableKeyName, inventory: targetInventory });
|
|
673
|
+
const current = comparableTarget || supportedTargetManifest({ record, stableKey, stableKeyName: input.stableKeyName, inventory: targetInventory });
|
|
628
674
|
if (typeof current === 'string') {
|
|
629
675
|
const reason = `TARGET Database View is incompatible: ${current}`;
|
|
630
676
|
blockers.push(`Database View "${stableKey}": ${reason}.`);
|
|
@@ -632,18 +678,28 @@ export async function buildDatabaseViewsPlan(input) {
|
|
|
632
678
|
continue;
|
|
633
679
|
}
|
|
634
680
|
if (current.name !== desired.name) {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
681
|
+
if (input.migrationPolicy?.sourceWins === true) {
|
|
682
|
+
warnings.push(`Database View "${stableKey}" will be renamed from "${current.name}" to "${desired.name}" by source-wins migration.`);
|
|
683
|
+
}
|
|
684
|
+
else {
|
|
685
|
+
const reason = 'TARGET name differs; renames require an explicit migration';
|
|
686
|
+
blockers.push(`Database View "${stableKey}": ${reason}.`);
|
|
687
|
+
items.push({ status: 'conflict', stableKey, name: desired.name, reason, desiredHash, ...rawQueryDetail });
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
639
690
|
}
|
|
640
691
|
if (current.type !== desired.type || current.definitionMode !== desired.definitionMode) {
|
|
641
692
|
const reason = current.type !== desired.type
|
|
642
693
|
? 'TARGET type differs; VIEW and MATERIALIZED_VIEW transitions require an explicit migration'
|
|
643
694
|
: 'TARGET definitionMode transition between STRUCTURED and RAW_SQL requires an explicit migration';
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
695
|
+
if (input.migrationPolicy?.allowDestructive === true) {
|
|
696
|
+
warnings.push(`Database View "${stableKey}": ${reason}; reviewed --force allows source-wins replacement semantics.`);
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
blockers.push(`Database View "${stableKey}": ${reason}. Re-run the reviewed migration with --force.`);
|
|
700
|
+
items.push({ status: 'conflict', stableKey, name: desired.name, reason, desiredHash, ...rawQueryDetail });
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
647
703
|
}
|
|
648
704
|
const currentHash = hashPortableDatabaseView(current);
|
|
649
705
|
const baselineHash = lock.databaseViews[stableKey]?.environments[input.envName]?.remoteHash;
|
|
@@ -661,7 +717,18 @@ export async function buildDatabaseViewsPlan(input) {
|
|
|
661
717
|
continue;
|
|
662
718
|
}
|
|
663
719
|
if (!baselineHash) {
|
|
664
|
-
items.push({
|
|
720
|
+
items.push({
|
|
721
|
+
status: 'missing-lock',
|
|
722
|
+
stableKey,
|
|
723
|
+
name: desired.name,
|
|
724
|
+
desiredHash,
|
|
725
|
+
currentHash,
|
|
726
|
+
reason: 'TARGET differs and has no environment baseline',
|
|
727
|
+
changedFields: diffManifestFields(desired, current),
|
|
728
|
+
fieldChanges: describeFieldChanges(desired, current, diffManifestFields(desired, current)),
|
|
729
|
+
...rawQueryDetail,
|
|
730
|
+
...materializedPlanDetails({ manifest: desired, schedules: targetSchedules.schedules, databaseViewId: viewIdOf(record) }),
|
|
731
|
+
});
|
|
665
732
|
continue;
|
|
666
733
|
}
|
|
667
734
|
const localChanged = hashDatabaseViewManifest(desired) !== lock.databaseViews[stableKey]?.sourceHash;
|
|
@@ -675,6 +742,8 @@ export async function buildDatabaseViewsPlan(input) {
|
|
|
675
742
|
currentHash,
|
|
676
743
|
baselineHash,
|
|
677
744
|
changedFields: diffManifestFields(desired, current),
|
|
745
|
+
fieldChanges: describeFieldChanges(desired, current, diffManifestFields(desired, current)),
|
|
746
|
+
...rawQueryDetail,
|
|
678
747
|
...materializedPlanDetails({ manifest: desired, schedules: targetSchedules.schedules, databaseViewId: viewIdOf(record) }),
|
|
679
748
|
});
|
|
680
749
|
}
|
|
@@ -898,10 +967,11 @@ async function recheckDatabaseViewUpdate(input) {
|
|
|
898
967
|
if (stableKeyOf(target, input.stableKeyName) !== input.manifest.stableKey) {
|
|
899
968
|
throw new Error(`TARGET Database View changed ${input.stableKeyName} after planning`);
|
|
900
969
|
}
|
|
901
|
-
if (target.type !== input.manifest.type || target.definitionMode !== input.manifest.definitionMode)
|
|
970
|
+
if ((target.type !== input.manifest.type || target.definitionMode !== input.manifest.definitionMode)
|
|
971
|
+
&& input.migrationPolicy?.allowDestructive !== true) {
|
|
902
972
|
throw new Error('TARGET Database View changed type or definitionMode after planning');
|
|
903
973
|
}
|
|
904
|
-
if (target.name !== input.manifest.name) {
|
|
974
|
+
if (target.name !== input.manifest.name && input.migrationPolicy?.sourceWins !== true) {
|
|
905
975
|
throw new Error('TARGET name differs; renames require an explicit migration');
|
|
906
976
|
}
|
|
907
977
|
const sourceReadiness = validateTargetSources(input.manifest, databaseResult.databases, input.stableKeyName);
|
|
@@ -925,7 +995,9 @@ async function recheckDatabaseViewUpdate(input) {
|
|
|
925
995
|
schedules: schedules.schedules,
|
|
926
996
|
databaseViewId,
|
|
927
997
|
});
|
|
928
|
-
if (materializedDetails.scheduleDependencies
|
|
998
|
+
if (materializedDetails.scheduleDependencies
|
|
999
|
+
&& materializedDetails.scheduleDependencies.length > 0
|
|
1000
|
+
&& input.migrationPolicy?.allowActiveScheduleDependencies !== true) {
|
|
929
1001
|
throw new Error(`active refresh Schedule dependencies require manual coordination: ${materializedDetails.scheduleDependencies.join(', ')}`);
|
|
930
1002
|
}
|
|
931
1003
|
const preview = await input.client.previewDatabaseView(databaseViewPreviewPayload(input.manifest));
|
|
@@ -942,7 +1014,11 @@ function updateDatabaseViewEnvironmentBaseline(input) {
|
|
|
942
1014
|
sourceHash: hashDatabaseViewManifest(input.manifest),
|
|
943
1015
|
environments: {
|
|
944
1016
|
...(existing?.environments || {}),
|
|
945
|
-
[input.envName]: {
|
|
1017
|
+
[input.envName]: {
|
|
1018
|
+
remoteHash: input.remoteHash,
|
|
1019
|
+
syncedAt: new Date().toISOString(),
|
|
1020
|
+
dependencyHash: databaseViewDependencyHash(input.manifest, input.databases, input.stableKeyName),
|
|
1021
|
+
},
|
|
946
1022
|
},
|
|
947
1023
|
};
|
|
948
1024
|
lock.databaseViews[input.manifest.stableKey] = entry;
|
|
@@ -976,17 +1052,6 @@ export async function pushDatabaseViews(input) {
|
|
|
976
1052
|
|| (input.force === true && ['remote-changed', 'conflict', 'missing-lock'].includes(item.status) && !canReconcile(item)));
|
|
977
1053
|
const results = [];
|
|
978
1054
|
for (const item of plan.items) {
|
|
979
|
-
const local = item.stableKey ? localByKey.get(item.stableKey) : undefined;
|
|
980
|
-
if (selected(item) && item.stableKey && local && local.manifest.type === 'MATERIALIZED_VIEW' && input.allowMaterializedWrites !== true) {
|
|
981
|
-
results.push({
|
|
982
|
-
stableKey: item.stableKey,
|
|
983
|
-
action: 'skipped',
|
|
984
|
-
status: 'skipped',
|
|
985
|
-
targetPath: localTargetPath(input.cwd, local.manifestPath),
|
|
986
|
-
reason: 'MATERIALIZED_VIEW deployment requires --allow-materialized',
|
|
987
|
-
});
|
|
988
|
-
continue;
|
|
989
|
-
}
|
|
990
1055
|
if (!selected(item)
|
|
991
1056
|
|| !item.stableKey
|
|
992
1057
|
|| !localByKey.has(item.stableKey)
|
|
@@ -1006,8 +1071,7 @@ export async function pushDatabaseViews(input) {
|
|
|
1006
1071
|
}
|
|
1007
1072
|
for (const item of plan.items.filter((candidate) => (selected(candidate)
|
|
1008
1073
|
&& candidate.status === 'create'
|
|
1009
|
-
&& candidate.stableKey
|
|
1010
|
-
&& (localByKey.get(candidate.stableKey)?.manifest.type === 'VIEW' || input.allowMaterializedWrites === true)))) {
|
|
1074
|
+
&& candidate.stableKey))) {
|
|
1011
1075
|
const stableKey = item.stableKey;
|
|
1012
1076
|
const local = localByKey.get(stableKey);
|
|
1013
1077
|
if (!local) {
|
|
@@ -1044,6 +1108,8 @@ export async function pushDatabaseViews(input) {
|
|
|
1044
1108
|
manifestPath: local.manifestPath,
|
|
1045
1109
|
manifest: desired,
|
|
1046
1110
|
remoteHash,
|
|
1111
|
+
databases,
|
|
1112
|
+
stableKeyName: input.stableKeyName,
|
|
1047
1113
|
});
|
|
1048
1114
|
results.push({
|
|
1049
1115
|
stableKey,
|
|
@@ -1069,8 +1135,7 @@ export async function pushDatabaseViews(input) {
|
|
|
1069
1135
|
}
|
|
1070
1136
|
for (const item of plan.items.filter((candidate) => (selected(candidate)
|
|
1071
1137
|
&& candidate.stableKey
|
|
1072
|
-
&& canUpdate(candidate)
|
|
1073
|
-
&& (localByKey.get(candidate.stableKey)?.manifest.type === 'VIEW' || input.allowMaterializedWrites === true)))) {
|
|
1138
|
+
&& canUpdate(candidate)))) {
|
|
1074
1139
|
const stableKey = item.stableKey;
|
|
1075
1140
|
const local = localByKey.get(stableKey);
|
|
1076
1141
|
if (!local) {
|
|
@@ -1088,6 +1153,7 @@ export async function pushDatabaseViews(input) {
|
|
|
1088
1153
|
manifest: desired,
|
|
1089
1154
|
stableKeyName: input.stableKeyName,
|
|
1090
1155
|
expectedHash: item.currentHash,
|
|
1156
|
+
migrationPolicy: input.migrationPolicy,
|
|
1091
1157
|
});
|
|
1092
1158
|
const payload = updateDatabaseViewPayload({ manifest: desired, target: live.target });
|
|
1093
1159
|
await input.client.updateDatabaseView(viewIdOf(live.target), payload);
|
|
@@ -1108,6 +1174,8 @@ export async function pushDatabaseViews(input) {
|
|
|
1108
1174
|
manifestPath: local.manifestPath,
|
|
1109
1175
|
manifest: desired,
|
|
1110
1176
|
remoteHash,
|
|
1177
|
+
databases: live.databases,
|
|
1178
|
+
stableKeyName: input.stableKeyName,
|
|
1111
1179
|
});
|
|
1112
1180
|
results.push({
|
|
1113
1181
|
stableKey,
|
|
@@ -1131,8 +1199,7 @@ export async function pushDatabaseViews(input) {
|
|
|
1131
1199
|
}
|
|
1132
1200
|
for (const item of plan.items.filter((candidate) => (selected(candidate)
|
|
1133
1201
|
&& candidate.stableKey
|
|
1134
|
-
&& canReconcile(candidate)
|
|
1135
|
-
&& (localByKey.get(candidate.stableKey)?.manifest.type === 'VIEW' || input.allowMaterializedWrites === true)))) {
|
|
1202
|
+
&& canReconcile(candidate)))) {
|
|
1136
1203
|
const stableKey = item.stableKey;
|
|
1137
1204
|
const local = localByKey.get(stableKey);
|
|
1138
1205
|
if (!local) {
|
|
@@ -1148,6 +1215,7 @@ export async function pushDatabaseViews(input) {
|
|
|
1148
1215
|
manifest: local.manifest,
|
|
1149
1216
|
stableKeyName: input.stableKeyName,
|
|
1150
1217
|
expectedHash: item.currentHash,
|
|
1218
|
+
migrationPolicy: input.migrationPolicy,
|
|
1151
1219
|
});
|
|
1152
1220
|
const accessPolicy = updateDatabaseViewPayload({ manifest: local.manifest, target: live.target });
|
|
1153
1221
|
const remoteHash = verifyUpdatedDatabaseView({
|
|
@@ -1165,6 +1233,8 @@ export async function pushDatabaseViews(input) {
|
|
|
1165
1233
|
manifestPath: local.manifestPath,
|
|
1166
1234
|
manifest: local.manifest,
|
|
1167
1235
|
remoteHash,
|
|
1236
|
+
databases: live.databases,
|
|
1237
|
+
stableKeyName: input.stableKeyName,
|
|
1168
1238
|
});
|
|
1169
1239
|
results.push({
|
|
1170
1240
|
stableKey,
|
|
@@ -1264,6 +1334,17 @@ export async function pullDatabaseViewsToWorkspace(input) {
|
|
|
1264
1334
|
previousPath: existing?.manifestPath,
|
|
1265
1335
|
};
|
|
1266
1336
|
});
|
|
1337
|
+
const sourceStableKeys = new Set(manifests.map((manifest) => manifest.stableKey));
|
|
1338
|
+
const pruned = input.pruneOrphans === true
|
|
1339
|
+
? [...existingByKey.values()]
|
|
1340
|
+
.filter((entry) => !sourceStableKeys.has(entry.manifest.stableKey))
|
|
1341
|
+
.map((entry) => ({
|
|
1342
|
+
stableKey: entry.manifest.stableKey,
|
|
1343
|
+
targetPath: localTargetPath(input.cwd, entry.manifestPath),
|
|
1344
|
+
manifestPath: entry.manifestPath,
|
|
1345
|
+
}))
|
|
1346
|
+
.sort((left, right) => right.manifestPath.length - left.manifestPath.length || left.stableKey.localeCompare(right.stableKey))
|
|
1347
|
+
: [];
|
|
1267
1348
|
const targetPaths = new Set();
|
|
1268
1349
|
for (const write of writes) {
|
|
1269
1350
|
const targetPath = path.resolve(write.filePath);
|
|
@@ -1288,15 +1369,16 @@ export async function pullDatabaseViewsToWorkspace(input) {
|
|
|
1288
1369
|
});
|
|
1289
1370
|
const previous = lock.databaseViews[write.manifest.stableKey];
|
|
1290
1371
|
const previousBaseline = previous?.environments[input.envName];
|
|
1372
|
+
const dependencyHash = databaseViewDependencyHash(write.manifest, sourceDatabases.databases, input.stableKeyName);
|
|
1291
1373
|
const entry = {
|
|
1292
1374
|
stableKey: write.manifest.stableKey,
|
|
1293
1375
|
path: toPortableRelativePath(projectRoot, write.filePath),
|
|
1294
1376
|
sourceHash: write.sourceHash,
|
|
1295
1377
|
environments: {
|
|
1296
1378
|
...(previous?.environments || {}),
|
|
1297
|
-
[input.envName]: previousBaseline?.remoteHash === write.remoteHash
|
|
1379
|
+
[input.envName]: previousBaseline?.remoteHash === write.remoteHash && previousBaseline.dependencyHash === dependencyHash
|
|
1298
1380
|
? previousBaseline
|
|
1299
|
-
: { remoteHash: write.remoteHash, syncedAt: new Date().toISOString() },
|
|
1381
|
+
: { remoteHash: write.remoteHash, syncedAt: new Date().toISOString(), dependencyHash },
|
|
1300
1382
|
},
|
|
1301
1383
|
};
|
|
1302
1384
|
if (!previous || hashStable(previous) !== hashStable(entry)) {
|
|
@@ -1304,6 +1386,11 @@ export async function pullDatabaseViewsToWorkspace(input) {
|
|
|
1304
1386
|
}
|
|
1305
1387
|
lock.databaseViews[write.manifest.stableKey] = entry;
|
|
1306
1388
|
}
|
|
1389
|
+
for (const removed of pruned) {
|
|
1390
|
+
removeRelocatedManifest(removed.manifestPath, root);
|
|
1391
|
+
delete lock.databaseViews[removed.stableKey];
|
|
1392
|
+
lockChanged = true;
|
|
1393
|
+
}
|
|
1307
1394
|
if (lockChanged) {
|
|
1308
1395
|
writeComponentLock(projectRoot, lock);
|
|
1309
1396
|
}
|
|
@@ -1312,6 +1399,7 @@ export async function pullDatabaseViewsToWorkspace(input) {
|
|
|
1312
1399
|
manifest: write.manifest,
|
|
1313
1400
|
targetPath: localTargetPath(input.cwd, write.filePath),
|
|
1314
1401
|
})),
|
|
1402
|
+
pruned: pruned.map(({ stableKey, targetPath }) => ({ stableKey, targetPath })),
|
|
1315
1403
|
skipped,
|
|
1316
1404
|
};
|
|
1317
1405
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type FieldChange } from '../diff-details.ts';
|
|
1
2
|
import type { RevoClient } from '../client.ts';
|
|
2
3
|
export declare const ENDPOINTS_DIRECTORY = "Endpoints";
|
|
3
4
|
export declare const ENDPOINT_MANIFEST_FILE = "endpoint.json";
|
|
@@ -31,6 +32,10 @@ export type EndpointPullResult = {
|
|
|
31
32
|
manifest: EndpointManifest;
|
|
32
33
|
targetPath: string;
|
|
33
34
|
}>;
|
|
35
|
+
pruned: Array<{
|
|
36
|
+
stableKey: string;
|
|
37
|
+
targetPath: string;
|
|
38
|
+
}>;
|
|
34
39
|
skipped: Array<{
|
|
35
40
|
targetPath: string;
|
|
36
41
|
reason: string;
|
|
@@ -39,6 +44,7 @@ export type EndpointPullResult = {
|
|
|
39
44
|
declare const ENDPOINT_PLAN_STATUS_ORDER: readonly ["create", "restore", "safe-update", "remote-changed", "conflict", "missing-lock", "restore-blocked", "collision", "clean", "orphan", "skipped"];
|
|
40
45
|
export type EndpointPlanStatus = typeof ENDPOINT_PLAN_STATUS_ORDER[number];
|
|
41
46
|
export type EndpointPlanItem = {
|
|
47
|
+
fieldChanges?: FieldChange[];
|
|
42
48
|
status: EndpointPlanStatus;
|
|
43
49
|
stableKey?: string;
|
|
44
50
|
name?: string;
|
|
@@ -51,8 +57,26 @@ export type EndpointPlanItem = {
|
|
|
51
57
|
label: string;
|
|
52
58
|
values: string;
|
|
53
59
|
}>;
|
|
60
|
+
dependencies?: EndpointDependencyEdge[];
|
|
61
|
+
routeDependencies?: string[];
|
|
54
62
|
targetRevisionHash?: string;
|
|
55
63
|
};
|
|
64
|
+
export type ProjectedEndpointComponentDependency = {
|
|
65
|
+
stableKey: string;
|
|
66
|
+
desiredHash: string;
|
|
67
|
+
state: 'ready' | 'pending-create' | 'pending-update' | 'pending-adopt';
|
|
68
|
+
};
|
|
69
|
+
export type EndpointDependencyReadiness = 'ready' | 'pending-component-create' | 'pending-component-update' | 'pending-component-adopt' | 'blocked';
|
|
70
|
+
export type EndpointDependencyEdge = {
|
|
71
|
+
relation: 'execution' | 'schema';
|
|
72
|
+
stableKey: string;
|
|
73
|
+
binding: 'latest' | 'pinned';
|
|
74
|
+
expectedHash: string;
|
|
75
|
+
projectedHash: string | null;
|
|
76
|
+
actualHash: string | null;
|
|
77
|
+
readiness: EndpointDependencyReadiness;
|
|
78
|
+
element?: string;
|
|
79
|
+
};
|
|
56
80
|
export type EndpointPushResult = {
|
|
57
81
|
stableKey: string;
|
|
58
82
|
action: 'create' | 'update' | 'restore' | 'noop' | 'orphan' | 'skipped';
|
|
@@ -66,6 +90,7 @@ export type EndpointPlan = {
|
|
|
66
90
|
env: string;
|
|
67
91
|
counts: Record<EndpointPlanStatus, number>;
|
|
68
92
|
blockers: string[];
|
|
93
|
+
warnings: string[];
|
|
69
94
|
items: EndpointPlanItem[];
|
|
70
95
|
exclusions: string[];
|
|
71
96
|
};
|
|
@@ -76,12 +101,14 @@ export declare function pullEndpointsToWorkspace(input: {
|
|
|
76
101
|
envName: string;
|
|
77
102
|
stableKeyName: string;
|
|
78
103
|
force?: boolean;
|
|
104
|
+
pruneOrphans?: boolean;
|
|
79
105
|
}): Promise<EndpointPullResult>;
|
|
80
106
|
export declare function buildEndpointsPlan(input: {
|
|
81
107
|
client: RevoClient;
|
|
82
108
|
cwd: string;
|
|
83
109
|
envName: string;
|
|
84
110
|
stableKeyName: string;
|
|
111
|
+
projectedComponents?: ProjectedEndpointComponentDependency[];
|
|
85
112
|
}): Promise<EndpointPlan>;
|
|
86
113
|
export declare function pushEndpoints(input: {
|
|
87
114
|
client: RevoClient;
|