@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.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -22,6 +32,7 @@ var index_exports = {};
|
|
|
22
32
|
__export(index_exports, {
|
|
23
33
|
LOCK_FILE_NAME: () => LOCK_FILE_NAME,
|
|
24
34
|
LOCK_FILE_VERSION: () => LOCK_FILE_VERSION,
|
|
35
|
+
addEnhancedMigrationRecord: () => addEnhancedMigrationRecord,
|
|
25
36
|
addMigrationRecord: () => addMigrationRecord,
|
|
26
37
|
applySchema: () => applySchema,
|
|
27
38
|
buildSchemaHashes: () => buildSchemaHashes,
|
|
@@ -33,11 +44,15 @@ __export(index_exports, {
|
|
|
33
44
|
computeSchemaHash: () => computeSchemaHash,
|
|
34
45
|
createEmptyLockFile: () => createEmptyLockFile,
|
|
35
46
|
diffHclSchemas: () => diffHclSchemas,
|
|
47
|
+
extractTableNameFromFilename: () => extractTableNameFromFilename,
|
|
48
|
+
extractTimestampFromFilename: () => extractTimestampFromFilename,
|
|
49
|
+
findMigrationByTable: () => findMigrationByTable,
|
|
36
50
|
formatDiffSummary: () => formatDiffSummary,
|
|
37
51
|
formatPreview: () => formatPreview,
|
|
38
52
|
generateHclSchema: () => generateHclSchema,
|
|
39
53
|
generateHclTable: () => generateHclTable,
|
|
40
54
|
generatePreview: () => generatePreview,
|
|
55
|
+
getMigrationsToRegenerate: () => getMigrationsToRegenerate,
|
|
41
56
|
getPrimaryKeyType: () => getPrimaryKeyType,
|
|
42
57
|
getTimestampType: () => getTimestampType,
|
|
43
58
|
hasBlockingIssues: () => hasBlockingIssues,
|
|
@@ -55,6 +70,7 @@ __export(index_exports, {
|
|
|
55
70
|
updateLockFile: () => updateLockFile,
|
|
56
71
|
updateLockFileV1: () => updateLockFileV1,
|
|
57
72
|
validateHcl: () => validateHcl,
|
|
73
|
+
validateMigrations: () => validateMigrations,
|
|
58
74
|
writeLockFile: () => writeLockFile
|
|
59
75
|
});
|
|
60
76
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -104,6 +120,7 @@ function propertyToSnapshot(property) {
|
|
|
104
120
|
onUpdate: prop.onUpdate,
|
|
105
121
|
mappedBy: prop.mappedBy,
|
|
106
122
|
joinTable: prop.joinTable,
|
|
123
|
+
pivotFields: prop.pivotFields,
|
|
107
124
|
// renamedFrom is kept in snapshot for comparison (rename detection),
|
|
108
125
|
// but will be stripped when writing to lock file.
|
|
109
126
|
renamedFrom: prop.renamedFrom,
|
|
@@ -491,6 +508,125 @@ function addMigrationRecord(lockFile, fileName, schemas, migrationContent) {
|
|
|
491
508
|
migrations: [...lockFile.migrations, record]
|
|
492
509
|
};
|
|
493
510
|
}
|
|
511
|
+
function addEnhancedMigrationRecord(lockFile, options) {
|
|
512
|
+
const record = {
|
|
513
|
+
fileName: options.fileName,
|
|
514
|
+
timestamp: options.timestamp,
|
|
515
|
+
tableName: options.tableName,
|
|
516
|
+
type: options.type,
|
|
517
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
518
|
+
schemas: options.schemas,
|
|
519
|
+
checksum: computeHash(options.content)
|
|
520
|
+
};
|
|
521
|
+
return {
|
|
522
|
+
...lockFile,
|
|
523
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
524
|
+
migrations: [...lockFile.migrations, record]
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function extractTimestampFromFilename(fileName) {
|
|
528
|
+
const match = fileName.match(/^(\d{4}_\d{2}_\d{2}_\d{6})_/);
|
|
529
|
+
return match ? match[1] : null;
|
|
530
|
+
}
|
|
531
|
+
function extractTableNameFromFilename(fileName) {
|
|
532
|
+
const createMatch = fileName.match(/_create_(.+)_table\.php$/);
|
|
533
|
+
if (createMatch) return createMatch[1];
|
|
534
|
+
const updateMatch = fileName.match(/_update_(.+)_table\.php$/);
|
|
535
|
+
if (updateMatch) return updateMatch[1];
|
|
536
|
+
const dropMatch = fileName.match(/_drop_(.+)_table\.php$/);
|
|
537
|
+
if (dropMatch) return dropMatch[1];
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
async function validateMigrations(lockFile, migrationsDir) {
|
|
541
|
+
const missingFiles = [];
|
|
542
|
+
const modifiedFiles = [];
|
|
543
|
+
const staleFiles = [];
|
|
544
|
+
let filesOnDisk = [];
|
|
545
|
+
try {
|
|
546
|
+
const { readdirSync } = await import("fs");
|
|
547
|
+
filesOnDisk = readdirSync(migrationsDir).filter((f) => f.endsWith(".php"));
|
|
548
|
+
} catch {
|
|
549
|
+
}
|
|
550
|
+
const filesOnDiskSet = new Set(filesOnDisk);
|
|
551
|
+
for (const migration of lockFile.migrations) {
|
|
552
|
+
const fileName = migration.fileName;
|
|
553
|
+
if (!filesOnDiskSet.has(fileName)) {
|
|
554
|
+
missingFiles.push(fileName);
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
if (migration.checksum) {
|
|
558
|
+
try {
|
|
559
|
+
const { readFileSync } = await import("fs");
|
|
560
|
+
const { join: join3 } = await import("path");
|
|
561
|
+
const content = readFileSync(join3(migrationsDir, fileName), "utf8");
|
|
562
|
+
const currentChecksum = computeHash(content);
|
|
563
|
+
if (currentChecksum !== migration.checksum) {
|
|
564
|
+
modifiedFiles.push(fileName);
|
|
565
|
+
}
|
|
566
|
+
} catch {
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
const trackedFileNames = new Set(lockFile.migrations.map((m) => m.fileName));
|
|
571
|
+
const now = /* @__PURE__ */ new Date();
|
|
572
|
+
for (const fileName of filesOnDisk) {
|
|
573
|
+
if (!trackedFileNames.has(fileName)) {
|
|
574
|
+
const timestamp = extractTimestampFromFilename(fileName);
|
|
575
|
+
if (timestamp) {
|
|
576
|
+
const [year, month, day] = timestamp.split("_").slice(0, 3).map(Number);
|
|
577
|
+
const fileDate = new Date(year, month - 1, day);
|
|
578
|
+
const daysDiff = (now.getTime() - fileDate.getTime()) / (1e3 * 60 * 60 * 24);
|
|
579
|
+
if (daysDiff > 7) {
|
|
580
|
+
staleFiles.push(fileName);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
valid: missingFiles.length === 0 && modifiedFiles.length === 0,
|
|
587
|
+
missingFiles,
|
|
588
|
+
modifiedFiles,
|
|
589
|
+
staleFiles,
|
|
590
|
+
totalTracked: lockFile.migrations.length,
|
|
591
|
+
totalOnDisk: filesOnDisk.length
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
function findMigrationByTable(lockFile, tableName, type) {
|
|
595
|
+
return lockFile.migrations.find((m) => {
|
|
596
|
+
const mig = m;
|
|
597
|
+
if (mig.tableName) {
|
|
598
|
+
return mig.tableName === tableName && (!type || mig.type === type);
|
|
599
|
+
}
|
|
600
|
+
const extractedTable = extractTableNameFromFilename(m.fileName);
|
|
601
|
+
return extractedTable === tableName;
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
function getMigrationsToRegenerate(lockFile, missingFiles) {
|
|
605
|
+
const missingSet = new Set(missingFiles);
|
|
606
|
+
const result = [];
|
|
607
|
+
for (const migration of lockFile.migrations) {
|
|
608
|
+
if (!missingSet.has(migration.fileName)) continue;
|
|
609
|
+
const mig = migration;
|
|
610
|
+
const timestamp = mig.timestamp ?? extractTimestampFromFilename(migration.fileName);
|
|
611
|
+
if (!timestamp) continue;
|
|
612
|
+
const tableName = mig.tableName ?? extractTableNameFromFilename(migration.fileName);
|
|
613
|
+
if (!tableName) continue;
|
|
614
|
+
let type = mig.type ?? "create";
|
|
615
|
+
if (!mig.type) {
|
|
616
|
+
if (migration.fileName.includes("_create_")) type = "create";
|
|
617
|
+
else if (migration.fileName.includes("_update_")) type = "alter";
|
|
618
|
+
else if (migration.fileName.includes("_drop_")) type = "drop";
|
|
619
|
+
}
|
|
620
|
+
result.push({
|
|
621
|
+
fileName: migration.fileName,
|
|
622
|
+
timestamp,
|
|
623
|
+
tableName,
|
|
624
|
+
type,
|
|
625
|
+
schemas: migration.schemas
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
return result;
|
|
629
|
+
}
|
|
494
630
|
|
|
495
631
|
// src/hcl/type-mapper.ts
|
|
496
632
|
var MYSQL_TYPES = {
|
|
@@ -1652,6 +1788,7 @@ function hasBlockingIssues(_preview) {
|
|
|
1652
1788
|
0 && (module.exports = {
|
|
1653
1789
|
LOCK_FILE_NAME,
|
|
1654
1790
|
LOCK_FILE_VERSION,
|
|
1791
|
+
addEnhancedMigrationRecord,
|
|
1655
1792
|
addMigrationRecord,
|
|
1656
1793
|
applySchema,
|
|
1657
1794
|
buildSchemaHashes,
|
|
@@ -1663,11 +1800,15 @@ function hasBlockingIssues(_preview) {
|
|
|
1663
1800
|
computeSchemaHash,
|
|
1664
1801
|
createEmptyLockFile,
|
|
1665
1802
|
diffHclSchemas,
|
|
1803
|
+
extractTableNameFromFilename,
|
|
1804
|
+
extractTimestampFromFilename,
|
|
1805
|
+
findMigrationByTable,
|
|
1666
1806
|
formatDiffSummary,
|
|
1667
1807
|
formatPreview,
|
|
1668
1808
|
generateHclSchema,
|
|
1669
1809
|
generateHclTable,
|
|
1670
1810
|
generatePreview,
|
|
1811
|
+
getMigrationsToRegenerate,
|
|
1671
1812
|
getPrimaryKeyType,
|
|
1672
1813
|
getTimestampType,
|
|
1673
1814
|
hasBlockingIssues,
|
|
@@ -1685,6 +1826,7 @@ function hasBlockingIssues(_preview) {
|
|
|
1685
1826
|
updateLockFile,
|
|
1686
1827
|
updateLockFileV1,
|
|
1687
1828
|
validateHcl,
|
|
1829
|
+
validateMigrations,
|
|
1688
1830
|
writeLockFile
|
|
1689
1831
|
});
|
|
1690
1832
|
//# sourceMappingURL=index.cjs.map
|