@famgia/omnify-cli 2.0.44 → 2.0.45

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
@@ -1400,6 +1400,16 @@ function getCliVersion() {
1400
1400
  function hasPluginGenerators(plugins) {
1401
1401
  return plugins.some((p) => p.generators && p.generators.length > 0);
1402
1402
  }
1403
+ function toTableName(schemaName) {
1404
+ const snake = schemaName.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
1405
+ if (snake.endsWith("y") && !["ay", "ey", "iy", "oy", "uy"].some((v) => snake.endsWith(v))) {
1406
+ return snake.slice(0, -1) + "ies";
1407
+ }
1408
+ if (snake.endsWith("s") || snake.endsWith("x") || snake.endsWith("ch") || snake.endsWith("sh")) {
1409
+ return snake + "es";
1410
+ }
1411
+ return snake + "s";
1412
+ }
1403
1413
  function getExistingMigrationTables(migrationsDir) {
1404
1414
  const existingTables = /* @__PURE__ */ new Set();
1405
1415
  if (!existsSync9(migrationsDir)) {
@@ -2393,7 +2403,37 @@ async function runGenerate(options) {
2393
2403
  allMigrationRecords = counts.migrationRecords;
2394
2404
  }
2395
2405
  logger.step("Updating lock file...");
2396
- let newLockFile = updateLockFile(existingLock, currentSnapshots, config.database.driver);
2406
+ const migratedSchemas = /* @__PURE__ */ new Set();
2407
+ for (const record of allMigrationRecords) {
2408
+ for (const schemaName of record.schemas) {
2409
+ migratedSchemas.add(schemaName);
2410
+ }
2411
+ }
2412
+ const modifiedWithoutMigration = [];
2413
+ for (const change of comparison.changes) {
2414
+ if (change.changeType === "modified") {
2415
+ const hasMigration = migratedSchemas.has(change.schemaName) || // Also check if there's an ALTER migration by table name
2416
+ allMigrationRecords.some(
2417
+ (r) => r.type === "alter" && r.tableName === toTableName(change.schemaName)
2418
+ );
2419
+ if (!hasMigration) {
2420
+ modifiedWithoutMigration.push(change.schemaName);
2421
+ logger.warn(`\u26A0\uFE0F Schema '${change.schemaName}' was modified but no ALTER migration was generated.`);
2422
+ }
2423
+ }
2424
+ }
2425
+ let snapshotsToUpdate = currentSnapshots;
2426
+ if (modifiedWithoutMigration.length > 0 && existingLock && isLockFileV2(existingLock)) {
2427
+ logger.warn("Keeping old state for schemas without migrations to ensure they are detected on next run.");
2428
+ snapshotsToUpdate = { ...currentSnapshots };
2429
+ for (const schemaName of modifiedWithoutMigration) {
2430
+ if (existingLock.schemas[schemaName]) {
2431
+ snapshotsToUpdate[schemaName] = existingLock.schemas[schemaName];
2432
+ logger.debug(` Keeping old state for: ${schemaName}`);
2433
+ }
2434
+ }
2435
+ }
2436
+ let newLockFile = updateLockFile(existingLock, snapshotsToUpdate, config.database.driver);
2397
2437
  if (allMigrationRecords.length > 0) {
2398
2438
  logger.debug(`Adding ${allMigrationRecords.length} migration(s) to lock file...`);
2399
2439
  for (const record of allMigrationRecords) {