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