@famgia/omnify-cli 0.0.123 → 0.0.128

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/dist/index.js CHANGED
@@ -886,7 +886,10 @@ import {
886
886
  compareSchemasDeep,
887
887
  isLockFileV2,
888
888
  validateMigrations,
889
- getMigrationsToRegenerate
889
+ getMigrationsToRegenerate,
890
+ VERSION_CHAIN_FILE,
891
+ readVersionChain,
892
+ checkBulkLockViolation
890
893
  } from "@famgia/omnify-atlas";
891
894
  import {
892
895
  generateMigrations,
@@ -1512,6 +1515,42 @@ async function runGenerate(options) {
1512
1515
  const currentSnapshots = await buildSchemaSnapshots(schemas);
1513
1516
  const v2Lock = existingLock && isLockFileV2(existingLock) ? existingLock : null;
1514
1517
  const comparison = compareSchemasDeep(currentSnapshots, v2Lock);
1518
+ const chainFilePath = resolve7(rootDir, VERSION_CHAIN_FILE);
1519
+ const versionChain = await readVersionChain(chainFilePath);
1520
+ if (versionChain && comparison.hasChanges) {
1521
+ const schemaActions = [];
1522
+ for (const change of comparison.changes) {
1523
+ if (change.changeType === "removed") {
1524
+ schemaActions.push({ name: change.schemaName, action: "delete" });
1525
+ } else if (change.changeType === "modified") {
1526
+ schemaActions.push({ name: change.schemaName, action: "modify" });
1527
+ }
1528
+ }
1529
+ if (schemaActions.length > 0) {
1530
+ const lockCheck = checkBulkLockViolation(versionChain, schemaActions);
1531
+ if (!lockCheck.allowed) {
1532
+ logger.newline();
1533
+ logger.error("\u{1F512} VERSION LOCK VIOLATION DETECTED");
1534
+ logger.error("");
1535
+ logger.error("The following schemas are locked in production:");
1536
+ for (const name of lockCheck.affectedSchemas) {
1537
+ logger.error(` \u2022 ${name}`);
1538
+ }
1539
+ logger.error("");
1540
+ logger.error(`Locked in version(s): ${lockCheck.lockedInVersions.join(", ")}`);
1541
+ logger.error("");
1542
+ logger.error("These schemas CANNOT be modified or deleted.");
1543
+ logger.error("This is enforced by the blockchain-like version chain.");
1544
+ logger.newline();
1545
+ throw new OmnifyError4(
1546
+ lockCheck.reason ?? "Schema modification blocked by version lock",
1547
+ "E407",
1548
+ void 0,
1549
+ "Restore the original schema files or create new schemas instead of modifying locked ones."
1550
+ );
1551
+ }
1552
+ }
1553
+ }
1515
1554
  if (existingLock && config.output.laravel?.migrationsPath) {
1516
1555
  const migrationsDir = resolve7(rootDir, config.output.laravel.migrationsPath);
1517
1556
  const migrationValidation = await validateMigrations(existingLock, migrationsDir);