befly 3.15.5 → 3.15.6

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/befly.js CHANGED
@@ -10339,7 +10339,6 @@ class SyncTable {
10339
10339
  const stmt = SyncTable.buildIndexSQL(tableName, act.indexName, act.fieldName, act.action);
10340
10340
  try {
10341
10341
  await db.unsafe(stmt);
10342
- Logger.debug(`[\u7D22\u5F15\u53D8\u5316] \u5220\u9664\u7D22\u5F15 ${tableName}.${act.indexName} (${act.fieldName})`);
10343
10342
  } catch (error) {
10344
10343
  Logger.error({ err: error, table: tableName, index: act.indexName, field: act.fieldName, msg: "\u5220\u9664\u7D22\u5F15\u5931\u8D25" });
10345
10344
  throw error;
@@ -10360,7 +10359,6 @@ class SyncTable {
10360
10359
  const stmt = SyncTable.buildIndexSQL(tableName, act.indexName, act.fieldName, act.action);
10361
10360
  try {
10362
10361
  await db.unsafe(stmt);
10363
- Logger.debug(`[\u7D22\u5F15\u53D8\u5316] \u65B0\u5EFA\u7D22\u5F15 ${tableName}.${act.indexName} (${act.fieldName})`);
10364
10362
  } catch (error) {
10365
10363
  Logger.error({ err: error, table: tableName, index: act.indexName, field: act.fieldName, msg: "\u521B\u5EFA\u7D22\u5F15\u5931\u8D25" });
10366
10364
  throw error;
@@ -10377,6 +10375,7 @@ class SyncTable {
10377
10375
  ${cols}
10378
10376
  ) ENGINE=${ENGINE} DEFAULT CHARSET=${CHARSET} COLLATE=${COLLATE}`;
10379
10377
  await db.unsafe(createSQL);
10378
+ Logger.debug(`[\u8868 ${tableName}] + \u521B\u5EFA\u8868\uFF08\u7CFB\u7EDF\u5B57\u6BB5 + \u4E1A\u52A1\u5B57\u6BB5\uFF09`);
10380
10379
  const indexTasks = [];
10381
10380
  const existingIndexes = {};
10382
10381
  for (const sysField of systemIndexFields) {
@@ -10410,15 +10409,17 @@ class SyncTable {
10410
10409
  const modifyClauses = [];
10411
10410
  const defaultClauses = [];
10412
10411
  const indexActions = [];
10412
+ const addedBusinessFields = [];
10413
+ const addedSystemFields = [];
10414
+ const modifiedFields = [];
10415
+ const defaultOnlyChangedFields = [];
10416
+ const compatibleTypeChanges = [];
10413
10417
  for (const [fieldKey, fieldDef] of Object.entries(fields)) {
10414
10418
  const dbFieldName = snakeCase(fieldKey);
10415
10419
  if (existingColumns[dbFieldName]) {
10416
10420
  const comparison = SyncTable.compareFieldDefinition(existingColumns[dbFieldName], fieldDef);
10417
10421
  if (comparison.length > 0) {
10418
- for (const c of comparison) {
10419
- const changeLabel = SyncTable.CHANGE_TYPE_LABELS[c.type] || "\u672A\u77E5";
10420
- Logger.debug(` ~ \u4FEE\u6539 ${dbFieldName} ${changeLabel}: ${c.current} -> ${c.expected}`);
10421
- }
10422
+ modifiedFields.push(dbFieldName);
10422
10423
  const hasTypeChange = comparison.some((c) => c.type === "datatype");
10423
10424
  const onlyDefaultChanged = comparison.every((c) => c.type === "default");
10424
10425
  const defaultChanged = comparison.some((c) => c.type === "default");
@@ -10432,7 +10433,7 @@ class SyncTable {
10432
10433
  `);
10433
10434
  throw new Error(errorMsg);
10434
10435
  }
10435
- Logger.debug(`[\u517C\u5BB9\u7C7B\u578B\u53D8\u66F4] ${tableName}.${dbFieldName} ${currentType} -> ${expectedType}`);
10436
+ compatibleTypeChanges.push(`${dbFieldName}: ${currentType} -> ${expectedType}`);
10436
10437
  }
10437
10438
  if (defaultChanged) {
10438
10439
  const actualDefault = SyncTable.resolveDefaultValue(fieldDef.default ?? null, fieldDef.type);
@@ -10445,6 +10446,7 @@ class SyncTable {
10445
10446
  if (fieldDef.type !== "text") {
10446
10447
  const colQuoted = SyncTable.quoteIdentifier(dbFieldName);
10447
10448
  defaultClauses.push(`ALTER COLUMN ${colQuoted} SET DEFAULT ${v}`);
10449
+ defaultOnlyChangedFields.push(dbFieldName);
10448
10450
  }
10449
10451
  }
10450
10452
  }
@@ -10454,6 +10456,7 @@ class SyncTable {
10454
10456
  changed = true;
10455
10457
  }
10456
10458
  } else {
10459
+ addedBusinessFields.push(dbFieldName);
10457
10460
  addClauses.push(SyncTable.generateDDLClause(fieldKey, fieldDef, true));
10458
10461
  changed = true;
10459
10462
  }
@@ -10463,7 +10466,7 @@ class SyncTable {
10463
10466
  if (!existingColumns[sysFieldName]) {
10464
10467
  const colDef = SyncTable.getSystemColumnDef(sysFieldName);
10465
10468
  if (colDef) {
10466
- Logger.debug(` + \u65B0\u589E\u7CFB\u7EDF\u5B57\u6BB5 ${sysFieldName}`);
10469
+ addedSystemFields.push(sysFieldName);
10467
10470
  addClauses.push(`ADD COLUMN ${colDef}`);
10468
10471
  changed = true;
10469
10472
  }
@@ -10497,6 +10500,49 @@ class SyncTable {
10497
10500
  indexActions
10498
10501
  };
10499
10502
  if (plan.changed) {
10503
+ const summaryParts = [];
10504
+ summaryParts.push(`[\u8868 ${tableName}] \u53D8\u66F4\u6C47\u603B`);
10505
+ summaryParts.push(`\u65B0\u589E\u5B57\u6BB5=${addedBusinessFields.length}`);
10506
+ summaryParts.push(`\u65B0\u589E\u7CFB\u7EDF\u5B57\u6BB5=${addedSystemFields.length}`);
10507
+ summaryParts.push(`\u4FEE\u6539\u5B57\u6BB5=${modifiedFields.length}`);
10508
+ summaryParts.push(`\u9ED8\u8BA4\u503C\u66F4\u65B0=${defaultOnlyChangedFields.length}`);
10509
+ summaryParts.push(`\u7D22\u5F15\u53D8\u66F4=${indexActions.length}`);
10510
+ const detailParts = [];
10511
+ if (addedBusinessFields.length > 0) {
10512
+ detailParts.push(`\u65B0\u589E\u5B57\u6BB5:${addedBusinessFields.join(",")}`);
10513
+ }
10514
+ if (addedSystemFields.length > 0) {
10515
+ detailParts.push(`\u65B0\u589E\u7CFB\u7EDF\u5B57\u6BB5:${addedSystemFields.join(",")}`);
10516
+ }
10517
+ if (modifiedFields.length > 0) {
10518
+ detailParts.push(`\u4FEE\u6539\u5B57\u6BB5:${modifiedFields.join(",")}`);
10519
+ }
10520
+ if (defaultOnlyChangedFields.length > 0) {
10521
+ detailParts.push(`\u9ED8\u8BA4\u503C\u66F4\u65B0:${defaultOnlyChangedFields.join(",")}`);
10522
+ }
10523
+ if (compatibleTypeChanges.length > 0) {
10524
+ detailParts.push(`\u517C\u5BB9\u7C7B\u578B\u53D8\u66F4:${compatibleTypeChanges.join(";")}`);
10525
+ }
10526
+ if (indexActions.length > 0) {
10527
+ const createIndexSummaries = [];
10528
+ const dropIndexSummaries = [];
10529
+ for (const a of indexActions) {
10530
+ const item = `${a.indexName}(${a.fieldName})`;
10531
+ if (a.action === "create") {
10532
+ createIndexSummaries.push(`+${item}`);
10533
+ } else {
10534
+ dropIndexSummaries.push(`-${item}`);
10535
+ }
10536
+ }
10537
+ const indexPart = [];
10538
+ if (dropIndexSummaries.length > 0)
10539
+ indexPart.push(dropIndexSummaries.join(","));
10540
+ if (createIndexSummaries.length > 0)
10541
+ indexPart.push(createIndexSummaries.join(","));
10542
+ detailParts.push(`\u7D22\u5F15:${indexPart.join(",")}`);
10543
+ }
10544
+ const msg = detailParts.length > 0 ? `${summaryParts.join("\uFF0C")}\uFF1B${detailParts.join("\uFF0C")}` : summaryParts.join("\uFF0C");
10545
+ Logger.debug(msg);
10500
10546
  await SyncTable.applyTablePlan(db, tableName, plan);
10501
10547
  }
10502
10548
  return plan;