@famgia/omnify-cli 2.0.41 → 2.0.43

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.cjs CHANGED
@@ -2032,7 +2032,54 @@ async function runGenerate(options) {
2032
2032
  const existingLock = await (0, import_omnify_atlas2.readLockFile)(lockPath);
2033
2033
  const currentSnapshots = await (0, import_omnify_atlas2.buildSchemaSnapshots)(schemas);
2034
2034
  const v2Lock = existingLock && (0, import_omnify_atlas2.isLockFileV2)(existingLock) ? existingLock : null;
2035
- const comparison = (0, import_omnify_atlas2.compareSchemasDeep)(currentSnapshots, v2Lock);
2035
+ let comparison = (0, import_omnify_atlas2.compareSchemasDeep)(currentSnapshots, v2Lock);
2036
+ if (existingLock && !(0, import_omnify_atlas2.isLockFileV2)(existingLock) && existingLock.schemas) {
2037
+ logger.debug("Detected v1 lock file format - performing hash-based comparison");
2038
+ const v1Schemas = existingLock.schemas;
2039
+ const modifiedInV1 = /* @__PURE__ */ new Set();
2040
+ for (const [name, v1Schema] of Object.entries(v1Schemas)) {
2041
+ const currentSnapshot = currentSnapshots[name];
2042
+ if (currentSnapshot && v1Schema.hash !== currentSnapshot.hash) {
2043
+ modifiedInV1.add(name);
2044
+ logger.debug(` Schema ${name}: hash changed (v1 migration)`);
2045
+ }
2046
+ }
2047
+ if (modifiedInV1.size > 0) {
2048
+ const updatedChanges = [];
2049
+ for (const change of comparison.changes) {
2050
+ if (change.changeType === "added" && modifiedInV1.has(change.schemaName)) {
2051
+ const currentSnapshot = currentSnapshots[change.schemaName];
2052
+ if (currentSnapshot) {
2053
+ const columnChanges = [];
2054
+ for (const [propName, propDef] of Object.entries(currentSnapshot.properties)) {
2055
+ columnChanges.push({
2056
+ column: propName,
2057
+ changeType: "added",
2058
+ currentDef: propDef
2059
+ });
2060
+ }
2061
+ updatedChanges.push({
2062
+ schemaName: change.schemaName,
2063
+ changeType: "modified",
2064
+ previousHash: v1Schemas[change.schemaName]?.hash,
2065
+ currentHash: currentSnapshot.hash,
2066
+ columnChanges: columnChanges.length > 0 ? columnChanges : void 0
2067
+ });
2068
+ logger.info(` \u2022 ${change.schemaName}: upgrading from v1 lock file (will generate ALTER migration)`);
2069
+ } else {
2070
+ updatedChanges.push(change);
2071
+ }
2072
+ } else {
2073
+ updatedChanges.push(change);
2074
+ }
2075
+ }
2076
+ comparison = {
2077
+ hasChanges: updatedChanges.length > 0 || comparison.unchanged.length !== Object.keys(currentSnapshots).length,
2078
+ changes: updatedChanges,
2079
+ unchanged: comparison.unchanged
2080
+ };
2081
+ }
2082
+ }
2036
2083
  const chainFilePath = (0, import_node_path9.resolve)(rootDir, import_omnify_atlas2.VERSION_CHAIN_FILE);
2037
2084
  const versionChain = await (0, import_omnify_atlas2.readVersionChain)(chainFilePath);
2038
2085
  if (versionChain && comparison.hasChanges) {
@@ -2140,14 +2187,12 @@ async function runGenerate(options) {
2140
2187
  }
2141
2188
  }
2142
2189
  for (const migData of createMigrations) {
2143
- const migrationSchemas = Object.fromEntries(
2144
- Object.entries(schemas).filter(([name]) => migData.schemas.includes(name))
2145
- );
2146
- if (Object.keys(migrationSchemas).length === 0) {
2190
+ const schemaExists = migData.schemas.some((name) => name in schemas);
2191
+ if (!schemaExists) {
2147
2192
  logger.warn(` Cannot regenerate ${migData.fileName}: schema not found`);
2148
2193
  continue;
2149
2194
  }
2150
- const regenerated = (0, import_omnify_laravel.generateMigrations)(migrationSchemas, {
2195
+ const regenerated = (0, import_omnify_laravel.generateMigrations)(schemas, {
2151
2196
  timestamp: migData.timestamp,
2152
2197
  customTypes: customTypesMap2
2153
2198
  });