befly 3.15.4 → 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 +58 -8
- package/dist/befly.min.js +11 -11
- package/dist/sync/syncTable.js +63 -8
- package/package.json +2 -2
package/dist/befly.js
CHANGED
|
@@ -10193,6 +10193,10 @@ class SyncTable {
|
|
|
10193
10193
|
return false;
|
|
10194
10194
|
const cBase = c.replace(/\s*unsigned/gi, "").replace(/\([^)]*\)/g, "").trim();
|
|
10195
10195
|
const nBase = n.replace(/\s*unsigned/gi, "").replace(/\([^)]*\)/g, "").trim();
|
|
10196
|
+
const textFamily = ["tinytext", "text", "mediumtext", "longtext"];
|
|
10197
|
+
if (textFamily.includes(cBase) && textFamily.includes(nBase)) {
|
|
10198
|
+
return true;
|
|
10199
|
+
}
|
|
10196
10200
|
const intTypes = ["tinyint", "smallint", "mediumint", "int", "integer", "bigint"];
|
|
10197
10201
|
const cIntIdx = intTypes.indexOf(cBase);
|
|
10198
10202
|
const nIntIdx = intTypes.indexOf(nBase);
|
|
@@ -10335,7 +10339,6 @@ class SyncTable {
|
|
|
10335
10339
|
const stmt = SyncTable.buildIndexSQL(tableName, act.indexName, act.fieldName, act.action);
|
|
10336
10340
|
try {
|
|
10337
10341
|
await db.unsafe(stmt);
|
|
10338
|
-
Logger.debug(`[\u7D22\u5F15\u53D8\u5316] \u5220\u9664\u7D22\u5F15 ${tableName}.${act.indexName} (${act.fieldName})`);
|
|
10339
10342
|
} catch (error) {
|
|
10340
10343
|
Logger.error({ err: error, table: tableName, index: act.indexName, field: act.fieldName, msg: "\u5220\u9664\u7D22\u5F15\u5931\u8D25" });
|
|
10341
10344
|
throw error;
|
|
@@ -10356,7 +10359,6 @@ class SyncTable {
|
|
|
10356
10359
|
const stmt = SyncTable.buildIndexSQL(tableName, act.indexName, act.fieldName, act.action);
|
|
10357
10360
|
try {
|
|
10358
10361
|
await db.unsafe(stmt);
|
|
10359
|
-
Logger.debug(`[\u7D22\u5F15\u53D8\u5316] \u65B0\u5EFA\u7D22\u5F15 ${tableName}.${act.indexName} (${act.fieldName})`);
|
|
10360
10362
|
} catch (error) {
|
|
10361
10363
|
Logger.error({ err: error, table: tableName, index: act.indexName, field: act.fieldName, msg: "\u521B\u5EFA\u7D22\u5F15\u5931\u8D25" });
|
|
10362
10364
|
throw error;
|
|
@@ -10373,6 +10375,7 @@ class SyncTable {
|
|
|
10373
10375
|
${cols}
|
|
10374
10376
|
) ENGINE=${ENGINE} DEFAULT CHARSET=${CHARSET} COLLATE=${COLLATE}`;
|
|
10375
10377
|
await db.unsafe(createSQL);
|
|
10378
|
+
Logger.debug(`[\u8868 ${tableName}] + \u521B\u5EFA\u8868\uFF08\u7CFB\u7EDF\u5B57\u6BB5 + \u4E1A\u52A1\u5B57\u6BB5\uFF09`);
|
|
10376
10379
|
const indexTasks = [];
|
|
10377
10380
|
const existingIndexes = {};
|
|
10378
10381
|
for (const sysField of systemIndexFields) {
|
|
@@ -10406,15 +10409,17 @@ class SyncTable {
|
|
|
10406
10409
|
const modifyClauses = [];
|
|
10407
10410
|
const defaultClauses = [];
|
|
10408
10411
|
const indexActions = [];
|
|
10412
|
+
const addedBusinessFields = [];
|
|
10413
|
+
const addedSystemFields = [];
|
|
10414
|
+
const modifiedFields = [];
|
|
10415
|
+
const defaultOnlyChangedFields = [];
|
|
10416
|
+
const compatibleTypeChanges = [];
|
|
10409
10417
|
for (const [fieldKey, fieldDef] of Object.entries(fields)) {
|
|
10410
10418
|
const dbFieldName = snakeCase(fieldKey);
|
|
10411
10419
|
if (existingColumns[dbFieldName]) {
|
|
10412
10420
|
const comparison = SyncTable.compareFieldDefinition(existingColumns[dbFieldName], fieldDef);
|
|
10413
10421
|
if (comparison.length > 0) {
|
|
10414
|
-
|
|
10415
|
-
const changeLabel = SyncTable.CHANGE_TYPE_LABELS[c.type] || "\u672A\u77E5";
|
|
10416
|
-
Logger.debug(` ~ \u4FEE\u6539 ${dbFieldName} ${changeLabel}: ${c.current} -> ${c.expected}`);
|
|
10417
|
-
}
|
|
10422
|
+
modifiedFields.push(dbFieldName);
|
|
10418
10423
|
const hasTypeChange = comparison.some((c) => c.type === "datatype");
|
|
10419
10424
|
const onlyDefaultChanged = comparison.every((c) => c.type === "default");
|
|
10420
10425
|
const defaultChanged = comparison.some((c) => c.type === "default");
|
|
@@ -10428,7 +10433,7 @@ class SyncTable {
|
|
|
10428
10433
|
`);
|
|
10429
10434
|
throw new Error(errorMsg);
|
|
10430
10435
|
}
|
|
10431
|
-
|
|
10436
|
+
compatibleTypeChanges.push(`${dbFieldName}: ${currentType} -> ${expectedType}`);
|
|
10432
10437
|
}
|
|
10433
10438
|
if (defaultChanged) {
|
|
10434
10439
|
const actualDefault = SyncTable.resolveDefaultValue(fieldDef.default ?? null, fieldDef.type);
|
|
@@ -10441,6 +10446,7 @@ class SyncTable {
|
|
|
10441
10446
|
if (fieldDef.type !== "text") {
|
|
10442
10447
|
const colQuoted = SyncTable.quoteIdentifier(dbFieldName);
|
|
10443
10448
|
defaultClauses.push(`ALTER COLUMN ${colQuoted} SET DEFAULT ${v}`);
|
|
10449
|
+
defaultOnlyChangedFields.push(dbFieldName);
|
|
10444
10450
|
}
|
|
10445
10451
|
}
|
|
10446
10452
|
}
|
|
@@ -10450,6 +10456,7 @@ class SyncTable {
|
|
|
10450
10456
|
changed = true;
|
|
10451
10457
|
}
|
|
10452
10458
|
} else {
|
|
10459
|
+
addedBusinessFields.push(dbFieldName);
|
|
10453
10460
|
addClauses.push(SyncTable.generateDDLClause(fieldKey, fieldDef, true));
|
|
10454
10461
|
changed = true;
|
|
10455
10462
|
}
|
|
@@ -10459,7 +10466,7 @@ class SyncTable {
|
|
|
10459
10466
|
if (!existingColumns[sysFieldName]) {
|
|
10460
10467
|
const colDef = SyncTable.getSystemColumnDef(sysFieldName);
|
|
10461
10468
|
if (colDef) {
|
|
10462
|
-
|
|
10469
|
+
addedSystemFields.push(sysFieldName);
|
|
10463
10470
|
addClauses.push(`ADD COLUMN ${colDef}`);
|
|
10464
10471
|
changed = true;
|
|
10465
10472
|
}
|
|
@@ -10493,6 +10500,49 @@ class SyncTable {
|
|
|
10493
10500
|
indexActions
|
|
10494
10501
|
};
|
|
10495
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);
|
|
10496
10546
|
await SyncTable.applyTablePlan(db, tableName, plan);
|
|
10497
10547
|
}
|
|
10498
10548
|
return plan;
|