@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
@@ -2,12 +2,14 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { ApiError } from "../client.js";
4
4
  import { hashStable, readComponentLock, writeComponentLock, } from "../component-lock.js";
5
- import { excludeDatabaseBackupArtifacts, isDatabaseBackupArtifact } from "../database-schema-artifacts.js";
5
+ import { excludeDatabaseBackupArtifacts, isDatabaseBackupArtifact } from "../database-table-artifacts.js";
6
6
  import { readConfiguredResourceMetadataStableKey, sanitizeUserMetadata } from "../resource-metadata.js";
7
7
  import { readJsonFile, sanitizeSegment } from "../utils.js";
8
8
  import { findManifestFiles, isRecord, localTargetPath, removeRelocatedManifest, requireProjectLayout, stableKeySuffix, toPortableRelativePath, unwrapData, writePulledManifest, } from "./util.js";
9
- export const DATABASE_SCHEMAS_DIRECTORY = 'DatabaseSchemas';
10
- export const DATABASE_SCHEMA_MANIFEST_FILE = 'database-schema.json';
9
+ export const DATABASE_SCHEMAS_DIRECTORY = 'DatabaseTables';
10
+ export const DATABASE_SCHEMA_MANIFEST_FILE = 'database-table.json';
11
+ const LEGACY_DATABASE_SCHEMAS_DIRECTORY = 'DatabaseSchemas';
12
+ const LEGACY_DATABASE_SCHEMA_MANIFEST_FILE = 'database-schema.json';
11
13
  const INSTANCE_FIELDS = new Set([
12
14
  'databaseId', 'databaseDefinitionId', 'id', 'version', 'revision', 'details', 'records',
13
15
  'createdAt', 'createdBy', 'lastUpdateAt', 'lastUpdateBy', 'updatedAt', 'updatedBy',
@@ -35,7 +37,12 @@ function canonicalValue(value, omitInstanceFields = false) {
35
37
  .map((key) => [key, canonicalValue(value[key], omitInstanceFields)]));
36
38
  }
37
39
  function portableDefinition(value) {
38
- const definition = canonicalValue(value, true);
40
+ const definition = {
41
+ ...canonicalValue(value, true),
42
+ // The Database Table write API requires this flag explicitly even though
43
+ // older/source records may omit it to mean the default value.
44
+ isIndex: isRecord(value) && value.isIndex === true,
45
+ };
39
46
  if (!Object.hasOwn(definition, 'metadata')) {
40
47
  return definition;
41
48
  }
@@ -181,7 +188,13 @@ function pathIdentity(filePath) {
181
188
  .join(path.sep);
182
189
  }
183
190
  function loadWorkspaceManifests(workspaceRoot) {
184
- return findManifestFiles(path.join(workspaceRoot, DATABASE_SCHEMAS_DIRECTORY), DATABASE_SCHEMA_MANIFEST_FILE)
191
+ const manifests = [
192
+ ...findManifestFiles(path.join(workspaceRoot, DATABASE_SCHEMAS_DIRECTORY), DATABASE_SCHEMA_MANIFEST_FILE),
193
+ ...findManifestFiles(path.join(workspaceRoot, DATABASE_SCHEMAS_DIRECTORY), LEGACY_DATABASE_SCHEMA_MANIFEST_FILE),
194
+ ...findManifestFiles(path.join(workspaceRoot, LEGACY_DATABASE_SCHEMAS_DIRECTORY), DATABASE_SCHEMA_MANIFEST_FILE),
195
+ ...findManifestFiles(path.join(workspaceRoot, LEGACY_DATABASE_SCHEMAS_DIRECTORY), LEGACY_DATABASE_SCHEMA_MANIFEST_FILE),
196
+ ];
197
+ return manifests
185
198
  .map((manifestPath) => ({
186
199
  manifestPath,
187
200
  manifest: readJsonFile(manifestPath),
@@ -286,6 +299,34 @@ function sizeRiskHint(size) {
286
299
  }
287
300
  return `Observed target size: ${size.total} bytes total (${size.table} table, ${size.indexes} indexes, ${size.audit} audit). Use it to choose the maintenance window and timeout for scans, rewrites, and index work.`;
288
301
  }
302
+ function isMigrationBlockingChange(change, stableKeyName, policy) {
303
+ if (change.risk !== 'manual') {
304
+ return false;
305
+ }
306
+ if (!policy?.sourceWins) {
307
+ return true;
308
+ }
309
+ if (change.kind === 'foreign-reference') {
310
+ return false;
311
+ }
312
+ if (change.kind === 'column-removed') {
313
+ return !policy.allowDestructive;
314
+ }
315
+ if (change.kind === 'column-added') {
316
+ return false;
317
+ }
318
+ if (change.kind === 'column-changed') {
319
+ return change.field.endsWith(`.metadata.${stableKeyName}`)
320
+ || change.field.endsWith('.isArray');
321
+ }
322
+ if (change.kind === 'immutable-field' && change.field === 'name') {
323
+ return false;
324
+ }
325
+ return true;
326
+ }
327
+ function hasMigrationBlockingChanges(item, stableKeyName, policy) {
328
+ return item.changes?.some((change) => isMigrationBlockingChange(change, stableKeyName, policy)) === true;
329
+ }
289
330
  function columnName(column) {
290
331
  return typeof column.name === 'string' ? column.name : '';
291
332
  }
@@ -680,7 +721,7 @@ function targetPlanCatalog(records, stableKeyName) {
680
721
  return { managed, unmanaged };
681
722
  }
682
723
  export async function buildDatabaseSchemasPlan(input) {
683
- const { projectRoot, workspaceRoot } = requireProjectLayout(input.cwd, 'Database Schema');
724
+ const { projectRoot, workspaceRoot } = requireProjectLayout(input.cwd, 'Database Table');
684
725
  const localEntries = loadWorkspaceManifests(workspaceRoot).filter((entry) => (input.skipPartitions !== true
685
726
  || !isRecord(entry.manifest)
686
727
  || entry.manifest.kind !== 'database-partition'));
@@ -722,7 +763,7 @@ export async function buildDatabaseSchemasPlan(input) {
722
763
  const errors = validatePlanManifest(entry.manifest, input.stableKeyName);
723
764
  if (errors.length > 0) {
724
765
  const relativePath = path.relative(projectRoot, entry.manifestPath);
725
- blockers.push(`Invalid Database Schema manifest ${relativePath}: ${errors.join('; ')}.`);
766
+ blockers.push(`Invalid Database Table manifest ${relativePath}: ${errors.join('; ')}.`);
726
767
  items.push({
727
768
  status: 'collision',
728
769
  name: isRecord(entry.manifest) && typeof entry.manifest.name === 'string'
@@ -764,7 +805,7 @@ export async function buildDatabaseSchemasPlan(input) {
764
805
  for (const stableKey of stableKeys) {
765
806
  duplicateLocalNames.add(stableKey);
766
807
  }
767
- blockers.push(`Duplicate desired physical Database Schema name "${name}" for Stable Keys: ${stableKeys.sort().join(', ')}.`);
808
+ blockers.push(`Duplicate desired physical Database Table name "${name}" for Stable Keys: ${stableKeys.sort().join(', ')}.`);
768
809
  }
769
810
  }
770
811
  for (const [stableKey, entries] of localByKey) {
@@ -805,7 +846,7 @@ export async function buildDatabaseSchemasPlan(input) {
805
846
  for (const [stableKey, entries] of localByKey) {
806
847
  const desired = portableDatabaseSchemaManifest(entries[0].manifest);
807
848
  if (entries.length > 1) {
808
- blockers.push(`Duplicate desired Database Schema stableKey "${stableKey}".`);
849
+ blockers.push(`Duplicate desired Database Table stableKey "${stableKey}".`);
809
850
  items.push({
810
851
  status: 'collision', stableKey, name: desired.name, kind: desired.kind,
811
852
  ...(desired.parentStableKey ? { parentStableKey: desired.parentStableKey } : {}),
@@ -824,7 +865,7 @@ export async function buildDatabaseSchemasPlan(input) {
824
865
  }
825
866
  const graphError = invalidLocalGraph.get(stableKey);
826
867
  if (graphError) {
827
- blockers.push(`Invalid desired Database Schema graph for "${stableKey}": ${graphError}.`);
868
+ blockers.push(`Invalid desired Database Table graph for "${stableKey}": ${graphError}.`);
828
869
  items.push({
829
870
  status: 'collision', stableKey, name: desired.name, kind: desired.kind,
830
871
  ...(desired.parentStableKey ? { parentStableKey: desired.parentStableKey } : {}),
@@ -849,7 +890,7 @@ export async function buildDatabaseSchemasPlan(input) {
849
890
  }
850
891
  if (matches.length > 1) {
851
892
  consumedTargetKeys.add(stableKey);
852
- blockers.push(`Duplicate target Database Schema stableKey "${stableKey}".`);
893
+ blockers.push(`Duplicate target Database Table stableKey "${stableKey}".`);
853
894
  items.push({
854
895
  status: 'collision', stableKey, name: desired.name, kind: desired.kind,
855
896
  ...(desired.parentStableKey ? { parentStableKey: desired.parentStableKey } : {}),
@@ -869,8 +910,8 @@ export async function buildDatabaseSchemasPlan(input) {
869
910
  consumedTargetKeys.add(collision.manifest.stableKey);
870
911
  }
871
912
  const reason = unmanagedNameCollisions.length > 0
872
- ? `target Database Schema with the same physical name is unmanaged because it is missing ${input.stableKeyName}`
873
- : `target Database Schema with the same physical name has a different ${input.stableKeyName}`;
913
+ ? `target Database Table with the same physical name is unmanaged because it is missing ${input.stableKeyName}`
914
+ : `target Database Table with the same physical name has a different ${input.stableKeyName}`;
874
915
  items.push({
875
916
  status: 'collision', stableKey, name: desired.name, kind: desired.kind, reason,
876
917
  ...(desired.parentStableKey ? { parentStableKey: desired.parentStableKey } : {}),
@@ -881,43 +922,48 @@ export async function buildDatabaseSchemasPlan(input) {
881
922
  }
882
923
  if (matches.length === 0) {
883
924
  const sourceRestricted = lock.databaseSchemas[stableKey]?.sourceRestricted;
884
- if (desired.kind === 'database-schema' && sourceRestricted !== false) {
925
+ if (desired.kind === 'database-schema'
926
+ && sourceRestricted === undefined
927
+ && input.migrationPolicy?.sourceWins !== true) {
885
928
  items.push({
886
929
  status: 'access-policy-required',
887
930
  stableKey,
888
931
  name: desired.name,
889
932
  kind: desired.kind,
890
- reason: sourceRestricted === true
891
- ? 'source root table is restricted and target ACL principals are intentionally not portable'
892
- : 'source root access policy is unknown because the lock predates policy capture',
933
+ reason: 'source root access policy is unknown because the lock predates policy capture',
893
934
  desiredHash: hashPortableDatabaseSchema(desired),
894
- hints: [
895
- sourceRestricted === true
896
- ? 'Do not create this table without an explicit target access-policy decision. Configure target ACL principals through the target-local workflow before reconciling this resource.'
897
- : 'Pull the source again to capture its access policy before creating this root table on the target.',
898
- ],
935
+ hints: ['Pull the source again to capture its access policy before creating this root table on the target.'],
899
936
  });
900
937
  continue;
901
938
  }
902
939
  const foreignReferences = desired.migration?.foreignReferences === 'manual'
903
940
  || hasForeignReferences(desired.definition || []);
941
+ const foreignReferencesBlockCreate = foreignReferences
942
+ && input.migrationPolicy?.sourceWins !== true;
904
943
  items.push({
905
- status: foreignReferences ? 'manual-schema-migration-required' : 'create',
944
+ status: foreignReferencesBlockCreate ? 'manual-schema-migration-required' : 'create',
906
945
  stableKey,
907
946
  name: desired.name,
908
947
  kind: desired.kind,
909
948
  ...(desired.parentStableKey ? { parentStableKey: desired.parentStableKey } : {}),
910
- reason: foreignReferences ? 'foreign references require manual deployment and verification' : 'desired resource is missing on target',
949
+ reason: foreignReferencesBlockCreate
950
+ ? 'foreign references require manual deployment and verification'
951
+ : 'desired resource is missing on target',
911
952
  desiredHash: hashPortableDatabaseSchema(desired),
912
953
  changes: foreignReferences ? [{
913
954
  kind: 'foreign-reference', field: 'definition.foreignReferences', risk: 'manual',
914
955
  hint: 'Create the table and enforce or verify its foreign relationships through an explicit migration; the API does not create SQL foreign-key constraints.',
915
956
  }] : undefined,
916
957
  hints: [foreignReferences
917
- ? 'Create and verify this table through a reviewed migration before reconciling its Stable Key.'
958
+ ? input.migrationPolicy?.sourceWins
959
+ ? 'Create the table from source, retain the foreign-reference declaration, and report that no physical SQL foreign-key constraint is enforced.'
960
+ : 'Create and verify this table through a reviewed migration before reconciling its Stable Key.'
918
961
  : desired.kind === 'database-partition'
919
962
  ? 'Create this partition only after its target parent exists, then verify its portable hash before recording the target lock baseline.'
920
- : 'Create this root table without records, verify its portable hash, then record the target lock baseline.'],
963
+ : 'Create this root table without records, verify its portable hash, then record the target lock baseline.',
964
+ ...(desired.kind === 'database-schema' && sourceRestricted === true
965
+ ? ['Create this table restricted with no ACL users or groups; assign target users and groups separately after migration.']
966
+ : [])],
921
967
  });
922
968
  continue;
923
969
  }
@@ -925,7 +971,10 @@ export async function buildDatabaseSchemasPlan(input) {
925
971
  const current = matches[0];
926
972
  const desiredHash = hashPortableDatabaseSchema(desired);
927
973
  const changes = diffDatabaseSchemas(desired, current.manifest, input.stableKeyName);
928
- if (changes.some((change) => change.kind === 'column-renamed')) {
974
+ if (changes.some((change) => (change.kind === 'column-renamed'
975
+ || change.kind === 'column-removed'
976
+ || (change.kind === 'column-changed'
977
+ && (change.field.endsWith('.type') || change.field.endsWith('.isArray')))))) {
929
978
  if (!databasesWithActiveViewDependencies) {
930
979
  const views = await input.client.listAllDatabaseViews();
931
980
  databasesWithActiveViewDependencies = new Set(views
@@ -1010,7 +1059,7 @@ export async function buildDatabaseSchemasPlan(input) {
1010
1059
  });
1011
1060
  continue;
1012
1061
  }
1013
- if (changes.some((change) => change.risk === 'manual')) {
1062
+ if (hasMigrationBlockingChanges({ changes }, input.stableKeyName, input.migrationPolicy)) {
1014
1063
  items.push({
1015
1064
  ...common,
1016
1065
  status: 'manual-schema-migration-required',
@@ -1035,7 +1084,7 @@ export async function buildDatabaseSchemasPlan(input) {
1035
1084
  continue;
1036
1085
  }
1037
1086
  if (matches.length > 1) {
1038
- blockers.push(`Duplicate target Database Schema stableKey "${stableKey}".`);
1087
+ blockers.push(`Duplicate target Database Table stableKey "${stableKey}".`);
1039
1088
  items.push({
1040
1089
  status: 'collision', stableKey, name: matches[0].manifest.name, kind: matches[0].manifest.kind,
1041
1090
  ...(matches[0].manifest.parentStableKey ? { parentStableKey: matches[0].manifest.parentStableKey } : {}),
@@ -1141,8 +1190,25 @@ export async function buildDatabaseSchemasPlan(input) {
1141
1190
  if (!input.withStats) {
1142
1191
  warnings.push('Table sizes were not fetched; use --with-stats for one cached bulk size request and more concrete DDL risk context.');
1143
1192
  }
1193
+ if (input.migrationPolicy?.sourceWins) {
1194
+ warnings.push('Source-wins migration policy is active: target content drift and supported DDL are overwritten from the pulled source snapshot.');
1195
+ if (items.some((item) => item.changes?.some((change) => change.kind === 'foreign-reference'))) {
1196
+ warnings.push('Foreign-reference declarations are copied as metadata, but the current backend does not create physical SQL foreign-key constraints.');
1197
+ }
1198
+ if (items.some((item) => item.changes?.some((change) => change.kind === 'column-removed'))) {
1199
+ warnings.push(input.migrationPolicy.allowDestructive
1200
+ ? 'Destructive column removal is enabled for this migration plan.'
1201
+ : 'Column removal requires --force because it can destroy target data.');
1202
+ }
1203
+ }
1204
+ if (items.some((item) => (item.status === 'create'
1205
+ && item.kind === 'database-schema'
1206
+ && item.stableKey
1207
+ && lock.databaseSchemas[item.stableKey]?.sourceRestricted === true))) {
1208
+ warnings.push('Restricted source tables will be created restricted without ACL users or groups; assign target users and groups separately after migration.');
1209
+ }
1144
1210
  return {
1145
- resourceType: 'database-schema',
1211
+ resourceType: 'database-table',
1146
1212
  env: input.envName,
1147
1213
  withStats: Boolean(input.withStats),
1148
1214
  skipPartitions: input.skipPartitions === true,
@@ -1151,7 +1217,7 @@ export async function buildDatabaseSchemasPlan(input) {
1151
1217
  warnings,
1152
1218
  exclusions: [
1153
1219
  'audit configuration and audit history are target-local',
1154
- 'ACL users, groups, and restricted policy are target-local',
1220
+ 'ACL users and groups are target-local; new root tables inherit the source restricted setting',
1155
1221
  'tags are target-local',
1156
1222
  'root schemas and unknown target-only partitions are never deleted by plan',
1157
1223
  ...(input.skipPartitions === true
@@ -1184,7 +1250,7 @@ function validateCatalog(records, stableKeyName, envName) {
1184
1250
  }
1185
1251
  const raw = rawStableKey(record, stableKeyName);
1186
1252
  if (raw.present && (typeof raw.value !== 'string' || !raw.value.trim())) {
1187
- throw new Error(`Invalid database-schema stableKey on ${id}; no files were changed.`);
1253
+ throw new Error(`Invalid database-table stableKey on ${id}; no files were changed.`);
1188
1254
  }
1189
1255
  const stableKey = configuredStableKey(record, stableKeyName);
1190
1256
  if (!stableKey) {
@@ -1192,7 +1258,7 @@ function validateCatalog(records, stableKeyName, envName) {
1192
1258
  continue;
1193
1259
  }
1194
1260
  if (entriesByKey.has(stableKey)) {
1195
- throw new Error(`Duplicate database-schema stableKey "${stableKey}" on ${envName}; no files were changed.`);
1261
+ throw new Error(`Duplicate database-table stableKey "${stableKey}" on ${envName}; no files were changed.`);
1196
1262
  }
1197
1263
  const entry = { record, id, stableKey, parentId: null };
1198
1264
  entriesById.set(id, entry);
@@ -1281,11 +1347,11 @@ function validateCatalog(records, stableKeyName, envName) {
1281
1347
  return { entries: [...entriesById.values()], entriesById, skipped };
1282
1348
  }
1283
1349
  export async function pullDatabaseSchemasToWorkspace(input) {
1284
- const { projectRoot, workspaceRoot } = requireProjectLayout(input.cwd, 'Database Schema');
1350
+ const { projectRoot, workspaceRoot } = requireProjectLayout(input.cwd, 'Database Table');
1285
1351
  const { databases } = await input.client.listAllDatabaseSchemas({ projection: 'pull' });
1286
1352
  const catalog = validateCatalog(databases, input.stableKeyName, input.envName);
1287
1353
  if (input.strict && catalog.skipped.length > 0) {
1288
- throw new Error(`Database Schema strict pull requires Stable Keys on all active resources; ${catalog.skipped.length} unmanaged resource(s) found.`);
1354
+ throw new Error(`Database Table strict pull requires Stable Keys on all active resources; ${catalog.skipped.length} unmanaged resource(s) found.`);
1289
1355
  }
1290
1356
  const manifestsById = new Map(catalog.entries.map((entry) => [entry.id, manifestFromEntry(entry, input.stableKeyName)]));
1291
1357
  const pathsById = new Map();
@@ -1307,16 +1373,16 @@ export async function pullDatabaseSchemasToWorkspace(input) {
1307
1373
  const identity = pathIdentity(resolvePath(entry));
1308
1374
  const owner = catalogPathOwners.get(identity);
1309
1375
  if (owner && owner !== entry.stableKey) {
1310
- throw new Error(`Database Schema workspace path collision for "${entry.stableKey}" and "${owner}"; no files were changed.`);
1376
+ throw new Error(`Database Table workspace path collision for "${entry.stableKey}" and "${owner}"; no files were changed.`);
1311
1377
  }
1312
1378
  catalogPathOwners.set(identity, entry.stableKey);
1313
1379
  }
1314
1380
  for (const local of loadWorkspaceManifests(workspaceRoot)) {
1315
1381
  if (!isRecord(local.manifest) || typeof local.manifest.stableKey !== 'string') {
1316
- throw new Error(`Invalid database-schema manifest ${path.relative(projectRoot, local.manifestPath)}; no files were changed.`);
1382
+ throw new Error(`Invalid database-table manifest ${path.relative(projectRoot, local.manifestPath)}; no files were changed.`);
1317
1383
  }
1318
1384
  if (existingByKey.has(local.manifest.stableKey)) {
1319
- throw new Error(`Duplicate local database-schema stableKey "${local.manifest.stableKey}"; no files were changed.`);
1385
+ throw new Error(`Duplicate local database-table stableKey "${local.manifest.stableKey}"; no files were changed.`);
1320
1386
  }
1321
1387
  existingByKey.set(local.manifest.stableKey, local);
1322
1388
  }
@@ -1364,13 +1430,13 @@ export async function pullDatabaseSchemasToWorkspace(input) {
1364
1430
  const identity = pathIdentity(write.filePath);
1365
1431
  const owner = pathOwners.get(identity);
1366
1432
  if (owner && owner !== write.manifest.stableKey) {
1367
- throw new Error(`Database Schema workspace path collision for "${write.manifest.stableKey}" and "${owner}"; no files were changed.`);
1433
+ throw new Error(`Database Table workspace path collision for "${write.manifest.stableKey}" and "${owner}"; no files were changed.`);
1368
1434
  }
1369
1435
  pathOwners.set(identity, write.manifest.stableKey);
1370
1436
  if (fs.existsSync(write.filePath)) {
1371
1437
  const local = readJsonFile(write.filePath);
1372
1438
  if (local.stableKey !== write.manifest.stableKey) {
1373
- throw new Error(`Database Schema workspace path is occupied by "${String(local.stableKey)}"; no files were changed.`);
1439
+ throw new Error(`Database Table workspace path is occupied by "${String(local.stableKey)}"; no files were changed.`);
1374
1440
  }
1375
1441
  }
1376
1442
  }
@@ -1379,8 +1445,9 @@ export async function pullDatabaseSchemasToWorkspace(input) {
1379
1445
  filePath: write.filePath,
1380
1446
  manifest: write.manifest,
1381
1447
  previousPath: write.previousPath,
1382
- root: path.join(workspaceRoot, DATABASE_SCHEMAS_DIRECTORY),
1448
+ root: workspaceRoot,
1383
1449
  force: input.force,
1450
+ legacyManifestNames: [LEGACY_DATABASE_SCHEMA_MANIFEST_FILE],
1384
1451
  });
1385
1452
  const previous = lock.databaseSchemas[write.manifest.stableKey];
1386
1453
  const entry = {
@@ -1399,7 +1466,7 @@ export async function pullDatabaseSchemasToWorkspace(input) {
1399
1466
  lock.databaseSchemas[write.manifest.stableKey] = entry;
1400
1467
  }
1401
1468
  for (const removed of pruned) {
1402
- removeRelocatedManifest(removed.manifestPath, path.join(workspaceRoot, DATABASE_SCHEMAS_DIRECTORY));
1469
+ removeRelocatedManifest(removed.manifestPath, workspaceRoot);
1403
1470
  delete lock.databaseSchemas[removed.stableKey];
1404
1471
  }
1405
1472
  if (writes.length > 0 || pruned.length > 0) {
@@ -1427,7 +1494,7 @@ export async function pullDatabaseSchemasToWorkspace(input) {
1427
1494
  class PartitionParentUnavailableError extends Error {
1428
1495
  }
1429
1496
  function readWorkspaceDatabaseSchemasForPush(cwd, stableKeyName) {
1430
- const { workspaceRoot } = requireProjectLayout(cwd, 'Database Schema');
1497
+ const { workspaceRoot } = requireProjectLayout(cwd, 'Database Table');
1431
1498
  const entriesByKey = new Map();
1432
1499
  for (const entry of loadWorkspaceManifests(workspaceRoot)) {
1433
1500
  const errors = validatePlanManifest(entry.manifest, stableKeyName);
@@ -1443,6 +1510,14 @@ function readWorkspaceDatabaseSchemasForPush(cwd, stableKeyName) {
1443
1510
  .filter(([, entries]) => entries.length === 1)
1444
1511
  .map(([stableKey, entries]) => [stableKey, entries[0]]));
1445
1512
  }
1513
+ export function readWorkspaceDatabaseSchemas(cwd, stableKeyName) {
1514
+ return [...readWorkspaceDatabaseSchemasForPush(cwd, stableKeyName).values()]
1515
+ .map(({ manifest, manifestPath }) => ({
1516
+ manifest,
1517
+ targetPath: localTargetPath(cwd, manifestPath),
1518
+ }))
1519
+ .sort((left, right) => left.manifest.stableKey.localeCompare(right.manifest.stableKey));
1520
+ }
1446
1521
  function createPayloadForDatabaseSchema(input) {
1447
1522
  const common = {
1448
1523
  name: input.manifest.name,
@@ -1467,7 +1542,7 @@ function createPayloadForDatabaseSchema(input) {
1467
1542
  ? {}
1468
1543
  : { partition: canonicalValue(input.manifest.partition, true) }),
1469
1544
  audit: false,
1470
- restricted: false,
1545
+ restricted: input.restricted === true,
1471
1546
  };
1472
1547
  }
1473
1548
  function createItemsInDependencyOrder(items, localByKey) {
@@ -1565,7 +1640,7 @@ function verifyCreatedDatabaseSchema(input) {
1565
1640
  return remoteHash;
1566
1641
  }
1567
1642
  function updateDatabaseSchemaEnvironmentBaseline(input) {
1568
- const { projectRoot } = requireProjectLayout(input.cwd, 'Database Schema');
1643
+ const { projectRoot } = requireProjectLayout(input.cwd, 'Database Table');
1569
1644
  const lock = readComponentLock(projectRoot);
1570
1645
  const existing = lock.databaseSchemas[input.manifest.stableKey];
1571
1646
  const entry = {
@@ -1596,21 +1671,21 @@ async function resolveLiveDatabaseSchemaWriteTarget(input) {
1596
1671
  const records = excludeDatabaseBackupArtifacts(input.records);
1597
1672
  const matches = records.filter((record) => configuredStableKey(record, input.stableKeyName) === input.stableKey);
1598
1673
  if (matches.length !== 1) {
1599
- throw new Error(`expected one live target Database Schema match, found ${matches.length}`);
1674
+ throw new Error(`expected one live target Database Table match, found ${matches.length}`);
1600
1675
  }
1601
1676
  const databaseId = databaseIdOf(matches[0]);
1602
1677
  if (!databaseId) {
1603
- throw new Error('live target Database Schema did not include databaseId');
1678
+ throw new Error('live target Database Table did not include databaseId');
1604
1679
  }
1605
1680
  const record = unwrapData(await input.client.getDatabaseSchema(databaseId));
1606
1681
  if (configuredStableKey(record, input.stableKeyName) !== input.stableKey) {
1607
- throw new Error(`live target Database Schema is missing or changed ${input.stableKeyName}`);
1682
+ throw new Error(`live target Database Table is missing or changed ${input.stableKeyName}`);
1608
1683
  }
1609
1684
  if (databaseIdOf(record) !== databaseId) {
1610
- throw new Error('live target Database Schema identity changed before write');
1685
+ throw new Error('live target Database Table identity changed before write');
1611
1686
  }
1612
1687
  if (typeof record.version !== 'number') {
1613
- throw new Error('live target Database Schema did not include a current version');
1688
+ throw new Error('live target Database Table did not include a current version');
1614
1689
  }
1615
1690
  const freshRecords = records.map((candidate) => databaseIdOf(candidate) === databaseId ? record : candidate);
1616
1691
  const resolved = resolveDatabaseSchemaManifestFromRecords({
@@ -1620,7 +1695,7 @@ async function resolveLiveDatabaseSchemaWriteTarget(input) {
1620
1695
  stableKeyName: input.stableKeyName,
1621
1696
  });
1622
1697
  if (resolved.hash !== input.expectedHash) {
1623
- throw new Error('target Database Schema changed after planning');
1698
+ throw new Error('target Database Table changed after planning');
1624
1699
  }
1625
1700
  return {
1626
1701
  databaseId,
@@ -1633,7 +1708,7 @@ async function resolveLiveDatabaseSchemaWriteTarget(input) {
1633
1708
  function replaceDatabaseSchemaRecord(records, replacement) {
1634
1709
  const databaseId = databaseIdOf(replacement);
1635
1710
  if (!databaseId) {
1636
- throw new Error('target Database Schema did not include databaseId');
1711
+ throw new Error('target Database Table did not include databaseId');
1637
1712
  }
1638
1713
  const existing = records.some((record) => databaseIdOf(record) === databaseId);
1639
1714
  return existing
@@ -1642,11 +1717,14 @@ function replaceDatabaseSchemaRecord(records, replacement) {
1642
1717
  }
1643
1718
  function buildDatabaseSchemaUpdatePayload(input) {
1644
1719
  if (typeof input.target.version !== 'number') {
1645
- throw new Error('live target Database Schema did not include a current version');
1720
+ throw new Error('live target Database Table did not include a current version');
1646
1721
  }
1647
1722
  const payload = {
1648
1723
  version: input.target.version,
1649
1724
  metadata: sanitizeUserMetadata(input.desired.metadata),
1725
+ ...(input.sourceWins === true && input.desired.name !== input.target.name
1726
+ ? { name: input.desired.name }
1727
+ : {}),
1650
1728
  ...(typeof input.desired.category === 'string' ? { category: input.desired.category } : {}),
1651
1729
  ...(input.desired.description === undefined
1652
1730
  ? (typeof input.target.desc === 'string' && input.target.desc ? { desc: '' } : {})
@@ -1683,7 +1761,7 @@ function buildDatabaseSchemaUpdatePayload(input) {
1683
1761
  const stableKey = columnStableKey(value, stableKeyName);
1684
1762
  const stableKeyTargets = stableKey ? targetDefinitionsByStableKey.get(stableKey) || [] : [];
1685
1763
  if (stableKey && (stableKeyTargets.length > 1 || (desiredStableKeyOwners.get(stableKey) || []).length > 1)) {
1686
- throw new Error(`column Stable Key "${stableKey}" is duplicated; refusing to update Database Schema definitions`);
1764
+ throw new Error(`column Stable Key "${stableKey}" is duplicated; refusing to update Database Table definitions`);
1687
1765
  }
1688
1766
  const namedTargets = targetDefinitionsByName.get(columnName(value)) || [];
1689
1767
  const namedTarget = namedTargets.length === 1 ? namedTargets[0] : undefined;
@@ -1829,11 +1907,11 @@ function resolveLiveOrphanRootDeleteTarget(input) {
1829
1907
  return target;
1830
1908
  }
1831
1909
  function recordDeletedPartitionTombstone(input) {
1832
- const { projectRoot } = requireProjectLayout(input.cwd, 'Database Schema');
1910
+ const { projectRoot } = requireProjectLayout(input.cwd, 'Database Table');
1833
1911
  const lock = readComponentLock(projectRoot);
1834
1912
  const existing = lock.databaseSchemas[input.stableKey];
1835
1913
  if (!existing) {
1836
- throw new Error('cannot record tombstone without an existing Database Schema lock entry');
1914
+ throw new Error('cannot record tombstone without an existing Database Table lock entry');
1837
1915
  }
1838
1916
  lock.databaseSchemas[input.stableKey] = {
1839
1917
  ...existing,
@@ -1854,7 +1932,7 @@ export async function pushDatabaseSchemas(input) {
1854
1932
  const plan = await buildDatabaseSchemasPlan(input);
1855
1933
  const localByKey = readWorkspaceDatabaseSchemasForPush(input.cwd, input.stableKeyName);
1856
1934
  if (input.stableKey && !localByKey.has(input.stableKey) && input.pruneOrphans !== true) {
1857
- throw new Error(`Database Schema Stable Key "${input.stableKey}" was not found in the workspace.`);
1935
+ throw new Error(`Database Table Stable Key "${input.stableKey}" was not found in the workspace.`);
1858
1936
  }
1859
1937
  const selected = (item) => !input.stableKey || item.stableKey === input.stableKey;
1860
1938
  const results = [];
@@ -1870,6 +1948,8 @@ export async function pushDatabaseSchemas(input) {
1870
1948
  const replaceTargetInventoryRecord = (record) => {
1871
1949
  targetInventory = replaceDatabaseSchemaRecord(targetInventory || [], record);
1872
1950
  };
1951
+ const { projectRoot } = requireProjectLayout(input.cwd, 'Database Table');
1952
+ const sourceLock = readComponentLock(projectRoot);
1873
1953
  const blockedCreateStatuses = new Set([
1874
1954
  'access-policy-required',
1875
1955
  'manual-schema-migration-required',
@@ -1929,7 +2009,11 @@ export async function pushDatabaseSchemas(input) {
1929
2009
  stableKeyName: input.stableKeyName,
1930
2010
  });
1931
2011
  lastMutation.at = Date.now();
1932
- const created = unwrapData(await input.client.createDatabaseSchema(createPayloadForDatabaseSchema({ manifest: desired, parentName: preflight.parentName })));
2012
+ const created = unwrapData(await input.client.createDatabaseSchema(createPayloadForDatabaseSchema({
2013
+ manifest: desired,
2014
+ parentName: preflight.parentName,
2015
+ restricted: sourceLock.databaseSchemas[stableKey]?.sourceRestricted === true,
2016
+ })));
1933
2017
  writeAccepted = true;
1934
2018
  const createdId = databaseIdOf(created);
1935
2019
  if (!createdId) {
@@ -2020,7 +2104,7 @@ export async function pushDatabaseSchemas(input) {
2020
2104
  expectedHash: item.currentHash,
2021
2105
  });
2022
2106
  }
2023
- if (item.changes?.some((change) => change.kind === 'column-renamed')) {
2107
+ if (item.changes?.some((change) => change.kind === 'database-view-dependency')) {
2024
2108
  await assertNoActiveDatabaseViewDependencies({
2025
2109
  client: input.client,
2026
2110
  databaseId: live.databaseId,
@@ -2032,6 +2116,7 @@ export async function pushDatabaseSchemas(input) {
2032
2116
  desired,
2033
2117
  target: live.record,
2034
2118
  stableKeyName: input.stableKeyName,
2119
+ sourceWins: input.migrationPolicy?.sourceWins,
2035
2120
  }));
2036
2121
  writeAccepted = true;
2037
2122
  if (live.record.audit === true) {
@@ -2057,7 +2142,7 @@ export async function pushDatabaseSchemas(input) {
2057
2142
  });
2058
2143
  }
2059
2144
  if (!live) {
2060
- throw new Error('live target Database Schema could not be resolved before verification');
2145
+ throw new Error('live target Database Table could not be resolved before verification');
2061
2146
  }
2062
2147
  const verified = unwrapData(await input.client.getDatabaseSchema(live.databaseId));
2063
2148
  const remoteHash = verifyDatabaseSchemaWrite({
@@ -2102,7 +2187,7 @@ export async function pushDatabaseSchemas(input) {
2102
2187
  const forcedContentDrift = (item) => (input.force === true
2103
2188
  && (item.status === 'missing-lock' || item.status === 'remote-changed' || item.status === 'conflict')
2104
2189
  && item.desiredHash !== item.currentHash
2105
- && !item.changes?.some((change) => change.risk === 'manual'));
2190
+ && !hasMigrationBlockingChanges(item, input.stableKeyName, input.migrationPolicy));
2106
2191
  for (const item of plan.items.filter((candidate) => (selected(candidate)
2107
2192
  && candidate.status === 'safe-update'))) {
2108
2193
  await processUpdate(item, 'update');
@@ -2131,7 +2216,7 @@ export async function pushDatabaseSchemas(input) {
2131
2216
  action: 'skipped',
2132
2217
  status: 'skipped',
2133
2218
  targetPath: localTargetPath(input.cwd, local.manifestPath),
2134
- reason: item.changes?.some((change) => change.risk === 'manual')
2219
+ reason: hasMigrationBlockingChanges(item, input.stableKeyName, input.migrationPolicy)
2135
2220
  ? 'one or more changes require an explicit DDL or data migration; --force cannot bypass it'
2136
2221
  : item.status === 'missing-lock'
2137
2222
  ? 'missing environment lock baseline; review the live target and re-run with --force to adopt an identical target or overwrite safe portable content only'
@@ -1,4 +1,6 @@
1
+ import { type FieldChange } from '../diff-details.ts';
1
2
  import type { RevoClient } from '../client.ts';
3
+ import type { DatabaseSchemaRecord } from '../types.ts';
2
4
  export declare const DATABASE_VIEWS_DIRECTORY = "DatabaseViews";
3
5
  export declare const DATABASE_VIEW_MANIFEST_FILE = "database-view.json";
4
6
  export type DatabaseViewSourceColumn = {
@@ -59,10 +61,22 @@ export type DatabaseViewPullResult = {
59
61
  manifest: DatabaseViewManifest;
60
62
  targetPath: string;
61
63
  }>;
64
+ pruned: Array<{
65
+ stableKey: string;
66
+ targetPath: string;
67
+ }>;
62
68
  skipped: DatabaseViewPullSkip[];
63
69
  };
64
- export type DatabaseViewPlanStatus = 'clean' | 'create' | 'safe-update' | 'remote-changed' | 'conflict' | 'missing-lock' | 'orphan' | 'collision' | 'skipped';
70
+ export type DatabaseViewMigrationPolicy = {
71
+ sourceWins: boolean;
72
+ allowDestructive: boolean;
73
+ deferPreview?: boolean;
74
+ allowActiveScheduleDependencies?: boolean;
75
+ };
76
+ export type DatabaseViewPlanStatus = 'clean' | 'create' | 'safe-update' | 'remote-changed' | 'conflict' | 'validation-failed' | 'missing-lock' | 'orphan' | 'collision' | 'skipped';
65
77
  export type DatabaseViewPlanItem = {
78
+ fieldChanges?: FieldChange[];
79
+ rawQueryDiff?: string[];
66
80
  status: DatabaseViewPlanStatus;
67
81
  stableKey?: string;
68
82
  name: string;
@@ -93,6 +107,11 @@ export type DatabaseViewPushResult = {
93
107
  error?: string;
94
108
  accessPolicyRequired?: boolean;
95
109
  };
110
+ type WorkspaceEntry = {
111
+ manifestPath: string;
112
+ manifest: DatabaseViewManifest;
113
+ };
114
+ export declare function readWorkspaceDatabaseViews(cwd: string): WorkspaceEntry[];
96
115
  export declare function hashPortableDatabaseView(manifest: DatabaseViewManifest): string;
97
116
  export declare function hashDatabaseViewManifest(manifest: DatabaseViewManifest): string;
98
117
  export declare function buildDatabaseViewsPlan(input: {
@@ -100,6 +119,8 @@ export declare function buildDatabaseViewsPlan(input: {
100
119
  cwd: string;
101
120
  envName: string;
102
121
  stableKeyName: string;
122
+ migrationPolicy?: DatabaseViewMigrationPolicy;
123
+ dependencyDatabases?: DatabaseSchemaRecord[];
103
124
  }): Promise<DatabaseViewsPlan>;
104
125
  export declare function pushDatabaseViews(input: {
105
126
  client: RevoClient;
@@ -108,7 +129,7 @@ export declare function pushDatabaseViews(input: {
108
129
  stableKeyName: string;
109
130
  stableKey?: string;
110
131
  force?: boolean;
111
- allowMaterializedWrites?: boolean;
132
+ migrationPolicy?: DatabaseViewMigrationPolicy;
112
133
  }): Promise<{
113
134
  plan: DatabaseViewsPlan;
114
135
  results: DatabaseViewPushResult[];
@@ -120,5 +141,6 @@ export declare function pullDatabaseViewsToWorkspace(input: {
120
141
  stableKeyName: string;
121
142
  force?: boolean;
122
143
  strict?: boolean;
144
+ pruneOrphans?: boolean;
123
145
  }): Promise<DatabaseViewPullResult>;
124
146
  export {};