@dbcube/schema-builder 5.1.6 → 5.2.1
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 +40 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +38 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/.npmignore +0 -51
- package/CONTRIBUTING.md +0 -9
- package/bun.lockb +0 -0
- package/pnpm-workspace.yaml +0 -2
- package/tsup.config.ts +0 -14
package/dist/index.cjs
CHANGED
|
@@ -30,8 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
Config: () => import_core2.Config,
|
|
33
34
|
CubeValidator: () => CubeValidator,
|
|
34
35
|
DependencyResolver: () => DependencyResolver,
|
|
36
|
+
Engine: () => import_core2.Engine,
|
|
35
37
|
Schema: () => Schema,
|
|
36
38
|
UIUtils: () => UIUtils,
|
|
37
39
|
default: () => index_default
|
|
@@ -1178,7 +1180,19 @@ var Schema = class {
|
|
|
1178
1180
|
returnFormattedError(queries.status, queries.message);
|
|
1179
1181
|
break;
|
|
1180
1182
|
}
|
|
1183
|
+
const dbType = queries.data.database_type ?? this.engine.getConfig?.()?.type;
|
|
1181
1184
|
delete queries.data.database_type;
|
|
1185
|
+
const generatedCreate = (queries.data.regular_queries ?? []).filter((q) => q.includes("CREATE"))[0];
|
|
1186
|
+
if (generatedCreate) {
|
|
1187
|
+
const diffQueries = await import_core.TableProcessor.generateAlterQueries(
|
|
1188
|
+
generatedCreate,
|
|
1189
|
+
dbType,
|
|
1190
|
+
dml.data.table,
|
|
1191
|
+
dml.data.database
|
|
1192
|
+
);
|
|
1193
|
+
const nonCreate = (queries.data.regular_queries ?? []).filter((q) => !q.includes("CREATE"));
|
|
1194
|
+
queries.data.regular_queries = [...diffQueries, ...nonCreate];
|
|
1195
|
+
}
|
|
1182
1196
|
const parseJsonQueries = JSON.stringify(queries.data);
|
|
1183
1197
|
const response = await this.engine.run("schema_engine", [
|
|
1184
1198
|
"--action",
|
|
@@ -1433,13 +1447,18 @@ var Schema = class {
|
|
|
1433
1447
|
UIUtils.showOperationSummary(summary);
|
|
1434
1448
|
return totalSeedersProcessed > 0 ? { processed: totalSeedersProcessed, success: successCount, errors: errorCount } : null;
|
|
1435
1449
|
}
|
|
1436
|
-
async executeAlters() {
|
|
1450
|
+
async executeAlters(filterFiles, options = {}) {
|
|
1437
1451
|
const startTime = Date.now();
|
|
1438
1452
|
const cubesDir = import_path3.default.join(process.cwd(), "dbcube");
|
|
1453
|
+
const dryRun = options.dryRun === true;
|
|
1439
1454
|
if (!import_fs4.default.existsSync(cubesDir)) {
|
|
1440
1455
|
throw new Error("\u274C The cubes folder does not exist");
|
|
1441
1456
|
}
|
|
1442
|
-
|
|
1457
|
+
let cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", ".alter.cube");
|
|
1458
|
+
if (filterFiles && filterFiles.length > 0) {
|
|
1459
|
+
const wanted = new Set(filterFiles.map((f) => import_path3.default.basename(f)));
|
|
1460
|
+
cubeFiles = cubeFiles.filter((f) => wanted.has(import_path3.default.basename(f)));
|
|
1461
|
+
}
|
|
1443
1462
|
if (cubeFiles.length === 0) {
|
|
1444
1463
|
throw new Error("\u274C There are no .alter.cube files to execute");
|
|
1445
1464
|
}
|
|
@@ -1494,6 +1513,22 @@ var Schema = class {
|
|
|
1494
1513
|
}
|
|
1495
1514
|
delete queries.data.database_type;
|
|
1496
1515
|
const parseJsonQueries = JSON.stringify(queries.data);
|
|
1516
|
+
if (dryRun) {
|
|
1517
|
+
console.log(`
|
|
1518
|
+
${import_chalk2.default.cyan("\u2500\u2500 dry-run \u2500\u2500")} ${import_chalk2.default.bold(alterName)}`);
|
|
1519
|
+
const allQueries = [
|
|
1520
|
+
...queries.data.regular_queries ?? [],
|
|
1521
|
+
...queries.data.special_queries ?? []
|
|
1522
|
+
];
|
|
1523
|
+
for (const q of allQueries) {
|
|
1524
|
+
console.log(` ${import_chalk2.default.gray("SQL>")} ${q}`);
|
|
1525
|
+
}
|
|
1526
|
+
UIUtils.showItemSuccess(alterName + " (dry-run)");
|
|
1527
|
+
successCount++;
|
|
1528
|
+
processedAlters.push(alterName);
|
|
1529
|
+
totalAltersProcessed++;
|
|
1530
|
+
continue;
|
|
1531
|
+
}
|
|
1497
1532
|
const response = await this.engine.run("schema_engine", [
|
|
1498
1533
|
"--action",
|
|
1499
1534
|
"execute",
|
|
@@ -1652,11 +1687,14 @@ ${import_chalk2.default.red("\u{1F6AB}")} ${import_chalk2.default.bold.red("ERRO
|
|
|
1652
1687
|
}
|
|
1653
1688
|
|
|
1654
1689
|
// src/index.ts
|
|
1690
|
+
var import_core2 = require("@dbcube/core");
|
|
1655
1691
|
var index_default = Schema;
|
|
1656
1692
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1657
1693
|
0 && (module.exports = {
|
|
1694
|
+
Config,
|
|
1658
1695
|
CubeValidator,
|
|
1659
1696
|
DependencyResolver,
|
|
1697
|
+
Engine,
|
|
1660
1698
|
Schema,
|
|
1661
1699
|
UIUtils
|
|
1662
1700
|
});
|