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