befly 3.37.0 → 3.38.0
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/package.json +1 -1
- package/scripts/syncDb/diff.js +27 -1
- package/scripts/syncDb/index.js +6 -4
package/package.json
CHANGED
package/scripts/syncDb/diff.js
CHANGED
|
@@ -217,6 +217,7 @@ export function buildSyncDbDiff(groupedDbColumns, existingTableMap, beflyMode =
|
|
|
217
217
|
export async function applySyncDbDiff(diff, tablesDir, existingTableMap) {
|
|
218
218
|
let createdTableFileCount = 0;
|
|
219
219
|
let appendedFieldCount = 0;
|
|
220
|
+
let removedFieldCount = 0;
|
|
220
221
|
|
|
221
222
|
for (const missingTable of diff.missingTables) {
|
|
222
223
|
const tableDef = {};
|
|
@@ -245,8 +246,33 @@ export async function applySyncDbDiff(diff, tablesDir, existingTableMap) {
|
|
|
245
246
|
printSyncDbProcessLog(`已补充字段映射 ${targetFilePath},补充字段数量=${tableInfo.fields.length}`);
|
|
246
247
|
}
|
|
247
248
|
|
|
249
|
+
for (const [tableFileName, tableInfo] of Object.entries(diff.extraFieldsByTable)) {
|
|
250
|
+
const existing = existingTableMap.get(String(tableFileName).toLowerCase());
|
|
251
|
+
const targetFilePath = existing?.filePath || tableInfo.filePath || join(tablesDir, `${tableFileName}.json`);
|
|
252
|
+
const currentTableDef = isPlainObject(existing?.tableDef) ? existing.tableDef : {};
|
|
253
|
+
let tableRemovedFieldCount = 0;
|
|
254
|
+
|
|
255
|
+
for (const fieldItem of tableInfo.fields) {
|
|
256
|
+
if (!Object.hasOwn(currentTableDef, fieldItem.fieldName)) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
delete currentTableDef[fieldItem.fieldName];
|
|
261
|
+
removedFieldCount = removedFieldCount + 1;
|
|
262
|
+
tableRemovedFieldCount = tableRemovedFieldCount + 1;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (tableRemovedFieldCount <= 0) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
await Bun.write(targetFilePath, `${JSON.stringify(sortSyncDbObjectKeys(currentTableDef), null, 4)}\n`);
|
|
270
|
+
printSyncDbProcessLog(`已删除多余字段映射 ${targetFilePath},删除字段数量=${tableRemovedFieldCount}`);
|
|
271
|
+
}
|
|
272
|
+
|
|
248
273
|
return {
|
|
249
274
|
createdTableFileCount: createdTableFileCount,
|
|
250
|
-
appendedFieldCount: appendedFieldCount
|
|
275
|
+
appendedFieldCount: appendedFieldCount,
|
|
276
|
+
removedFieldCount: removedFieldCount
|
|
251
277
|
};
|
|
252
278
|
}
|
package/scripts/syncDb/index.js
CHANGED
|
@@ -12,22 +12,24 @@ export async function syncDb(mysqlConfig) {
|
|
|
12
12
|
try {
|
|
13
13
|
printSyncDbProcessLog("开始执行应用");
|
|
14
14
|
const { diff, groupedDbColumns, tablesDir, existingTableMap } = await prepareSyncDbBaseContext(mysqlConfig);
|
|
15
|
-
const extraFieldCount = diff.extraFieldCount;
|
|
16
15
|
const writtenReportPath = await writeSyncDbReport(reportPath, diff, groupedDbColumns, existingTableMap);
|
|
17
16
|
printSyncDbDiffSummary(diff);
|
|
18
17
|
const applyResult = await applySyncDbDiff(diff, tablesDir, existingTableMap);
|
|
19
|
-
const hasDiff = diff.missingTables.length > 0 || applyResult.appendedFieldCount > 0 || diff.extraTables.length > 0 ||
|
|
18
|
+
const hasDiff = diff.missingTables.length > 0 || applyResult.appendedFieldCount > 0 || diff.extraTables.length > 0 || applyResult.removedFieldCount > 0;
|
|
20
19
|
|
|
21
|
-
printSyncDbProcessLog(
|
|
20
|
+
printSyncDbProcessLog(
|
|
21
|
+
`应用完成,缺少表数量=${diff.missingTables.length},缺少字段数量=${applyResult.appendedFieldCount},多余表数量=${diff.extraTables.length},多余字段数量=${diff.extraFieldCount},新建表定义文件数量=${applyResult.createdTableFileCount},补充字段数量=${applyResult.appendedFieldCount},删除字段数量=${applyResult.removedFieldCount}`
|
|
22
|
+
);
|
|
22
23
|
|
|
23
24
|
return {
|
|
24
25
|
mode: "apply",
|
|
25
26
|
createdTableFileCount: applyResult.createdTableFileCount,
|
|
26
27
|
appendedFieldCount: applyResult.appendedFieldCount,
|
|
28
|
+
removedFieldCount: applyResult.removedFieldCount,
|
|
27
29
|
missingTableCount: diff.missingTables.length,
|
|
28
30
|
missingFieldCount: applyResult.appendedFieldCount,
|
|
29
31
|
extraTableCount: diff.extraTables.length,
|
|
30
|
-
extraFieldCount: extraFieldCount,
|
|
32
|
+
extraFieldCount: diff.extraFieldCount,
|
|
31
33
|
hasDiff: hasDiff,
|
|
32
34
|
reportPath: writtenReportPath
|
|
33
35
|
};
|