@famgia/omnify-atlas 0.0.98 → 0.0.99

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.d.cts CHANGED
@@ -100,17 +100,42 @@ interface SchemaHash {
100
100
  }
101
101
  /**
102
102
  * Generated migration record.
103
+ * Enhanced for team development with file tracking and regeneration support.
104
+ * Note: timestamp, tableName, type are optional for backwards compatibility with v1 lock files.
103
105
  */
104
106
  interface GeneratedMigration {
105
- /** Migration file name */
107
+ /** Migration file name (e.g., "2026_01_13_100000_create_users_table.php") */
106
108
  readonly fileName: string;
107
- /** Timestamp when generated */
109
+ /** Migration timestamp prefix for regeneration (e.g., "2026_01_13_100000") - Optional for backwards compatibility */
110
+ readonly timestamp?: string | undefined;
111
+ /** Table name for lookup (e.g., "users") - Optional for backwards compatibility */
112
+ readonly tableName?: string | undefined;
113
+ /** Migration type - Optional for backwards compatibility */
114
+ readonly type?: 'create' | 'alter' | 'drop' | 'pivot' | undefined;
115
+ /** Timestamp when generated (ISO 8601) */
108
116
  readonly generatedAt: string;
109
117
  /** Schemas involved in this migration */
110
118
  readonly schemas: readonly string[];
111
- /** Migration checksum for integrity */
119
+ /** Migration content checksum (SHA-256) for integrity verification */
112
120
  readonly checksum: string;
113
121
  }
122
+ /**
123
+ * Migration validation result.
124
+ */
125
+ interface MigrationValidation {
126
+ /** Whether all migrations are valid */
127
+ readonly valid: boolean;
128
+ /** List of missing migration files */
129
+ readonly missingFiles: readonly string[];
130
+ /** List of migrations with checksum mismatch (file modified) */
131
+ readonly modifiedFiles: readonly string[];
132
+ /** List of stale migrations (old timestamp, recently added to repo) */
133
+ readonly staleFiles: readonly string[];
134
+ /** Total migrations tracked */
135
+ readonly totalTracked: number;
136
+ /** Total migrations found on disk */
137
+ readonly totalOnDisk: number;
138
+ }
114
139
  /**
115
140
  * Lock file structure for tracking schema state (v1 - legacy).
116
141
  */
@@ -221,12 +246,6 @@ interface LockFileComparison {
221
246
  readonly unchanged: readonly string[];
222
247
  }
223
248
 
224
- /**
225
- * @famgia/omnify-atlas - Lock File Management
226
- *
227
- * Manages the .omnify.lock file for tracking schema state.
228
- */
229
-
230
249
  /**
231
250
  * Default lock file name.
232
251
  */
@@ -305,6 +324,49 @@ declare function updateLockFileV1(existingLockFile: LockFile | null, currentHash
305
324
  * Adds a migration record to the lock file.
306
325
  */
307
326
  declare function addMigrationRecord(lockFile: LockFile, fileName: string, schemas: readonly string[], migrationContent: string): LockFile;
327
+ /**
328
+ * Adds an enhanced migration record to the lock file.
329
+ * Includes timestamp and tableName for regeneration support.
330
+ */
331
+ declare function addEnhancedMigrationRecord(lockFile: LockFile, options: {
332
+ fileName: string;
333
+ timestamp: string;
334
+ tableName: string;
335
+ type: 'create' | 'alter' | 'drop' | 'pivot';
336
+ schemas: readonly string[];
337
+ content: string;
338
+ }): LockFile;
339
+ /**
340
+ * Extracts timestamp from migration filename.
341
+ * @example "2026_01_13_100000_create_users_table.php" → "2026_01_13_100000"
342
+ */
343
+ declare function extractTimestampFromFilename(fileName: string): string | null;
344
+ /**
345
+ * Extracts table name from migration filename.
346
+ * @example "2026_01_13_100000_create_users_table.php" → "users"
347
+ */
348
+ declare function extractTableNameFromFilename(fileName: string): string | null;
349
+ /**
350
+ * Validates migration files against lock file records.
351
+ * Checks for missing files, modified files, and stale migrations.
352
+ */
353
+ declare function validateMigrations(lockFile: LockFile, migrationsDir: string): Promise<MigrationValidation>;
354
+ /**
355
+ * Finds migration record by table name.
356
+ * Useful for regenerating deleted migrations.
357
+ */
358
+ declare function findMigrationByTable(lockFile: LockFile, tableName: string, type?: 'create' | 'alter' | 'drop' | 'pivot'): GeneratedMigration | undefined;
359
+ /**
360
+ * Gets migrations that need to be regenerated (missing files).
361
+ * Returns migrations with their stored timestamps for consistent regeneration.
362
+ */
363
+ declare function getMigrationsToRegenerate(lockFile: LockFile, missingFiles: readonly string[]): Array<{
364
+ fileName: string;
365
+ timestamp: string;
366
+ tableName: string;
367
+ type: 'create' | 'alter' | 'drop' | 'pivot';
368
+ schemas: readonly string[];
369
+ }>;
308
370
 
309
371
  /**
310
372
  * @famgia/omnify-atlas - HCL Types
@@ -752,4 +814,4 @@ declare function formatPreview(preview: ChangePreview, format?: PreviewFormat):
752
814
  */
753
815
  declare function hasBlockingIssues(_preview: ChangePreview): boolean;
754
816
 
755
- export { type AtlasConfig, type AtlasDiffOptions, type AtlasDiffResult, type AtlasInspectResult, type AtlasResult, type AtlasVersion, type ChangePreview, type ChangeSeverity, type ChangeType, type ColumnChange, type DiffResult, type DiffSummary, type GeneratedMigration, type HclColumn, type HclEnum, type HclForeignKey, type HclGenerationOptions, type HclIndex, type HclSchema, type HclTable, type IndexChange, type IndexSnapshot, LOCK_FILE_NAME, LOCK_FILE_VERSION, type LockFile, type LockFileComparison, type LockFileV1, type LockFileV2, type ParsedStatement, type PreviewFormat, type PreviewOptions, type PropertySnapshot, type SchemaChange, type SchemaHash, type SchemaSnapshot, type SqlColumnType, type SqlOperationType, type TableChange, addMigrationRecord, applySchema, buildSchemaHashes, buildSchemaSnapshots, checkAtlasVersion, compareSchemas, compareSchemasDeep, computeHash, computeSchemaHash, createEmptyLockFile, diffHclSchemas, formatDiffSummary, formatPreview, generateHclSchema, generateHclTable, generatePreview, getPrimaryKeyType, getTimestampType, hasBlockingIssues, isLockFileV2, mapPropertyToSql, parseDiffOutput, previewSchemaChanges, propertyNameToColumnName, propertyToSnapshot, readLockFile, renderHcl, runAtlasDiff, schemaNameToTableName, schemaToSnapshot, updateLockFile, updateLockFileV1, validateHcl, writeLockFile };
817
+ export { type AtlasConfig, type AtlasDiffOptions, type AtlasDiffResult, type AtlasInspectResult, type AtlasResult, type AtlasVersion, type ChangePreview, type ChangeSeverity, type ChangeType, type ColumnChange, type DiffResult, type DiffSummary, type GeneratedMigration, type HclColumn, type HclEnum, type HclForeignKey, type HclGenerationOptions, type HclIndex, type HclSchema, type HclTable, type IndexChange, type IndexSnapshot, LOCK_FILE_NAME, LOCK_FILE_VERSION, type LockFile, type LockFileComparison, type LockFileV1, type LockFileV2, type MigrationValidation, type ParsedStatement, type PreviewFormat, type PreviewOptions, type PropertySnapshot, type SchemaChange, type SchemaHash, type SchemaSnapshot, type SqlColumnType, type SqlOperationType, type TableChange, addEnhancedMigrationRecord, addMigrationRecord, applySchema, buildSchemaHashes, buildSchemaSnapshots, checkAtlasVersion, compareSchemas, compareSchemasDeep, computeHash, computeSchemaHash, createEmptyLockFile, diffHclSchemas, extractTableNameFromFilename, extractTimestampFromFilename, findMigrationByTable, formatDiffSummary, formatPreview, generateHclSchema, generateHclTable, generatePreview, getMigrationsToRegenerate, getPrimaryKeyType, getTimestampType, hasBlockingIssues, isLockFileV2, mapPropertyToSql, parseDiffOutput, previewSchemaChanges, propertyNameToColumnName, propertyToSnapshot, readLockFile, renderHcl, runAtlasDiff, schemaNameToTableName, schemaToSnapshot, updateLockFile, updateLockFileV1, validateHcl, validateMigrations, writeLockFile };
package/dist/index.d.ts CHANGED
@@ -100,17 +100,42 @@ interface SchemaHash {
100
100
  }
101
101
  /**
102
102
  * Generated migration record.
103
+ * Enhanced for team development with file tracking and regeneration support.
104
+ * Note: timestamp, tableName, type are optional for backwards compatibility with v1 lock files.
103
105
  */
104
106
  interface GeneratedMigration {
105
- /** Migration file name */
107
+ /** Migration file name (e.g., "2026_01_13_100000_create_users_table.php") */
106
108
  readonly fileName: string;
107
- /** Timestamp when generated */
109
+ /** Migration timestamp prefix for regeneration (e.g., "2026_01_13_100000") - Optional for backwards compatibility */
110
+ readonly timestamp?: string | undefined;
111
+ /** Table name for lookup (e.g., "users") - Optional for backwards compatibility */
112
+ readonly tableName?: string | undefined;
113
+ /** Migration type - Optional for backwards compatibility */
114
+ readonly type?: 'create' | 'alter' | 'drop' | 'pivot' | undefined;
115
+ /** Timestamp when generated (ISO 8601) */
108
116
  readonly generatedAt: string;
109
117
  /** Schemas involved in this migration */
110
118
  readonly schemas: readonly string[];
111
- /** Migration checksum for integrity */
119
+ /** Migration content checksum (SHA-256) for integrity verification */
112
120
  readonly checksum: string;
113
121
  }
122
+ /**
123
+ * Migration validation result.
124
+ */
125
+ interface MigrationValidation {
126
+ /** Whether all migrations are valid */
127
+ readonly valid: boolean;
128
+ /** List of missing migration files */
129
+ readonly missingFiles: readonly string[];
130
+ /** List of migrations with checksum mismatch (file modified) */
131
+ readonly modifiedFiles: readonly string[];
132
+ /** List of stale migrations (old timestamp, recently added to repo) */
133
+ readonly staleFiles: readonly string[];
134
+ /** Total migrations tracked */
135
+ readonly totalTracked: number;
136
+ /** Total migrations found on disk */
137
+ readonly totalOnDisk: number;
138
+ }
114
139
  /**
115
140
  * Lock file structure for tracking schema state (v1 - legacy).
116
141
  */
@@ -221,12 +246,6 @@ interface LockFileComparison {
221
246
  readonly unchanged: readonly string[];
222
247
  }
223
248
 
224
- /**
225
- * @famgia/omnify-atlas - Lock File Management
226
- *
227
- * Manages the .omnify.lock file for tracking schema state.
228
- */
229
-
230
249
  /**
231
250
  * Default lock file name.
232
251
  */
@@ -305,6 +324,49 @@ declare function updateLockFileV1(existingLockFile: LockFile | null, currentHash
305
324
  * Adds a migration record to the lock file.
306
325
  */
307
326
  declare function addMigrationRecord(lockFile: LockFile, fileName: string, schemas: readonly string[], migrationContent: string): LockFile;
327
+ /**
328
+ * Adds an enhanced migration record to the lock file.
329
+ * Includes timestamp and tableName for regeneration support.
330
+ */
331
+ declare function addEnhancedMigrationRecord(lockFile: LockFile, options: {
332
+ fileName: string;
333
+ timestamp: string;
334
+ tableName: string;
335
+ type: 'create' | 'alter' | 'drop' | 'pivot';
336
+ schemas: readonly string[];
337
+ content: string;
338
+ }): LockFile;
339
+ /**
340
+ * Extracts timestamp from migration filename.
341
+ * @example "2026_01_13_100000_create_users_table.php" → "2026_01_13_100000"
342
+ */
343
+ declare function extractTimestampFromFilename(fileName: string): string | null;
344
+ /**
345
+ * Extracts table name from migration filename.
346
+ * @example "2026_01_13_100000_create_users_table.php" → "users"
347
+ */
348
+ declare function extractTableNameFromFilename(fileName: string): string | null;
349
+ /**
350
+ * Validates migration files against lock file records.
351
+ * Checks for missing files, modified files, and stale migrations.
352
+ */
353
+ declare function validateMigrations(lockFile: LockFile, migrationsDir: string): Promise<MigrationValidation>;
354
+ /**
355
+ * Finds migration record by table name.
356
+ * Useful for regenerating deleted migrations.
357
+ */
358
+ declare function findMigrationByTable(lockFile: LockFile, tableName: string, type?: 'create' | 'alter' | 'drop' | 'pivot'): GeneratedMigration | undefined;
359
+ /**
360
+ * Gets migrations that need to be regenerated (missing files).
361
+ * Returns migrations with their stored timestamps for consistent regeneration.
362
+ */
363
+ declare function getMigrationsToRegenerate(lockFile: LockFile, missingFiles: readonly string[]): Array<{
364
+ fileName: string;
365
+ timestamp: string;
366
+ tableName: string;
367
+ type: 'create' | 'alter' | 'drop' | 'pivot';
368
+ schemas: readonly string[];
369
+ }>;
308
370
 
309
371
  /**
310
372
  * @famgia/omnify-atlas - HCL Types
@@ -752,4 +814,4 @@ declare function formatPreview(preview: ChangePreview, format?: PreviewFormat):
752
814
  */
753
815
  declare function hasBlockingIssues(_preview: ChangePreview): boolean;
754
816
 
755
- export { type AtlasConfig, type AtlasDiffOptions, type AtlasDiffResult, type AtlasInspectResult, type AtlasResult, type AtlasVersion, type ChangePreview, type ChangeSeverity, type ChangeType, type ColumnChange, type DiffResult, type DiffSummary, type GeneratedMigration, type HclColumn, type HclEnum, type HclForeignKey, type HclGenerationOptions, type HclIndex, type HclSchema, type HclTable, type IndexChange, type IndexSnapshot, LOCK_FILE_NAME, LOCK_FILE_VERSION, type LockFile, type LockFileComparison, type LockFileV1, type LockFileV2, type ParsedStatement, type PreviewFormat, type PreviewOptions, type PropertySnapshot, type SchemaChange, type SchemaHash, type SchemaSnapshot, type SqlColumnType, type SqlOperationType, type TableChange, addMigrationRecord, applySchema, buildSchemaHashes, buildSchemaSnapshots, checkAtlasVersion, compareSchemas, compareSchemasDeep, computeHash, computeSchemaHash, createEmptyLockFile, diffHclSchemas, formatDiffSummary, formatPreview, generateHclSchema, generateHclTable, generatePreview, getPrimaryKeyType, getTimestampType, hasBlockingIssues, isLockFileV2, mapPropertyToSql, parseDiffOutput, previewSchemaChanges, propertyNameToColumnName, propertyToSnapshot, readLockFile, renderHcl, runAtlasDiff, schemaNameToTableName, schemaToSnapshot, updateLockFile, updateLockFileV1, validateHcl, writeLockFile };
817
+ export { type AtlasConfig, type AtlasDiffOptions, type AtlasDiffResult, type AtlasInspectResult, type AtlasResult, type AtlasVersion, type ChangePreview, type ChangeSeverity, type ChangeType, type ColumnChange, type DiffResult, type DiffSummary, type GeneratedMigration, type HclColumn, type HclEnum, type HclForeignKey, type HclGenerationOptions, type HclIndex, type HclSchema, type HclTable, type IndexChange, type IndexSnapshot, LOCK_FILE_NAME, LOCK_FILE_VERSION, type LockFile, type LockFileComparison, type LockFileV1, type LockFileV2, type MigrationValidation, type ParsedStatement, type PreviewFormat, type PreviewOptions, type PropertySnapshot, type SchemaChange, type SchemaHash, type SchemaSnapshot, type SqlColumnType, type SqlOperationType, type TableChange, addEnhancedMigrationRecord, addMigrationRecord, applySchema, buildSchemaHashes, buildSchemaSnapshots, checkAtlasVersion, compareSchemas, compareSchemasDeep, computeHash, computeSchemaHash, createEmptyLockFile, diffHclSchemas, extractTableNameFromFilename, extractTimestampFromFilename, findMigrationByTable, formatDiffSummary, formatPreview, generateHclSchema, generateHclTable, generatePreview, getMigrationsToRegenerate, getPrimaryKeyType, getTimestampType, hasBlockingIssues, isLockFileV2, mapPropertyToSql, parseDiffOutput, previewSchemaChanges, propertyNameToColumnName, propertyToSnapshot, readLockFile, renderHcl, runAtlasDiff, schemaNameToTableName, schemaToSnapshot, updateLockFile, updateLockFileV1, validateHcl, validateMigrations, writeLockFile };
package/dist/index.js CHANGED
@@ -431,6 +431,125 @@ function addMigrationRecord(lockFile, fileName, schemas, migrationContent) {
431
431
  migrations: [...lockFile.migrations, record]
432
432
  };
433
433
  }
434
+ function addEnhancedMigrationRecord(lockFile, options) {
435
+ const record = {
436
+ fileName: options.fileName,
437
+ timestamp: options.timestamp,
438
+ tableName: options.tableName,
439
+ type: options.type,
440
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
441
+ schemas: options.schemas,
442
+ checksum: computeHash(options.content)
443
+ };
444
+ return {
445
+ ...lockFile,
446
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
447
+ migrations: [...lockFile.migrations, record]
448
+ };
449
+ }
450
+ function extractTimestampFromFilename(fileName) {
451
+ const match = fileName.match(/^(\d{4}_\d{2}_\d{2}_\d{6})_/);
452
+ return match ? match[1] : null;
453
+ }
454
+ function extractTableNameFromFilename(fileName) {
455
+ const createMatch = fileName.match(/_create_(.+)_table\.php$/);
456
+ if (createMatch) return createMatch[1];
457
+ const updateMatch = fileName.match(/_update_(.+)_table\.php$/);
458
+ if (updateMatch) return updateMatch[1];
459
+ const dropMatch = fileName.match(/_drop_(.+)_table\.php$/);
460
+ if (dropMatch) return dropMatch[1];
461
+ return null;
462
+ }
463
+ async function validateMigrations(lockFile, migrationsDir) {
464
+ const missingFiles = [];
465
+ const modifiedFiles = [];
466
+ const staleFiles = [];
467
+ let filesOnDisk = [];
468
+ try {
469
+ const { readdirSync } = await import("fs");
470
+ filesOnDisk = readdirSync(migrationsDir).filter((f) => f.endsWith(".php"));
471
+ } catch {
472
+ }
473
+ const filesOnDiskSet = new Set(filesOnDisk);
474
+ for (const migration of lockFile.migrations) {
475
+ const fileName = migration.fileName;
476
+ if (!filesOnDiskSet.has(fileName)) {
477
+ missingFiles.push(fileName);
478
+ continue;
479
+ }
480
+ if (migration.checksum) {
481
+ try {
482
+ const { readFileSync } = await import("fs");
483
+ const { join: join3 } = await import("path");
484
+ const content = readFileSync(join3(migrationsDir, fileName), "utf8");
485
+ const currentChecksum = computeHash(content);
486
+ if (currentChecksum !== migration.checksum) {
487
+ modifiedFiles.push(fileName);
488
+ }
489
+ } catch {
490
+ }
491
+ }
492
+ }
493
+ const trackedFileNames = new Set(lockFile.migrations.map((m) => m.fileName));
494
+ const now = /* @__PURE__ */ new Date();
495
+ for (const fileName of filesOnDisk) {
496
+ if (!trackedFileNames.has(fileName)) {
497
+ const timestamp = extractTimestampFromFilename(fileName);
498
+ if (timestamp) {
499
+ const [year, month, day] = timestamp.split("_").slice(0, 3).map(Number);
500
+ const fileDate = new Date(year, month - 1, day);
501
+ const daysDiff = (now.getTime() - fileDate.getTime()) / (1e3 * 60 * 60 * 24);
502
+ if (daysDiff > 7) {
503
+ staleFiles.push(fileName);
504
+ }
505
+ }
506
+ }
507
+ }
508
+ return {
509
+ valid: missingFiles.length === 0 && modifiedFiles.length === 0,
510
+ missingFiles,
511
+ modifiedFiles,
512
+ staleFiles,
513
+ totalTracked: lockFile.migrations.length,
514
+ totalOnDisk: filesOnDisk.length
515
+ };
516
+ }
517
+ function findMigrationByTable(lockFile, tableName, type) {
518
+ return lockFile.migrations.find((m) => {
519
+ const mig = m;
520
+ if (mig.tableName) {
521
+ return mig.tableName === tableName && (!type || mig.type === type);
522
+ }
523
+ const extractedTable = extractTableNameFromFilename(m.fileName);
524
+ return extractedTable === tableName;
525
+ });
526
+ }
527
+ function getMigrationsToRegenerate(lockFile, missingFiles) {
528
+ const missingSet = new Set(missingFiles);
529
+ const result = [];
530
+ for (const migration of lockFile.migrations) {
531
+ if (!missingSet.has(migration.fileName)) continue;
532
+ const mig = migration;
533
+ const timestamp = mig.timestamp ?? extractTimestampFromFilename(migration.fileName);
534
+ if (!timestamp) continue;
535
+ const tableName = mig.tableName ?? extractTableNameFromFilename(migration.fileName);
536
+ if (!tableName) continue;
537
+ let type = mig.type ?? "create";
538
+ if (!mig.type) {
539
+ if (migration.fileName.includes("_create_")) type = "create";
540
+ else if (migration.fileName.includes("_update_")) type = "alter";
541
+ else if (migration.fileName.includes("_drop_")) type = "drop";
542
+ }
543
+ result.push({
544
+ fileName: migration.fileName,
545
+ timestamp,
546
+ tableName,
547
+ type,
548
+ schemas: migration.schemas
549
+ });
550
+ }
551
+ return result;
552
+ }
434
553
 
435
554
  // src/hcl/type-mapper.ts
436
555
  var MYSQL_TYPES = {
@@ -1591,6 +1710,7 @@ function hasBlockingIssues(_preview) {
1591
1710
  export {
1592
1711
  LOCK_FILE_NAME,
1593
1712
  LOCK_FILE_VERSION,
1713
+ addEnhancedMigrationRecord,
1594
1714
  addMigrationRecord,
1595
1715
  applySchema,
1596
1716
  buildSchemaHashes,
@@ -1602,11 +1722,15 @@ export {
1602
1722
  computeSchemaHash,
1603
1723
  createEmptyLockFile,
1604
1724
  diffHclSchemas,
1725
+ extractTableNameFromFilename,
1726
+ extractTimestampFromFilename,
1727
+ findMigrationByTable,
1605
1728
  formatDiffSummary,
1606
1729
  formatPreview,
1607
1730
  generateHclSchema,
1608
1731
  generateHclTable,
1609
1732
  generatePreview,
1733
+ getMigrationsToRegenerate,
1610
1734
  getPrimaryKeyType,
1611
1735
  getTimestampType,
1612
1736
  hasBlockingIssues,
@@ -1624,6 +1748,7 @@ export {
1624
1748
  updateLockFile,
1625
1749
  updateLockFileV1,
1626
1750
  validateHcl,
1751
+ validateMigrations,
1627
1752
  writeLockFile
1628
1753
  };
1629
1754
  //# sourceMappingURL=index.js.map