@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.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Config, Engine } from '@dbcube/core';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Main class to handle MySQL database connections and queries.
|
|
3
5
|
* Implements the Singleton pattern to ensure a single instance of the connection pool.
|
|
@@ -28,7 +30,9 @@ export declare class Schema {
|
|
|
28
30
|
refreshTables(): Promise<any>;
|
|
29
31
|
freshTables(): Promise<any>;
|
|
30
32
|
executeSeeders(filterName?: string): Promise<any>;
|
|
31
|
-
executeAlters(
|
|
33
|
+
executeAlters(filterFiles?: string[] | null, options?: {
|
|
34
|
+
dryRun?: boolean;
|
|
35
|
+
}): Promise<any>;
|
|
32
36
|
executeTriggers(): Promise<any>;
|
|
33
37
|
}
|
|
34
38
|
export interface ProcessError {
|
|
@@ -136,6 +140,8 @@ export declare class DependencyResolver {
|
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
export {
|
|
143
|
+
Config,
|
|
144
|
+
Engine,
|
|
139
145
|
Schema as default,
|
|
140
146
|
};
|
|
141
147
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Config, Engine } from '@dbcube/core';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Main class to handle MySQL database connections and queries.
|
|
3
5
|
* Implements the Singleton pattern to ensure a single instance of the connection pool.
|
|
@@ -28,7 +30,9 @@ export declare class Schema {
|
|
|
28
30
|
refreshTables(): Promise<any>;
|
|
29
31
|
freshTables(): Promise<any>;
|
|
30
32
|
executeSeeders(filterName?: string): Promise<any>;
|
|
31
|
-
executeAlters(
|
|
33
|
+
executeAlters(filterFiles?: string[] | null, options?: {
|
|
34
|
+
dryRun?: boolean;
|
|
35
|
+
}): Promise<any>;
|
|
32
36
|
executeTriggers(): Promise<any>;
|
|
33
37
|
}
|
|
34
38
|
export interface ProcessError {
|
|
@@ -136,6 +140,8 @@ export declare class DependencyResolver {
|
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
export {
|
|
143
|
+
Config,
|
|
144
|
+
Engine,
|
|
139
145
|
Schema as default,
|
|
140
146
|
};
|
|
141
147
|
|
package/dist/index.js
CHANGED
|
@@ -1138,7 +1138,19 @@ var Schema = class {
|
|
|
1138
1138
|
returnFormattedError(queries.status, queries.message);
|
|
1139
1139
|
break;
|
|
1140
1140
|
}
|
|
1141
|
+
const dbType = queries.data.database_type ?? this.engine.getConfig?.()?.type;
|
|
1141
1142
|
delete queries.data.database_type;
|
|
1143
|
+
const generatedCreate = (queries.data.regular_queries ?? []).filter((q) => q.includes("CREATE"))[0];
|
|
1144
|
+
if (generatedCreate) {
|
|
1145
|
+
const diffQueries = await TableProcessor.generateAlterQueries(
|
|
1146
|
+
generatedCreate,
|
|
1147
|
+
dbType,
|
|
1148
|
+
dml.data.table,
|
|
1149
|
+
dml.data.database
|
|
1150
|
+
);
|
|
1151
|
+
const nonCreate = (queries.data.regular_queries ?? []).filter((q) => !q.includes("CREATE"));
|
|
1152
|
+
queries.data.regular_queries = [...diffQueries, ...nonCreate];
|
|
1153
|
+
}
|
|
1142
1154
|
const parseJsonQueries = JSON.stringify(queries.data);
|
|
1143
1155
|
const response = await this.engine.run("schema_engine", [
|
|
1144
1156
|
"--action",
|
|
@@ -1393,13 +1405,18 @@ var Schema = class {
|
|
|
1393
1405
|
UIUtils.showOperationSummary(summary);
|
|
1394
1406
|
return totalSeedersProcessed > 0 ? { processed: totalSeedersProcessed, success: successCount, errors: errorCount } : null;
|
|
1395
1407
|
}
|
|
1396
|
-
async executeAlters() {
|
|
1408
|
+
async executeAlters(filterFiles, options = {}) {
|
|
1397
1409
|
const startTime = Date.now();
|
|
1398
1410
|
const cubesDir = path4.join(process.cwd(), "dbcube");
|
|
1411
|
+
const dryRun = options.dryRun === true;
|
|
1399
1412
|
if (!fs5.existsSync(cubesDir)) {
|
|
1400
1413
|
throw new Error("\u274C The cubes folder does not exist");
|
|
1401
1414
|
}
|
|
1402
|
-
|
|
1415
|
+
let cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", ".alter.cube");
|
|
1416
|
+
if (filterFiles && filterFiles.length > 0) {
|
|
1417
|
+
const wanted = new Set(filterFiles.map((f) => path4.basename(f)));
|
|
1418
|
+
cubeFiles = cubeFiles.filter((f) => wanted.has(path4.basename(f)));
|
|
1419
|
+
}
|
|
1403
1420
|
if (cubeFiles.length === 0) {
|
|
1404
1421
|
throw new Error("\u274C There are no .alter.cube files to execute");
|
|
1405
1422
|
}
|
|
@@ -1454,6 +1471,22 @@ var Schema = class {
|
|
|
1454
1471
|
}
|
|
1455
1472
|
delete queries.data.database_type;
|
|
1456
1473
|
const parseJsonQueries = JSON.stringify(queries.data);
|
|
1474
|
+
if (dryRun) {
|
|
1475
|
+
console.log(`
|
|
1476
|
+
${chalk2.cyan("\u2500\u2500 dry-run \u2500\u2500")} ${chalk2.bold(alterName)}`);
|
|
1477
|
+
const allQueries = [
|
|
1478
|
+
...queries.data.regular_queries ?? [],
|
|
1479
|
+
...queries.data.special_queries ?? []
|
|
1480
|
+
];
|
|
1481
|
+
for (const q of allQueries) {
|
|
1482
|
+
console.log(` ${chalk2.gray("SQL>")} ${q}`);
|
|
1483
|
+
}
|
|
1484
|
+
UIUtils.showItemSuccess(alterName + " (dry-run)");
|
|
1485
|
+
successCount++;
|
|
1486
|
+
processedAlters.push(alterName);
|
|
1487
|
+
totalAltersProcessed++;
|
|
1488
|
+
continue;
|
|
1489
|
+
}
|
|
1457
1490
|
const response = await this.engine.run("schema_engine", [
|
|
1458
1491
|
"--action",
|
|
1459
1492
|
"execute",
|
|
@@ -1612,10 +1645,13 @@ ${chalk2.red("\u{1F6AB}")} ${chalk2.bold.red("ERRORS FOUND")}`);
|
|
|
1612
1645
|
}
|
|
1613
1646
|
|
|
1614
1647
|
// src/index.ts
|
|
1648
|
+
import { Engine as Engine2, Config } from "@dbcube/core";
|
|
1615
1649
|
var index_default = Schema;
|
|
1616
1650
|
export {
|
|
1651
|
+
Config,
|
|
1617
1652
|
CubeValidator,
|
|
1618
1653
|
DependencyResolver,
|
|
1654
|
+
Engine2 as Engine,
|
|
1619
1655
|
Schema,
|
|
1620
1656
|
UIUtils,
|
|
1621
1657
|
index_default as default
|