@famgia/omnify-cli 2.0.15 → 2.0.16
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 +86 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +83 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +86 -11
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/cli.js
CHANGED
|
@@ -1128,6 +1128,9 @@ import {
|
|
|
1128
1128
|
isLockFileV2,
|
|
1129
1129
|
validateMigrations,
|
|
1130
1130
|
getMigrationsToRegenerate,
|
|
1131
|
+
addEnhancedMigrationRecord,
|
|
1132
|
+
extractTimestampFromFilename,
|
|
1133
|
+
extractTableNameFromFilename,
|
|
1131
1134
|
VERSION_CHAIN_FILE,
|
|
1132
1135
|
readVersionChain,
|
|
1133
1136
|
checkBulkLockViolation
|
|
@@ -1591,6 +1594,7 @@ function schemaChangeToVersionChange(change) {
|
|
|
1591
1594
|
}
|
|
1592
1595
|
function writeGeneratorOutputs(outputs, rootDir) {
|
|
1593
1596
|
const counts = { migrations: 0, types: 0, models: 0, factories: 0, other: 0 };
|
|
1597
|
+
const migrationRecords = [];
|
|
1594
1598
|
for (const output of outputs) {
|
|
1595
1599
|
const filePath = resolve9(rootDir, output.path);
|
|
1596
1600
|
const dir = dirname6(filePath);
|
|
@@ -1604,13 +1608,34 @@ function writeGeneratorOutputs(outputs, rootDir) {
|
|
|
1604
1608
|
}
|
|
1605
1609
|
writeFileSync5(filePath, output.content);
|
|
1606
1610
|
logger.debug(`Created: ${output.path}`);
|
|
1607
|
-
if (output.type === "migration")
|
|
1608
|
-
|
|
1611
|
+
if (output.type === "migration") {
|
|
1612
|
+
counts.migrations++;
|
|
1613
|
+
const fileName = output.path.split("/").pop() ?? output.path;
|
|
1614
|
+
const timestamp = extractTimestampFromFilename(fileName);
|
|
1615
|
+
const metaTableName = output.metadata?.tableName;
|
|
1616
|
+
const tableName = metaTableName ?? extractTableNameFromFilename(fileName);
|
|
1617
|
+
const migrationType = output.metadata?.migrationType;
|
|
1618
|
+
const schemaName = output.metadata?.schemaName;
|
|
1619
|
+
const pathParts = output.path.split("/");
|
|
1620
|
+
pathParts.pop();
|
|
1621
|
+
const outputPath = pathParts.join("/");
|
|
1622
|
+
if (timestamp && tableName) {
|
|
1623
|
+
migrationRecords.push({
|
|
1624
|
+
fileName,
|
|
1625
|
+
timestamp,
|
|
1626
|
+
tableName,
|
|
1627
|
+
type: migrationType ?? "create",
|
|
1628
|
+
schemas: schemaName ? [schemaName] : [],
|
|
1629
|
+
content: output.content,
|
|
1630
|
+
outputPath
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
} else if (output.type === "type") counts.types++;
|
|
1609
1634
|
else if (output.type === "model") counts.models++;
|
|
1610
1635
|
else if (output.type === "factory") counts.factories++;
|
|
1611
1636
|
else counts.other++;
|
|
1612
1637
|
}
|
|
1613
|
-
return counts;
|
|
1638
|
+
return { ...counts, migrationRecords };
|
|
1614
1639
|
}
|
|
1615
1640
|
async function runPluginGeneration(plugins, schemas, rootDir, verbose, changes, localeConfig) {
|
|
1616
1641
|
const pluginManager = new PluginManager({
|
|
@@ -1641,6 +1666,7 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1641
1666
|
let typesGenerated = 0;
|
|
1642
1667
|
let modelsGenerated = 0;
|
|
1643
1668
|
let factoriesGenerated = 0;
|
|
1669
|
+
const migrationRecords = [];
|
|
1644
1670
|
const customTypesMap = /* @__PURE__ */ new Map();
|
|
1645
1671
|
for (const plugin of config.plugins) {
|
|
1646
1672
|
if (plugin.types) {
|
|
@@ -1686,6 +1712,17 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1686
1712
|
writeFileSync5(filePath, migration.content);
|
|
1687
1713
|
logger.debug(`Created: ${migration.fileName}`);
|
|
1688
1714
|
migrationsGenerated++;
|
|
1715
|
+
const timestamp = extractTimestampFromFilename(migration.fileName);
|
|
1716
|
+
if (timestamp && tableName) {
|
|
1717
|
+
migrationRecords.push({
|
|
1718
|
+
fileName: migration.fileName,
|
|
1719
|
+
timestamp,
|
|
1720
|
+
tableName,
|
|
1721
|
+
type: "create",
|
|
1722
|
+
schemas: migration.schemaName ? [migration.schemaName] : [],
|
|
1723
|
+
content: migration.content
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1689
1726
|
}
|
|
1690
1727
|
}
|
|
1691
1728
|
if (alterChanges.length > 0) {
|
|
@@ -1695,6 +1732,18 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1695
1732
|
writeFileSync5(filePath, migration.content);
|
|
1696
1733
|
logger.debug(`Created: ${migration.fileName}`);
|
|
1697
1734
|
migrationsGenerated++;
|
|
1735
|
+
const timestamp = extractTimestampFromFilename(migration.fileName);
|
|
1736
|
+
const tableName = migration.tables[0];
|
|
1737
|
+
if (timestamp && tableName) {
|
|
1738
|
+
migrationRecords.push({
|
|
1739
|
+
fileName: migration.fileName,
|
|
1740
|
+
timestamp,
|
|
1741
|
+
tableName,
|
|
1742
|
+
type: migration.type,
|
|
1743
|
+
schemas: [],
|
|
1744
|
+
content: migration.content
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1698
1747
|
}
|
|
1699
1748
|
}
|
|
1700
1749
|
logger.success(`Generated ${migrationsGenerated} migration(s)`);
|
|
@@ -1855,7 +1904,7 @@ function runDirectGeneration(schemas, config, rootDir, options, changes) {
|
|
|
1855
1904
|
logger.success("Auto-configured @omnify-base/* path in tsconfig.json");
|
|
1856
1905
|
}
|
|
1857
1906
|
}
|
|
1858
|
-
return { migrations: migrationsGenerated, types: typesGenerated, models: modelsGenerated, factories: factoriesGenerated };
|
|
1907
|
+
return { migrations: migrationsGenerated, types: typesGenerated, models: modelsGenerated, factories: factoriesGenerated, migrationRecords };
|
|
1859
1908
|
}
|
|
1860
1909
|
async function runGenerate(options) {
|
|
1861
1910
|
logger.setVerbose(options.verbose ?? false);
|
|
@@ -2015,7 +2064,7 @@ async function runGenerate(options) {
|
|
|
2015
2064
|
}
|
|
2016
2065
|
if (existingLock && config.output.laravel?.migrationsPath) {
|
|
2017
2066
|
const migrationsDir = resolve9(rootDir, config.output.laravel.migrationsPath);
|
|
2018
|
-
const migrationValidation = await validateMigrations(existingLock, migrationsDir);
|
|
2067
|
+
const migrationValidation = await validateMigrations(existingLock, migrationsDir, rootDir);
|
|
2019
2068
|
if (!migrationValidation.valid) {
|
|
2020
2069
|
logger.newline();
|
|
2021
2070
|
logger.warn("Migration file issues detected:");
|
|
@@ -2074,7 +2123,7 @@ async function runGenerate(options) {
|
|
|
2074
2123
|
const alterMigrations = toRegenerate.filter((m) => m.type === "alter" || m.type === "drop");
|
|
2075
2124
|
if (createMigrations.length > 0) {
|
|
2076
2125
|
logger.info(`Regenerating ${createMigrations.length} missing CREATE migration(s) with original timestamps...`);
|
|
2077
|
-
const
|
|
2126
|
+
const defaultMigrationsDir = resolve9(rootDir, config.output.laravel.migrationsPath);
|
|
2078
2127
|
const customTypesMap2 = /* @__PURE__ */ new Map();
|
|
2079
2128
|
for (const plugin of config.plugins) {
|
|
2080
2129
|
if (plugin.types) {
|
|
@@ -2095,11 +2144,20 @@ async function runGenerate(options) {
|
|
|
2095
2144
|
timestamp: migData.timestamp,
|
|
2096
2145
|
customTypes: customTypesMap2
|
|
2097
2146
|
});
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2147
|
+
const matchingMig = regenerated.find((mig) => {
|
|
2148
|
+
return mig.tables.includes(migData.tableName);
|
|
2149
|
+
});
|
|
2150
|
+
if (!matchingMig) {
|
|
2151
|
+
logger.warn(` Cannot regenerate ${migData.fileName}: migration for table '${migData.tableName}' not found`);
|
|
2152
|
+
continue;
|
|
2153
|
+
}
|
|
2154
|
+
const targetDir = migData.outputPath ? resolve9(rootDir, migData.outputPath) : defaultMigrationsDir;
|
|
2155
|
+
if (!existsSync9(targetDir)) {
|
|
2156
|
+
mkdirSync3(targetDir, { recursive: true });
|
|
2102
2157
|
}
|
|
2158
|
+
const filePath = resolve9(targetDir, migData.fileName);
|
|
2159
|
+
writeFileSync5(filePath, matchingMig.content);
|
|
2160
|
+
logger.success(` Regenerated: ${migData.fileName}`);
|
|
2103
2161
|
}
|
|
2104
2162
|
}
|
|
2105
2163
|
if (alterMigrations.length > 0) {
|
|
@@ -2129,6 +2187,7 @@ async function runGenerate(options) {
|
|
|
2129
2187
|
let typesGenerated = 0;
|
|
2130
2188
|
let modelsGenerated = 0;
|
|
2131
2189
|
let factoriesGenerated = 0;
|
|
2190
|
+
let allMigrationRecords = [];
|
|
2132
2191
|
const usePlugins = hasPluginGenerators(config.plugins);
|
|
2133
2192
|
const customTypesMap = /* @__PURE__ */ new Map();
|
|
2134
2193
|
for (const plugin of config.plugins) {
|
|
@@ -2158,6 +2217,7 @@ async function runGenerate(options) {
|
|
|
2158
2217
|
);
|
|
2159
2218
|
migrationsGenerated = counts.migrations;
|
|
2160
2219
|
typesGenerated = counts.types;
|
|
2220
|
+
allMigrationRecords = counts.migrationRecords;
|
|
2161
2221
|
if (counts.migrations > 0) {
|
|
2162
2222
|
logger.success(`Generated ${counts.migrations} migration(s)`);
|
|
2163
2223
|
}
|
|
@@ -2283,9 +2343,24 @@ async function runGenerate(options) {
|
|
|
2283
2343
|
typesGenerated = counts.types;
|
|
2284
2344
|
modelsGenerated = counts.models;
|
|
2285
2345
|
factoriesGenerated = counts.factories;
|
|
2346
|
+
allMigrationRecords = counts.migrationRecords;
|
|
2286
2347
|
}
|
|
2287
2348
|
logger.step("Updating lock file...");
|
|
2288
|
-
|
|
2349
|
+
let newLockFile = updateLockFile(existingLock, currentSnapshots, config.database.driver);
|
|
2350
|
+
if (allMigrationRecords.length > 0) {
|
|
2351
|
+
logger.debug(`Adding ${allMigrationRecords.length} migration(s) to lock file...`);
|
|
2352
|
+
for (const record of allMigrationRecords) {
|
|
2353
|
+
newLockFile = addEnhancedMigrationRecord(newLockFile, {
|
|
2354
|
+
fileName: record.fileName,
|
|
2355
|
+
timestamp: record.timestamp,
|
|
2356
|
+
tableName: record.tableName,
|
|
2357
|
+
type: record.type,
|
|
2358
|
+
schemas: record.schemas,
|
|
2359
|
+
content: record.content,
|
|
2360
|
+
outputPath: record.outputPath
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2289
2364
|
await writeLockFile(lockPath, newLockFile);
|
|
2290
2365
|
logger.debug(`Updated: ${config.lockFilePath}`);
|
|
2291
2366
|
if (comparison.hasChanges) {
|