@famgia/omnify-atlas 0.0.97 → 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.cjs +142 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -10
- package/dist/index.d.ts +80 -10
- package/dist/index.js +126 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -26,6 +26,14 @@ interface PropertySnapshot {
|
|
|
26
26
|
readonly onUpdate?: string | undefined;
|
|
27
27
|
readonly mappedBy?: string | undefined;
|
|
28
28
|
readonly joinTable?: string | undefined;
|
|
29
|
+
/** Pivot table fields for ManyToMany relationships */
|
|
30
|
+
readonly pivotFields?: Record<string, {
|
|
31
|
+
type: string;
|
|
32
|
+
nullable?: boolean;
|
|
33
|
+
default?: unknown;
|
|
34
|
+
length?: number;
|
|
35
|
+
unsigned?: boolean;
|
|
36
|
+
}> | undefined;
|
|
29
37
|
readonly renamedFrom?: string | undefined;
|
|
30
38
|
/** Laravel: hidden in serialization */
|
|
31
39
|
readonly hidden?: boolean | undefined;
|
|
@@ -92,17 +100,42 @@ interface SchemaHash {
|
|
|
92
100
|
}
|
|
93
101
|
/**
|
|
94
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.
|
|
95
105
|
*/
|
|
96
106
|
interface GeneratedMigration {
|
|
97
|
-
/** Migration file name */
|
|
107
|
+
/** Migration file name (e.g., "2026_01_13_100000_create_users_table.php") */
|
|
98
108
|
readonly fileName: string;
|
|
99
|
-
/**
|
|
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) */
|
|
100
116
|
readonly generatedAt: string;
|
|
101
117
|
/** Schemas involved in this migration */
|
|
102
118
|
readonly schemas: readonly string[];
|
|
103
|
-
/** Migration checksum for integrity */
|
|
119
|
+
/** Migration content checksum (SHA-256) for integrity verification */
|
|
104
120
|
readonly checksum: string;
|
|
105
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
|
+
}
|
|
106
139
|
/**
|
|
107
140
|
* Lock file structure for tracking schema state (v1 - legacy).
|
|
108
141
|
*/
|
|
@@ -213,12 +246,6 @@ interface LockFileComparison {
|
|
|
213
246
|
readonly unchanged: readonly string[];
|
|
214
247
|
}
|
|
215
248
|
|
|
216
|
-
/**
|
|
217
|
-
* @famgia/omnify-atlas - Lock File Management
|
|
218
|
-
*
|
|
219
|
-
* Manages the .omnify.lock file for tracking schema state.
|
|
220
|
-
*/
|
|
221
|
-
|
|
222
249
|
/**
|
|
223
250
|
* Default lock file name.
|
|
224
251
|
*/
|
|
@@ -297,6 +324,49 @@ declare function updateLockFileV1(existingLockFile: LockFile | null, currentHash
|
|
|
297
324
|
* Adds a migration record to the lock file.
|
|
298
325
|
*/
|
|
299
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
|
+
}>;
|
|
300
370
|
|
|
301
371
|
/**
|
|
302
372
|
* @famgia/omnify-atlas - HCL Types
|
|
@@ -744,4 +814,4 @@ declare function formatPreview(preview: ChangePreview, format?: PreviewFormat):
|
|
|
744
814
|
*/
|
|
745
815
|
declare function hasBlockingIssues(_preview: ChangePreview): boolean;
|
|
746
816
|
|
|
747
|
-
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
|
@@ -26,6 +26,14 @@ interface PropertySnapshot {
|
|
|
26
26
|
readonly onUpdate?: string | undefined;
|
|
27
27
|
readonly mappedBy?: string | undefined;
|
|
28
28
|
readonly joinTable?: string | undefined;
|
|
29
|
+
/** Pivot table fields for ManyToMany relationships */
|
|
30
|
+
readonly pivotFields?: Record<string, {
|
|
31
|
+
type: string;
|
|
32
|
+
nullable?: boolean;
|
|
33
|
+
default?: unknown;
|
|
34
|
+
length?: number;
|
|
35
|
+
unsigned?: boolean;
|
|
36
|
+
}> | undefined;
|
|
29
37
|
readonly renamedFrom?: string | undefined;
|
|
30
38
|
/** Laravel: hidden in serialization */
|
|
31
39
|
readonly hidden?: boolean | undefined;
|
|
@@ -92,17 +100,42 @@ interface SchemaHash {
|
|
|
92
100
|
}
|
|
93
101
|
/**
|
|
94
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.
|
|
95
105
|
*/
|
|
96
106
|
interface GeneratedMigration {
|
|
97
|
-
/** Migration file name */
|
|
107
|
+
/** Migration file name (e.g., "2026_01_13_100000_create_users_table.php") */
|
|
98
108
|
readonly fileName: string;
|
|
99
|
-
/**
|
|
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) */
|
|
100
116
|
readonly generatedAt: string;
|
|
101
117
|
/** Schemas involved in this migration */
|
|
102
118
|
readonly schemas: readonly string[];
|
|
103
|
-
/** Migration checksum for integrity */
|
|
119
|
+
/** Migration content checksum (SHA-256) for integrity verification */
|
|
104
120
|
readonly checksum: string;
|
|
105
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
|
+
}
|
|
106
139
|
/**
|
|
107
140
|
* Lock file structure for tracking schema state (v1 - legacy).
|
|
108
141
|
*/
|
|
@@ -213,12 +246,6 @@ interface LockFileComparison {
|
|
|
213
246
|
readonly unchanged: readonly string[];
|
|
214
247
|
}
|
|
215
248
|
|
|
216
|
-
/**
|
|
217
|
-
* @famgia/omnify-atlas - Lock File Management
|
|
218
|
-
*
|
|
219
|
-
* Manages the .omnify.lock file for tracking schema state.
|
|
220
|
-
*/
|
|
221
|
-
|
|
222
249
|
/**
|
|
223
250
|
* Default lock file name.
|
|
224
251
|
*/
|
|
@@ -297,6 +324,49 @@ declare function updateLockFileV1(existingLockFile: LockFile | null, currentHash
|
|
|
297
324
|
* Adds a migration record to the lock file.
|
|
298
325
|
*/
|
|
299
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
|
+
}>;
|
|
300
370
|
|
|
301
371
|
/**
|
|
302
372
|
* @famgia/omnify-atlas - HCL Types
|
|
@@ -744,4 +814,4 @@ declare function formatPreview(preview: ChangePreview, format?: PreviewFormat):
|
|
|
744
814
|
*/
|
|
745
815
|
declare function hasBlockingIssues(_preview: ChangePreview): boolean;
|
|
746
816
|
|
|
747
|
-
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
|
@@ -43,6 +43,7 @@ function propertyToSnapshot(property) {
|
|
|
43
43
|
onUpdate: prop.onUpdate,
|
|
44
44
|
mappedBy: prop.mappedBy,
|
|
45
45
|
joinTable: prop.joinTable,
|
|
46
|
+
pivotFields: prop.pivotFields,
|
|
46
47
|
// renamedFrom is kept in snapshot for comparison (rename detection),
|
|
47
48
|
// but will be stripped when writing to lock file.
|
|
48
49
|
renamedFrom: prop.renamedFrom,
|
|
@@ -430,6 +431,125 @@ function addMigrationRecord(lockFile, fileName, schemas, migrationContent) {
|
|
|
430
431
|
migrations: [...lockFile.migrations, record]
|
|
431
432
|
};
|
|
432
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
|
+
}
|
|
433
553
|
|
|
434
554
|
// src/hcl/type-mapper.ts
|
|
435
555
|
var MYSQL_TYPES = {
|
|
@@ -1590,6 +1710,7 @@ function hasBlockingIssues(_preview) {
|
|
|
1590
1710
|
export {
|
|
1591
1711
|
LOCK_FILE_NAME,
|
|
1592
1712
|
LOCK_FILE_VERSION,
|
|
1713
|
+
addEnhancedMigrationRecord,
|
|
1593
1714
|
addMigrationRecord,
|
|
1594
1715
|
applySchema,
|
|
1595
1716
|
buildSchemaHashes,
|
|
@@ -1601,11 +1722,15 @@ export {
|
|
|
1601
1722
|
computeSchemaHash,
|
|
1602
1723
|
createEmptyLockFile,
|
|
1603
1724
|
diffHclSchemas,
|
|
1725
|
+
extractTableNameFromFilename,
|
|
1726
|
+
extractTimestampFromFilename,
|
|
1727
|
+
findMigrationByTable,
|
|
1604
1728
|
formatDiffSummary,
|
|
1605
1729
|
formatPreview,
|
|
1606
1730
|
generateHclSchema,
|
|
1607
1731
|
generateHclTable,
|
|
1608
1732
|
generatePreview,
|
|
1733
|
+
getMigrationsToRegenerate,
|
|
1609
1734
|
getPrimaryKeyType,
|
|
1610
1735
|
getTimestampType,
|
|
1611
1736
|
hasBlockingIssues,
|
|
@@ -1623,6 +1748,7 @@ export {
|
|
|
1623
1748
|
updateLockFile,
|
|
1624
1749
|
updateLockFileV1,
|
|
1625
1750
|
validateHcl,
|
|
1751
|
+
validateMigrations,
|
|
1626
1752
|
writeLockFile
|
|
1627
1753
|
};
|
|
1628
1754
|
//# sourceMappingURL=index.js.map
|