befly 3.19.7 → 3.19.9
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/lib/redisHelper.js
CHANGED
|
@@ -501,15 +501,19 @@ export class RedisHelper {
|
|
|
501
501
|
async info(section) {
|
|
502
502
|
try {
|
|
503
503
|
const client = this.client;
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
code: "runtime"
|
|
508
|
-
});
|
|
504
|
+
|
|
505
|
+
if (typeof client.info === "function") {
|
|
506
|
+
return await client.info(section);
|
|
509
507
|
}
|
|
510
508
|
|
|
511
|
-
|
|
512
|
-
|
|
509
|
+
if (typeof client.send === "function") {
|
|
510
|
+
return await client.send("INFO", section ? [String(section)] : []);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
throw new Error("Redis info 不支持", {
|
|
514
|
+
cause: null,
|
|
515
|
+
code: "runtime"
|
|
516
|
+
});
|
|
513
517
|
} catch (error) {
|
|
514
518
|
Logger.error("Redis info 错误", error);
|
|
515
519
|
return "";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.19.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.19.9",
|
|
4
|
+
"gitHead": "558ea1598bb0547b5b068a1c014ea1f4d48939d5",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|
|
@@ -9,6 +9,7 @@ import { isNonEmptyString, isPlainObject } from "../../utils/is.js";
|
|
|
9
9
|
import { camelCase } from "../../utils/util.js";
|
|
10
10
|
import { buildSyncDbDiff, groupSyncDbColumns } from "./diff.js";
|
|
11
11
|
import { querySyncDbColumns } from "./query.js";
|
|
12
|
+
import { printSyncDbProcessLog } from "./report.js";
|
|
12
13
|
|
|
13
14
|
async function loadSyncDbTableDefs(tablesDir) {
|
|
14
15
|
const tableMap = new Map();
|
|
@@ -52,6 +53,7 @@ async function loadSyncDbTableDefs(tablesDir) {
|
|
|
52
53
|
export async function prepareSyncDbBaseContext(mysqlConfig) {
|
|
53
54
|
const tablesDir = resolve(join(process.cwd(), "tables"));
|
|
54
55
|
await mkdir(tablesDir, { recursive: true });
|
|
56
|
+
printSyncDbProcessLog(`tables目录=${tablesDir}`);
|
|
55
57
|
|
|
56
58
|
if (!isPlainObject(mysqlConfig)) {
|
|
57
59
|
throw new Error("syncDb 缺少 mysql 配置", {
|
|
@@ -62,6 +64,7 @@ export async function prepareSyncDbBaseContext(mysqlConfig) {
|
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
printSyncDbProcessLog(`连接 MySQL,database=${mysqlConfig.database}`);
|
|
65
68
|
await Connect.connectMysql(mysqlConfig);
|
|
66
69
|
const mysql = new DbHelper({
|
|
67
70
|
redis: null,
|
|
@@ -71,7 +74,9 @@ export async function prepareSyncDbBaseContext(mysqlConfig) {
|
|
|
71
74
|
beflyMode: mysqlConfig.beflyMode
|
|
72
75
|
});
|
|
73
76
|
|
|
77
|
+
printSyncDbProcessLog("开始读取数据库字段信息");
|
|
74
78
|
const dbColumns = await querySyncDbColumns(mysql);
|
|
79
|
+
printSyncDbProcessLog(`数据库字段读取完成,columnCount=${dbColumns.length}`);
|
|
75
80
|
const skippedBeflyTables = new Set();
|
|
76
81
|
for (const row of dbColumns) {
|
|
77
82
|
const tableName = String(row?.tableName || "");
|
|
@@ -90,6 +95,8 @@ export async function prepareSyncDbBaseContext(mysqlConfig) {
|
|
|
90
95
|
const groupedDbColumns = groupSyncDbColumns(dbColumns);
|
|
91
96
|
const existingTableMap = await loadSyncDbTableDefs(tablesDir);
|
|
92
97
|
const diff = buildSyncDbDiff(groupedDbColumns, existingTableMap);
|
|
98
|
+
printSyncDbProcessLog(`tables定义文件数量=${existingTableMap.size}`);
|
|
99
|
+
printSyncDbProcessLog(`差异扫描完成,missingTableCount=${diff.missingTables.length},missingFieldCount=${Object.values(diff.missingFieldsByTable).reduce((sum, item) => sum + item.fields.length, 0)}`);
|
|
93
100
|
|
|
94
101
|
return {
|
|
95
102
|
diff: diff,
|
package/scripts/syncDb/diff.js
CHANGED
|
@@ -2,6 +2,7 @@ import { join } from "node:path";
|
|
|
2
2
|
|
|
3
3
|
import { isNonEmptyString, isPlainObject } from "../../utils/is.js";
|
|
4
4
|
import { camelCase } from "../../utils/util.js";
|
|
5
|
+
import { printSyncDbProcessLog } from "./report.js";
|
|
5
6
|
import { toSyncDbFieldDef } from "./transform.js";
|
|
6
7
|
|
|
7
8
|
export function groupSyncDbColumns(rows) {
|
|
@@ -103,6 +104,7 @@ export async function applySyncDbDiff(diff, tablesDir, existingTableMap) {
|
|
|
103
104
|
const filePath = join(tablesDir, `${missingTable.tableFileName}.json`);
|
|
104
105
|
await Bun.write(filePath, `${JSON.stringify(tableDef, null, 4)}\n`);
|
|
105
106
|
createdTableFileCount = createdTableFileCount + 1;
|
|
107
|
+
printSyncDbProcessLog(`已生成表映射 ${filePath}`);
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
for (const [tableFileName, tableInfo] of Object.entries(diff.missingFieldsByTable)) {
|
|
@@ -116,6 +118,7 @@ export async function applySyncDbDiff(diff, tablesDir, existingTableMap) {
|
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
await Bun.write(targetFilePath, `${JSON.stringify(currentTableDef, null, 4)}\n`);
|
|
121
|
+
printSyncDbProcessLog(`已补充字段映射 ${targetFilePath},fieldCount=${tableInfo.fields.length}`);
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
return {
|
package/scripts/syncDb/index.js
CHANGED
|
@@ -5,10 +5,11 @@ import { Connect } from "../../lib/connect.js";
|
|
|
5
5
|
import { Logger } from "../../lib/logger.js";
|
|
6
6
|
import { applySyncDbDiff, countSyncDbMissingFields } from "./diff.js";
|
|
7
7
|
import { prepareSyncDbBaseContext } from "./context.js";
|
|
8
|
-
import { printSyncDbDiffSummary, writeSyncDbCheckReport } from "./report.js";
|
|
8
|
+
import { printSyncDbDiffSummary, printSyncDbProcessLog, writeSyncDbCheckReport } from "./report.js";
|
|
9
9
|
|
|
10
10
|
export async function syncDbCheck(mysqlConfig) {
|
|
11
11
|
try {
|
|
12
|
+
printSyncDbProcessLog("开始执行 check");
|
|
12
13
|
const reportPath = resolve(join(process.cwd(), "db.check.md"));
|
|
13
14
|
await mkdir(dirname(reportPath), { recursive: true });
|
|
14
15
|
await Bun.write(reportPath, "");
|
|
@@ -17,6 +18,7 @@ export async function syncDbCheck(mysqlConfig) {
|
|
|
17
18
|
const missingFieldCount = countSyncDbMissingFields(diff);
|
|
18
19
|
const writtenReportPath = await writeSyncDbCheckReport(reportPath, diff, groupedDbColumns, existingTableMap);
|
|
19
20
|
printSyncDbDiffSummary("check", diff);
|
|
21
|
+
printSyncDbProcessLog(`check完成,missingTableCount=${diff.missingTables.length},missingFieldCount=${missingFieldCount}`);
|
|
20
22
|
|
|
21
23
|
return {
|
|
22
24
|
mode: "check",
|
|
@@ -42,10 +44,12 @@ export async function syncDbCheck(mysqlConfig) {
|
|
|
42
44
|
|
|
43
45
|
export async function syncDbApply(mysqlConfig) {
|
|
44
46
|
try {
|
|
47
|
+
printSyncDbProcessLog("开始执行 apply");
|
|
45
48
|
const { diff, tablesDir, existingTableMap } = await prepareSyncDbBaseContext(mysqlConfig);
|
|
46
49
|
printSyncDbDiffSummary("check", diff);
|
|
47
50
|
const applyResult = await applySyncDbDiff(diff, tablesDir, existingTableMap);
|
|
48
51
|
printSyncDbDiffSummary("apply", diff);
|
|
52
|
+
printSyncDbProcessLog(`apply完成,createdTableFileCount=${applyResult.createdTableFileCount},appendedFieldCount=${applyResult.appendedFieldCount}`);
|
|
49
53
|
|
|
50
54
|
return {
|
|
51
55
|
mode: "apply",
|
package/scripts/syncDb/report.js
CHANGED
|
@@ -7,6 +7,10 @@ import { camelCase } from "../../utils/util.js";
|
|
|
7
7
|
import { countSyncDbMissingFields } from "./diff.js";
|
|
8
8
|
import { toSyncDbFieldDef } from "./transform.js";
|
|
9
9
|
|
|
10
|
+
export function printSyncDbProcessLog(message) {
|
|
11
|
+
process.stdout.write(`[syncDb] ${message}\n`);
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
export function printSyncDbDiffSummary(mode, diff) {
|
|
11
15
|
const tableNames = diff.missingTables.map((item) => item.tableName);
|
|
12
16
|
const missingFieldGroups = Object.values(diff.missingFieldsByTable);
|
|
@@ -182,6 +186,7 @@ export async function writeSyncDbCheckReport(reportPath, diff, groupedDbColumns,
|
|
|
182
186
|
await mkdir(dirname(reportPath), { recursive: true });
|
|
183
187
|
const markdown = buildSyncDbCheckMarkdown(diff, groupedDbColumns, existingTableMap);
|
|
184
188
|
await Bun.write(reportPath, markdown);
|
|
189
|
+
printSyncDbProcessLog(`差异报告已写入 ${reportPath}`);
|
|
185
190
|
Logger.info("差异报告写入完成", {
|
|
186
191
|
reportPath: reportPath
|
|
187
192
|
});
|