@zhijianma/studio 1.0.10
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/LICENSE +202 -0
- package/README.md +158 -0
- package/bin/cli.js +7 -0
- package/dist/app/friday/args.py +65 -0
- package/dist/app/friday/hook.py +52 -0
- package/dist/app/friday/main.py +164 -0
- package/dist/app/friday/model.py +124 -0
- package/dist/app/friday/tool/agentscope_tools.py +159 -0
- package/dist/app/friday/tool/utils.py +161 -0
- package/dist/app/friday/utils/common.py +28 -0
- package/dist/app/friday/utils/connect.py +63 -0
- package/dist/app/friday/utils/constants.py +8 -0
- package/dist/app/requirements.txt +1 -0
- package/dist/public/assets/001-aaron-Bb4ZO8rt.js +1 -0
- package/dist/public/assets/001-little girl-CnyQBZ0k.js +1 -0
- package/dist/public/assets/001-man-16-BO6NLPD_.js +1 -0
- package/dist/public/assets/002-avatar-C3FPnFjo.js +1 -0
- package/dist/public/assets/002-man-15-DfiiX2xR.js +1 -0
- package/dist/public/assets/002-old man-D4L-hA2l.js +1 -0
- package/dist/public/assets/003-avatar-UMXD80xE.js +1 -0
- package/dist/public/assets/003-cat-Cgyj1qJU.js +1 -0
- package/dist/public/assets/003-woman-20-Dy0WdjIG.js +1 -0
- package/dist/public/assets/004-avatar-D6Aw4tpO.js +1 -0
- package/dist/public/assets/004-dog-DUajs1ZO.js +1 -0
- package/dist/public/assets/004-woman-19-D5go5okE.js +1 -0
- package/dist/public/assets/005-avatar-NNQ3sWMe.js +1 -0
- package/dist/public/assets/005-child-SN-FoL0R.js +1 -0
- package/dist/public/assets/005-woman-18-AedSRg8a.js +1 -0
- package/dist/public/assets/006-avatar-FD8IUNL_.js +1 -0
- package/dist/public/assets/006-grandpa-T90IdpYr.js +1 -0
- package/dist/public/assets/006-man-14-DuMA-IZ-.js +1 -0
- package/dist/public/assets/007-avatar-eSQZtpkg.js +1 -0
- package/dist/public/assets/007-grandson-DV7UWhrR.js +1 -0
- package/dist/public/assets/007-man-13-owFTee2M.js +1 -0
- package/dist/public/assets/008-avatar-B9Rcm8D2.js +1 -0
- package/dist/public/assets/008-grandmother-1-BrQNVu9I.js +1 -0
- package/dist/public/assets/008-teenager-ClYxB7sG.js +1 -0
- package/dist/public/assets/009-avatar-DNSTEyOZ.js +1 -0
- package/dist/public/assets/009-grandfather-1-CPOn7LN0.js +1 -0
- package/dist/public/assets/009-grandmother-BAW_dEQC.js +1 -0
- package/dist/public/assets/010-avatar-CRXWH-A0.js +1 -0
- package/dist/public/assets/010-boy-1-C21LhAEr.js +1 -0
- package/dist/public/assets/011-woman-17-CI0UoPMR.js +1 -0
- package/dist/public/assets/012-avatar-BO5j-gGw.js +1 -0
- package/dist/public/assets/012-boy-T-hL8z9d.js +1 -0
- package/dist/public/assets/012-niece-M-tDMWMW.js +1 -0
- package/dist/public/assets/013-avatar-BTyOVKVo.js +1 -0
- package/dist/public/assets/013-granddaughter-D4VonRL-.js +1 -0
- package/dist/public/assets/013-woman-16-CuR7_ppw.js +1 -0
- package/dist/public/assets/014-avatar-DAW_Hvos.js +1 -0
- package/dist/public/assets/014-man-k8AXOF1Q.js +1 -0
- package/dist/public/assets/014-nurse-DnVigtmM.js +1 -0
- package/dist/public/assets/015-avatar-AxHR3j7h.js +1 -0
- package/dist/public/assets/015-woman-15-rDPwBxxc.js +1 -0
- package/dist/public/assets/015-woman-B71QRPrr.js +1 -0
- package/dist/public/assets/016-avatar-BVbMUisT.js +1 -0
- package/dist/public/assets/016-boy-BV_jzAu3.js +1 -0
- package/dist/public/assets/016-woman-14-D08zoPt9.js +1 -0
- package/dist/public/assets/017-gaming-BEpEpa1H.js +1 -0
- package/dist/public/assets/017-superpower-9xQAqiKN.js +1 -0
- package/dist/public/assets/017-uncle-EB1lmqAo.js +1 -0
- package/dist/public/assets/017-woman-13-BFsTAnGR.js +1 -0
- package/dist/public/assets/018-avatar-CnCLJXqW.js +1 -0
- package/dist/public/assets/018-young-QpIX6g3z.js +1 -0
- package/dist/public/assets/019-gaming-Dz5tR0Te.js +1 -0
- package/dist/public/assets/019-man-12-DiRb1dri.js +1 -0
- package/dist/public/assets/019-nephew-tXAgA9cr.js +1 -0
- package/dist/public/assets/020-avatar-Djtnu7jj.js +1 -0
- package/dist/public/assets/020-man-11-BNIZQyX4.js +1 -0
- package/dist/public/assets/020-young woman-BzklF8tq.js +1 -0
- package/dist/public/assets/021-aunt-CX9ikaTy.js +1 -0
- package/dist/public/assets/021-avatar-DP2sODK2.js +1 -0
- package/dist/public/assets/021-superhero-CIWREXp0.js +1 -0
- package/dist/public/assets/021-wizard-Dc9X50m_.js +1 -0
- package/dist/public/assets/021-woman-12-n9ipJK5z.js +1 -0
- package/dist/public/assets/022-father-B1_-ZTn1.js +1 -0
- package/dist/public/assets/022-woman-11-BUCsm06E.js +1 -0
- package/dist/public/assets/023-avatar-TeJ6vGqs.js +1 -0
- package/dist/public/assets/023-ghost-BYvGsa7H.js +1 -0
- package/dist/public/assets/023-man-10-Dfii-GE1.js +1 -0
- package/dist/public/assets/023-uncle-DoAMe1Iy.js +1 -0
- package/dist/public/assets/024-gaming-5ovd4aeT.js +1 -0
- package/dist/public/assets/024-man-9-CEenp_2W.js +1 -0
- package/dist/public/assets/024-prince-Fx3eCiNX.js +1 -0
- package/dist/public/assets/024-uncle-B6tqhqxU.js +1 -0
- package/dist/public/assets/025-gaming-CdlTp3Ub.js +1 -0
- package/dist/public/assets/025-man-8-Cfp6jNt4.js +1 -0
- package/dist/public/assets/025-man-BxhR-XTO.js +1 -0
- package/dist/public/assets/025-princess-Di5TdSnG.js +1 -0
- package/dist/public/assets/026-avatar-DojOPRVd.js +1 -0
- package/dist/public/assets/026-dad-CHaoMWM5.js +1 -0
- package/dist/public/assets/026-owl-Dl-UtZM8.js +1 -0
- package/dist/public/assets/026-woman-10-CywXJiaj.js +1 -0
- package/dist/public/assets/027-avatar-CrEyLmOb.js +1 -0
- package/dist/public/assets/027-girl-Box_GaMO.js +1 -0
- package/dist/public/assets/028-gaming-CmOZ2uGp.js +1 -0
- package/dist/public/assets/028-mom-tEacX7K4.js +1 -0
- package/dist/public/assets/028-woman-9-C1oq4sFk.js +1 -0
- package/dist/public/assets/029-boy-CVg6oMuZ.js +1 -0
- package/dist/public/assets/029-man-7-C4eeEeTQ.js +1 -0
- package/dist/public/assets/030-elf-C8vikAvx.js +1 -0
- package/dist/public/assets/030-gaming-ufCRMN7S.js +1 -0
- package/dist/public/assets/030-granddaughter-DVCp3D8k.js +1 -0
- package/dist/public/assets/030-woman-8-Bv_tRQci.js +1 -0
- package/dist/public/assets/031-avatar-D0u5HVaC.js +1 -0
- package/dist/public/assets/031-grandpa-jKj5oB8I.js +1 -0
- package/dist/public/assets/031-superhero-DfSkK-j2.js +1 -0
- package/dist/public/assets/031-woman-7-DJHfCbTS.js +1 -0
- package/dist/public/assets/032-avatar-BvY6LKIZ.js +1 -0
- package/dist/public/assets/032-grandson-DIjRxDr-.js +1 -0
- package/dist/public/assets/032-man-6-CU7pJmmt.js +1 -0
- package/dist/public/assets/033-avatar-Dviobgw8.js +1 -0
- package/dist/public/assets/033-elf-CTAEJgfN.js +1 -0
- package/dist/public/assets/033-grandfather-BCXPgoJj.js +1 -0
- package/dist/public/assets/033-man-5-wgMylvNO.js +1 -0
- package/dist/public/assets/034-avatar-BqtUHT3_.js +1 -0
- package/dist/public/assets/034-little girl-CrgnV25d.js +1 -0
- package/dist/public/assets/034-man-4-DJdzfcSi.js +1 -0
- package/dist/public/assets/035-gaming-Bp8xnJp_.js +1 -0
- package/dist/public/assets/035-mother-Ccg5FDO8.js +1 -0
- package/dist/public/assets/036-avatar-q6pZKQVf.js +1 -0
- package/dist/public/assets/036-father-DzpzeKJJ.js +1 -0
- package/dist/public/assets/036-goblin-vDsj4aP0.js +1 -0
- package/dist/public/assets/036-grandmother-BI_Fl_aR.js +1 -0
- package/dist/public/assets/037-avatar-CmfvVc7v.js +1 -0
- package/dist/public/assets/037-grandfather-Dtp4XH-s.js +1 -0
- package/dist/public/assets/037-sister-BQv83Uhf.js +1 -0
- package/dist/public/assets/038-gaming-UtXFtv5k.js +1 -0
- package/dist/public/assets/038-girl-Cwg5Rv36.js +1 -0
- package/dist/public/assets/038-gnome-HbogTmVa.js +1 -0
- package/dist/public/assets/038-woman-6-B7jMwsP0.js +1 -0
- package/dist/public/assets/039-avatar-Bb3kVg4l.js +1 -0
- package/dist/public/assets/039-man-3-BSjLnoLV.js +1 -0
- package/dist/public/assets/039-student-CIi32WG9.js +1 -0
- package/dist/public/assets/040-aunt-B5XQH_sJ.js +1 -0
- package/dist/public/assets/040-gaming-CzTjib4v.js +1 -0
- package/dist/public/assets/040-vampire-UFzaHu5c.js +1 -0
- package/dist/public/assets/040-woman-5-Byal-gfX.js +1 -0
- package/dist/public/assets/041-avatar-CPQN2PvT.js +1 -0
- package/dist/public/assets/041-little boy-DUZFMrmJ.js +1 -0
- package/dist/public/assets/041-queen-CqFzW3uO.js +1 -0
- package/dist/public/assets/041-woman-4-CKi_Q-ns.js +1 -0
- package/dist/public/assets/042-avatar-BatY-WQG.js +1 -0
- package/dist/public/assets/042-cyclops-DAxxBVqG.js +1 -0
- package/dist/public/assets/042-man-omzAnpu1.js +1 -0
- package/dist/public/assets/042-woman-3-2Ki1Qz3j.js +1 -0
- package/dist/public/assets/043-avatar-DN026abg.js +1 -0
- package/dist/public/assets/043-child-D8_xXkcm.js +1 -0
- package/dist/public/assets/043-genie-DK78Ykl6.js +1 -0
- package/dist/public/assets/043-woman-2-DMnB0A-0.js +1 -0
- package/dist/public/assets/044-avatar-Bz2FAXUw.js +1 -0
- package/dist/public/assets/044-avatar-DzDIyuj0.js +1 -0
- package/dist/public/assets/044-fairy-BT73odE0.js +1 -0
- package/dist/public/assets/044-sister-CtNPPHh-.js +1 -0
- package/dist/public/assets/045-avatar-DgiFAlxj.js +1 -0
- package/dist/public/assets/045-man-2-BZPavI2b.js +1 -0
- package/dist/public/assets/045-young-B39gytpm.js +1 -0
- package/dist/public/assets/046-avatar-ClHeZPOV.js +1 -0
- package/dist/public/assets/046-brother-BSvJBKnA.js +1 -0
- package/dist/public/assets/046-witch-CVjM2-iJ.js +1 -0
- package/dist/public/assets/046-woman-1-CHWuzLfU.js +1 -0
- package/dist/public/assets/047-avatar-DM01i1ZC.js +1 -0
- package/dist/public/assets/047-king-knA4oWNa.js +1 -0
- package/dist/public/assets/047-man-1-DRWdGzL5.js +1 -0
- package/dist/public/assets/048-father-B0wiM2h6.js +1 -0
- package/dist/public/assets/048-gaming-D7s83-h3.js +1 -0
- package/dist/public/assets/048-girl-CxGcfLgU.js +1 -0
- package/dist/public/assets/049-avatar-BfGDVwlO.js +1 -0
- package/dist/public/assets/049-little boy-Bu5mmsUf.js +1 -0
- package/dist/public/assets/049-man-B3xcAso3.js +1 -0
- package/dist/public/assets/050-avatar-itJOA0dd.js +1 -0
- package/dist/public/assets/050-boy-DEIcVyYT.js +1 -0
- package/dist/public/assets/050-knight-KRUkfXDS.js +1 -0
- package/dist/public/assets/051-avatar-fISL-mLU.js +1 -0
- package/dist/public/assets/052-avatar-BYrM0aPD.js +1 -0
- package/dist/public/assets/053-avatar-B-rnufvm.js +1 -0
- package/dist/public/assets/054-avatar-B7rwS7Qv.js +1 -0
- package/dist/public/assets/055-gaming-DqUOmMvT.js +1 -0
- package/dist/public/assets/056-avatar-D1lb7KL9.js +1 -0
- package/dist/public/assets/057-avatar-Df7NRaJW.js +1 -0
- package/dist/public/assets/058-avatar-C8zso2zk.js +1 -0
- package/dist/public/assets/059-avatar-zEhHpOcr.js +1 -0
- package/dist/public/assets/060-avatar-DkNabW8M.js +1 -0
- package/dist/public/assets/index-CWvY7i3l.css +1 -0
- package/dist/public/assets/index-Zxr-JuKD.js +820 -0
- package/dist/public/index.html +14 -0
- package/dist/public/logo.svg +42 -0
- package/dist/server/src/dao/FridayAppMessage.js +103 -0
- package/dist/server/src/dao/InputRequest.js +99 -0
- package/dist/server/src/dao/Message.js +42 -0
- package/dist/server/src/dao/Reply.js +96 -0
- package/dist/server/src/dao/Run.js +395 -0
- package/dist/server/src/dao/Trace.js +643 -0
- package/dist/server/src/database.js +54 -0
- package/dist/server/src/index.js +211 -0
- package/dist/server/src/migrations/1730000000000-AddMessageReplyForeignKey.js +216 -0
- package/dist/server/src/migrations/1740000000000-MigrateSpanTable.js +638 -0
- package/dist/server/src/migrations/index.js +19 -0
- package/dist/server/src/models/FridayApp.js +69 -0
- package/dist/server/src/models/FridayAppView.js +94 -0
- package/dist/server/src/models/InputRequest.js +41 -0
- package/dist/server/src/models/Message.js +39 -0
- package/dist/server/src/models/ModelInvocationView.js +127 -0
- package/dist/server/src/models/Reply.js +50 -0
- package/dist/server/src/models/Run.js +63 -0
- package/dist/server/src/models/RunView.js +111 -0
- package/dist/server/src/models/Trace.js +154 -0
- package/dist/server/src/otel/grpc-server.js +154 -0
- package/dist/server/src/otel/opentelemetry/proto/collector/trace/v1/trace_service.js +309 -0
- package/dist/server/src/otel/opentelemetry/proto/common/v1/common.js +747 -0
- package/dist/server/src/otel/opentelemetry/proto/resource/v1/resource.js +170 -0
- package/dist/server/src/otel/opentelemetry/proto/trace/v1/trace.js +1134 -0
- package/dist/server/src/otel/processor.js +395 -0
- package/dist/server/src/otel/router.js +128 -0
- package/dist/server/src/services/ReplyingStateManager.js +21 -0
- package/dist/server/src/trpc/router.js +385 -0
- package/dist/server/src/trpc/socket.js +589 -0
- package/dist/server/src/utils/index.js +17 -0
- package/dist/server/src/utils/processUtils.js +27 -0
- package/dist/shared/src/config/client.js +6 -0
- package/dist/shared/src/config/common.js +32 -0
- package/dist/shared/src/config/friday.js +168 -0
- package/dist/shared/src/config/index.js +19 -0
- package/dist/shared/src/config/server.js +104 -0
- package/dist/shared/src/index.js +18 -0
- package/dist/shared/src/types/index.js +20 -0
- package/dist/shared/src/types/messageForm.js +25 -0
- package/dist/shared/src/types/trace.js +20 -0
- package/dist/shared/src/types/trpc.js +98 -0
- package/dist/shared/src/types/usage.js +7 -0
- package/dist/shared/src/utils/banner.js +74 -0
- package/dist/shared/src/utils/objectUtils.js +74 -0
- package/dist/shared/src/utils/terminal.js +30 -0
- package/dist/shared/src/utils/timeUtils.js +86 -0
- package/package.json +89 -0
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MigrateSpanTable1740000000000 = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const objectUtils_1 = require("../../../shared/src/utils/objectUtils");
|
|
15
|
+
const timeUtils_1 = require("../../../shared/src/utils/timeUtils");
|
|
16
|
+
const Trace_1 = require("../models/Trace");
|
|
17
|
+
const processor_1 = require("../otel/processor");
|
|
18
|
+
const asString = (value, fallback = '') => typeof value === 'string' ? value : fallback;
|
|
19
|
+
const asNumber = (value, fallback = 0) => typeof value === 'number' ? value : fallback;
|
|
20
|
+
const asOptionalString = (value) => typeof value === 'string' ? value : undefined;
|
|
21
|
+
const asOptionalNumber = (value) => typeof value === 'number' ? value : undefined;
|
|
22
|
+
const toStringOrUndefined = (value) => value !== undefined && value !== null ? String(value) : undefined;
|
|
23
|
+
function parseJsonOrObject(value) {
|
|
24
|
+
if (typeof value === 'string') {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(value);
|
|
27
|
+
}
|
|
28
|
+
catch (_a) {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (value && typeof value === 'object') {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
function decodeStatus(status) {
|
|
38
|
+
var _a;
|
|
39
|
+
if (typeof status === 'string') {
|
|
40
|
+
const statusMap = {
|
|
41
|
+
OK: 1,
|
|
42
|
+
ERROR: 2,
|
|
43
|
+
UNSET: 0,
|
|
44
|
+
};
|
|
45
|
+
const upperStatus = status.toUpperCase();
|
|
46
|
+
return {
|
|
47
|
+
code: (_a = statusMap[upperStatus]) !== null && _a !== void 0 ? _a : 0,
|
|
48
|
+
message: '',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (status && typeof status === 'object') {
|
|
52
|
+
const s = status;
|
|
53
|
+
if ('code' in s && typeof s.code === 'number') {
|
|
54
|
+
return {
|
|
55
|
+
code: s.code,
|
|
56
|
+
message: typeof s.message === 'string' ? s.message : '',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { code: 0, message: '' };
|
|
61
|
+
}
|
|
62
|
+
function decodeEvents(eventsValue) {
|
|
63
|
+
if (!eventsValue)
|
|
64
|
+
return [];
|
|
65
|
+
let eventsArray = [];
|
|
66
|
+
if (typeof eventsValue === 'string') {
|
|
67
|
+
try {
|
|
68
|
+
eventsArray = JSON.parse(eventsValue);
|
|
69
|
+
}
|
|
70
|
+
catch (_a) {
|
|
71
|
+
eventsArray = [];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (Array.isArray(eventsValue)) {
|
|
75
|
+
eventsArray = eventsValue;
|
|
76
|
+
}
|
|
77
|
+
return eventsArray.map((event) => {
|
|
78
|
+
const e = event;
|
|
79
|
+
const timeUnixNano = asString(e.timestamp)
|
|
80
|
+
? (0, timeUtils_1.encodeUnixNano)(asString(e.timestamp))
|
|
81
|
+
: asString(e.timeUnixNano) || asString(e.time) || '0';
|
|
82
|
+
return {
|
|
83
|
+
name: asString(e.name),
|
|
84
|
+
time: timeUnixNano,
|
|
85
|
+
attributes: (e.attributes &&
|
|
86
|
+
typeof e.attributes === 'object' &&
|
|
87
|
+
e.attributes !== null
|
|
88
|
+
? e.attributes
|
|
89
|
+
: {}),
|
|
90
|
+
droppedAttributesCount: asNumber(e.droppedAttributesCount, 0),
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function decodeResource(attributes) {
|
|
95
|
+
const serviceName = (0, objectUtils_1.getNestedValue)(attributes, 'service.name') ||
|
|
96
|
+
(0, objectUtils_1.getNestedValue)(attributes, 'project.service_name');
|
|
97
|
+
const resourceAttributes = {};
|
|
98
|
+
if (serviceName) {
|
|
99
|
+
resourceAttributes['service.name'] = serviceName;
|
|
100
|
+
}
|
|
101
|
+
const resourceKeys = [
|
|
102
|
+
'service.namespace',
|
|
103
|
+
'service.version',
|
|
104
|
+
'service.instance.id',
|
|
105
|
+
];
|
|
106
|
+
for (const key of resourceKeys) {
|
|
107
|
+
const value = (0, objectUtils_1.getNestedValue)(attributes, key);
|
|
108
|
+
if (value !== undefined) {
|
|
109
|
+
resourceAttributes[key] = value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
attributes: resourceAttributes,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function decodeScope() {
|
|
117
|
+
return {
|
|
118
|
+
name: 'agentscope',
|
|
119
|
+
version: '1.0.7',
|
|
120
|
+
attributes: {},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function getConversationId(attributes, record) {
|
|
124
|
+
return (toStringOrUndefined((0, objectUtils_1.getNestedValue)(attributes, 'gen_ai.conversation.id')) ||
|
|
125
|
+
toStringOrUndefined((0, objectUtils_1.getNestedValue)(attributes, 'project.run_id')) ||
|
|
126
|
+
toStringOrUndefined(record.conversationId) ||
|
|
127
|
+
toStringOrUndefined(record.conversation_id) ||
|
|
128
|
+
'unknown');
|
|
129
|
+
}
|
|
130
|
+
function getSpanId(record, attributes) {
|
|
131
|
+
const spanId = toStringOrUndefined(record.id) ||
|
|
132
|
+
toStringOrUndefined(record.spanId) ||
|
|
133
|
+
toStringOrUndefined((0, objectUtils_1.getNestedValue)(attributes, 'span.id')) ||
|
|
134
|
+
toStringOrUndefined((0, objectUtils_1.getNestedValue)(attributes, 'spanId'));
|
|
135
|
+
if (!spanId) {
|
|
136
|
+
throw new Error(`Cannot determine spanId for record. Record has no 'id' field: ${JSON.stringify(record)}`);
|
|
137
|
+
}
|
|
138
|
+
return spanId;
|
|
139
|
+
}
|
|
140
|
+
// Helper methods to extract key fields (similar to SpanDao)
|
|
141
|
+
function extractServiceName(resource) {
|
|
142
|
+
const value = (0, objectUtils_1.getNestedValue)(resource.attributes, 'service.name');
|
|
143
|
+
return typeof value === 'string' ? value : undefined;
|
|
144
|
+
}
|
|
145
|
+
function extractOperationName(attributes) {
|
|
146
|
+
const value = (0, objectUtils_1.getNestedValue)(attributes, 'gen_ai.operation.name');
|
|
147
|
+
return typeof value === 'string' ? value : undefined;
|
|
148
|
+
}
|
|
149
|
+
function extractInstrumentationName(scope) {
|
|
150
|
+
// Try to get from attributes first (for backward compatibility)
|
|
151
|
+
const valueFromAttributes = (0, objectUtils_1.getNestedValue)(scope.attributes, 'server.name');
|
|
152
|
+
if (typeof valueFromAttributes === 'string') {
|
|
153
|
+
return valueFromAttributes;
|
|
154
|
+
}
|
|
155
|
+
// Fallback to scope.name
|
|
156
|
+
return scope.name;
|
|
157
|
+
}
|
|
158
|
+
function extractInstrumentationVersion(scope) {
|
|
159
|
+
// Try to get from attributes first (for backward compatibility)
|
|
160
|
+
const valueFromAttributes = (0, objectUtils_1.getNestedValue)(scope.attributes, 'server.version');
|
|
161
|
+
if (typeof valueFromAttributes === 'string') {
|
|
162
|
+
return valueFromAttributes;
|
|
163
|
+
}
|
|
164
|
+
// Fallback to scope.version
|
|
165
|
+
return scope.version;
|
|
166
|
+
}
|
|
167
|
+
function extractModel(attributes) {
|
|
168
|
+
const value = (0, objectUtils_1.getNestedValue)(attributes, 'gen_ai.request.model');
|
|
169
|
+
return typeof value === 'string' ? value : undefined;
|
|
170
|
+
}
|
|
171
|
+
function extractInputTokens(attributes) {
|
|
172
|
+
const value = (0, objectUtils_1.getNestedValue)(attributes, 'gen_ai.usage.input_tokens');
|
|
173
|
+
return typeof value === 'number' ? value : undefined;
|
|
174
|
+
}
|
|
175
|
+
function extractOutputTokens(attributes) {
|
|
176
|
+
const value = (0, objectUtils_1.getNestedValue)(attributes, 'gen_ai.usage.output_tokens');
|
|
177
|
+
return typeof value === 'number' ? value : undefined;
|
|
178
|
+
}
|
|
179
|
+
function calculateTotalTokens(inputTokens, outputTokens) {
|
|
180
|
+
// If both are numbers, return their sum
|
|
181
|
+
if (typeof inputTokens === 'number' && typeof outputTokens === 'number') {
|
|
182
|
+
return inputTokens + outputTokens;
|
|
183
|
+
}
|
|
184
|
+
// If only inputTokens is available, return it
|
|
185
|
+
if (typeof inputTokens === 'number') {
|
|
186
|
+
return inputTokens;
|
|
187
|
+
}
|
|
188
|
+
// If only outputTokens is available, return it
|
|
189
|
+
if (typeof outputTokens === 'number') {
|
|
190
|
+
return outputTokens;
|
|
191
|
+
}
|
|
192
|
+
// If neither is available, return undefined
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
function convertOldRecordToSpanTable(oldRecord) {
|
|
196
|
+
const r = oldRecord;
|
|
197
|
+
let attributes = parseJsonOrObject(r.attributes);
|
|
198
|
+
const convertedResult = processor_1.SpanProcessor.convertOldProtocolToNew(attributes, {
|
|
199
|
+
name: asString(r.name),
|
|
200
|
+
});
|
|
201
|
+
const spanName = convertedResult.span_name || asString(r.name);
|
|
202
|
+
attributes = convertedResult.attributes || attributes;
|
|
203
|
+
const startTimeUnixNano = asString(r.startTime)
|
|
204
|
+
? (0, timeUtils_1.encodeUnixNano)(asString(r.startTime))
|
|
205
|
+
: asString(r.startTimeUnixNano, '0');
|
|
206
|
+
const endTimeUnixNano = asString(r.endTime)
|
|
207
|
+
? (0, timeUtils_1.encodeUnixNano)(asString(r.endTime))
|
|
208
|
+
: asString(r.endTimeUnixNano, '0');
|
|
209
|
+
const latencyNs = asNumber(r.latencyMs, 0) > 0
|
|
210
|
+
? asNumber(r.latencyMs) * 1000000
|
|
211
|
+
: asNumber(r.latencyNs, 0) > 0
|
|
212
|
+
? asNumber(r.latencyNs)
|
|
213
|
+
: (0, timeUtils_1.getTimeDifferenceNano)(startTimeUnixNano, endTimeUnixNano);
|
|
214
|
+
const statusObj = decodeStatus(r.status);
|
|
215
|
+
const statusMessage = asOptionalString(r.statusMessage);
|
|
216
|
+
const status = statusMessage
|
|
217
|
+
? Object.assign(Object.assign({}, statusObj), { message: statusMessage }) : statusObj;
|
|
218
|
+
const events = decodeEvents(r.events);
|
|
219
|
+
const resource = decodeResource(attributes);
|
|
220
|
+
const scope = decodeScope();
|
|
221
|
+
const conversationId = getConversationId(attributes, r);
|
|
222
|
+
const spanId = getSpanId(r, attributes);
|
|
223
|
+
// Extract key fields for indexing
|
|
224
|
+
const serviceName = extractServiceName(resource);
|
|
225
|
+
const operationName = extractOperationName(attributes);
|
|
226
|
+
const instrumentationName = extractInstrumentationName(scope);
|
|
227
|
+
const instrumentationVersion = extractInstrumentationVersion(scope);
|
|
228
|
+
const model = extractModel(attributes);
|
|
229
|
+
const inputTokens = extractInputTokens(attributes);
|
|
230
|
+
const outputTokens = extractOutputTokens(attributes);
|
|
231
|
+
const totalTokens = calculateTotalTokens(inputTokens, outputTokens);
|
|
232
|
+
const statusCode = statusObj.code || 0;
|
|
233
|
+
const span = new Trace_1.SpanTable();
|
|
234
|
+
Object.assign(span, {
|
|
235
|
+
id: String(spanId),
|
|
236
|
+
traceId: toStringOrUndefined(r.traceId) || '',
|
|
237
|
+
spanId: String(spanId),
|
|
238
|
+
traceState: toStringOrUndefined(r.traceState),
|
|
239
|
+
parentSpanId: toStringOrUndefined(r.parentSpanId),
|
|
240
|
+
flags: asOptionalNumber(r.flags),
|
|
241
|
+
name: spanName,
|
|
242
|
+
kind: asNumber(r.kind, 0),
|
|
243
|
+
startTimeUnixNano: startTimeUnixNano,
|
|
244
|
+
endTimeUnixNano: endTimeUnixNano,
|
|
245
|
+
attributes: attributes,
|
|
246
|
+
droppedAttributesCount: 0,
|
|
247
|
+
events: events,
|
|
248
|
+
droppedEventsCount: 0,
|
|
249
|
+
links: [],
|
|
250
|
+
droppedLinksCount: 0,
|
|
251
|
+
status: status,
|
|
252
|
+
resource: resource,
|
|
253
|
+
scope: scope,
|
|
254
|
+
statusCode: statusCode,
|
|
255
|
+
serviceName: serviceName,
|
|
256
|
+
operationName: operationName,
|
|
257
|
+
instrumentationName: instrumentationName,
|
|
258
|
+
instrumentationVersion: instrumentationVersion,
|
|
259
|
+
model: model,
|
|
260
|
+
inputTokens: inputTokens,
|
|
261
|
+
outputTokens: outputTokens,
|
|
262
|
+
totalTokens: totalTokens,
|
|
263
|
+
conversationId: conversationId,
|
|
264
|
+
latencyNs: latencyNs,
|
|
265
|
+
});
|
|
266
|
+
return span;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Migration: Migrate old span_table structure to new structure
|
|
270
|
+
*
|
|
271
|
+
* Tasks:
|
|
272
|
+
* 1. Check if table exists and if migration has already been completed
|
|
273
|
+
* 2. Drop related views
|
|
274
|
+
* 3. Backup old table
|
|
275
|
+
* 4. Create new table structure
|
|
276
|
+
* 5. Migrate historical data
|
|
277
|
+
* 6. Delete backup table
|
|
278
|
+
*/
|
|
279
|
+
class MigrateSpanTable1740000000000 {
|
|
280
|
+
constructor() {
|
|
281
|
+
this.name = 'MigrateSpanTable1740000000000';
|
|
282
|
+
}
|
|
283
|
+
up(queryRunner) {
|
|
284
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
+
var _a, _b;
|
|
286
|
+
console.log('Starting migration: Migrating SpanTable structure...');
|
|
287
|
+
const tableName = 'span_table';
|
|
288
|
+
const viewName = 'model_invocation_view';
|
|
289
|
+
const oldTableName = 'span_table_old_backup';
|
|
290
|
+
// ========================================
|
|
291
|
+
// Step 1: Check if table exists
|
|
292
|
+
// ========================================
|
|
293
|
+
console.log('Step 1: Checking table structure...');
|
|
294
|
+
if (!(yield queryRunner.hasTable(tableName))) {
|
|
295
|
+
console.log('⏭️ span_table does not exist. Skipping migration.');
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const table = yield queryRunner.getTable(tableName);
|
|
299
|
+
if (!table) {
|
|
300
|
+
console.log('Unable to get table structure. Skipping migration.');
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
// Check if migration has already been completed
|
|
304
|
+
// New structure has spanId and instrumentationVersion columns
|
|
305
|
+
const hasSpanIdColumn = table.findColumnByName('spanId') !== undefined;
|
|
306
|
+
const hasInstrumentationVersion = table.findColumnByName('instrumentationVersion') !== undefined;
|
|
307
|
+
if (hasSpanIdColumn && hasInstrumentationVersion) {
|
|
308
|
+
console.log('✅ Table already has new structure. Migration already completed.');
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// ========================================
|
|
312
|
+
// Step 2: Drop related views
|
|
313
|
+
// ========================================
|
|
314
|
+
console.log('Step 2: Dropping related views...');
|
|
315
|
+
try {
|
|
316
|
+
yield queryRunner.query(`DROP VIEW IF EXISTS ${viewName}`);
|
|
317
|
+
console.log(`Dropped view ${viewName}`);
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
console.warn(`Error dropping view (may not exist):`, error);
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
yield queryRunner.query(`DELETE FROM typeorm_metadata WHERE type = 'VIEW' AND name = ?`, [viewName]);
|
|
324
|
+
}
|
|
325
|
+
catch (_c) {
|
|
326
|
+
// Ignore error, table may not exist
|
|
327
|
+
}
|
|
328
|
+
// ========================================
|
|
329
|
+
// Step 3: Backup old table
|
|
330
|
+
// ========================================
|
|
331
|
+
console.log('Step 3: Backing up old table...');
|
|
332
|
+
// If backup table already exists, drop it first
|
|
333
|
+
if (yield queryRunner.hasTable(oldTableName)) {
|
|
334
|
+
yield queryRunner.dropTable(oldTableName, true);
|
|
335
|
+
}
|
|
336
|
+
yield queryRunner.query(`ALTER TABLE "${tableName}" RENAME TO "${oldTableName}"`);
|
|
337
|
+
console.log(`Renamed table ${tableName} -> ${oldTableName}`);
|
|
338
|
+
// ========================================
|
|
339
|
+
// Step 4: Create new table structure
|
|
340
|
+
// ========================================
|
|
341
|
+
console.log('Step 4: Creating new table structure...');
|
|
342
|
+
yield queryRunner.createTable(new typeorm_1.Table({
|
|
343
|
+
name: tableName,
|
|
344
|
+
columns: [
|
|
345
|
+
{
|
|
346
|
+
name: 'id',
|
|
347
|
+
type: 'varchar',
|
|
348
|
+
isPrimary: true,
|
|
349
|
+
isNullable: false,
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
name: 'traceId',
|
|
353
|
+
type: 'varchar',
|
|
354
|
+
isNullable: false,
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
name: 'spanId',
|
|
358
|
+
type: 'varchar',
|
|
359
|
+
isNullable: false,
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
name: 'traceState',
|
|
363
|
+
type: 'varchar',
|
|
364
|
+
isNullable: true,
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
name: 'parentSpanId',
|
|
368
|
+
type: 'varchar',
|
|
369
|
+
isNullable: true,
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: 'flags',
|
|
373
|
+
type: 'integer',
|
|
374
|
+
isNullable: true,
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
name: 'name',
|
|
378
|
+
type: 'varchar',
|
|
379
|
+
isNullable: false,
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
name: 'kind',
|
|
383
|
+
type: 'integer',
|
|
384
|
+
isNullable: false,
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
name: 'startTimeUnixNano',
|
|
388
|
+
type: 'varchar',
|
|
389
|
+
isNullable: false,
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
name: 'endTimeUnixNano',
|
|
393
|
+
type: 'varchar',
|
|
394
|
+
isNullable: false,
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
name: 'attributes',
|
|
398
|
+
type: 'json',
|
|
399
|
+
isNullable: false,
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
name: 'droppedAttributesCount',
|
|
403
|
+
type: 'integer',
|
|
404
|
+
isNullable: true,
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
name: 'events',
|
|
408
|
+
type: 'json',
|
|
409
|
+
isNullable: true,
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
name: 'droppedEventsCount',
|
|
413
|
+
type: 'integer',
|
|
414
|
+
isNullable: true,
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
name: 'links',
|
|
418
|
+
type: 'json',
|
|
419
|
+
isNullable: true,
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
name: 'droppedLinksCount',
|
|
423
|
+
type: 'integer',
|
|
424
|
+
isNullable: true,
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
name: 'status',
|
|
428
|
+
type: 'json',
|
|
429
|
+
isNullable: false,
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
name: 'resource',
|
|
433
|
+
type: 'json',
|
|
434
|
+
isNullable: false,
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: 'scope',
|
|
438
|
+
type: 'json',
|
|
439
|
+
isNullable: false,
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
name: 'statusCode',
|
|
443
|
+
type: 'integer',
|
|
444
|
+
isNullable: true,
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
name: 'serviceName',
|
|
448
|
+
type: 'varchar',
|
|
449
|
+
isNullable: true,
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: 'operationName',
|
|
453
|
+
type: 'varchar',
|
|
454
|
+
isNullable: true,
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
name: 'instrumentationName',
|
|
458
|
+
type: 'varchar',
|
|
459
|
+
isNullable: true,
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
name: 'instrumentationVersion',
|
|
463
|
+
type: 'varchar',
|
|
464
|
+
isNullable: true,
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
name: 'model',
|
|
468
|
+
type: 'varchar',
|
|
469
|
+
isNullable: true,
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
name: 'inputTokens',
|
|
473
|
+
type: 'integer',
|
|
474
|
+
isNullable: true,
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
name: 'outputTokens',
|
|
478
|
+
type: 'integer',
|
|
479
|
+
isNullable: true,
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: 'totalTokens',
|
|
483
|
+
type: 'integer',
|
|
484
|
+
isNullable: true,
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
name: 'conversationId',
|
|
488
|
+
type: 'varchar',
|
|
489
|
+
isNullable: true,
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
name: 'latencyNs',
|
|
493
|
+
type: 'float',
|
|
494
|
+
isNullable: false,
|
|
495
|
+
},
|
|
496
|
+
],
|
|
497
|
+
indices: [
|
|
498
|
+
{
|
|
499
|
+
name: 'IDX_span_traceId',
|
|
500
|
+
columnNames: ['traceId'],
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
name: 'IDX_span_spanId',
|
|
504
|
+
columnNames: ['spanId'],
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
name: 'IDX_span_parentSpanId',
|
|
508
|
+
columnNames: ['parentSpanId'],
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
name: 'IDX_span_startTimeUnixNano',
|
|
512
|
+
columnNames: ['startTimeUnixNano'],
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
name: 'IDX_span_statusCode',
|
|
516
|
+
columnNames: ['statusCode'],
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
name: 'IDX_span_latencyNs',
|
|
520
|
+
columnNames: ['latencyNs'],
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
name: 'IDX_span_serviceName',
|
|
524
|
+
columnNames: ['serviceName'],
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
name: 'IDX_span_operationName',
|
|
528
|
+
columnNames: ['operationName'],
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
name: 'IDX_span_instrumentationName',
|
|
532
|
+
columnNames: ['instrumentationName'],
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
name: 'IDX_span_model',
|
|
536
|
+
columnNames: ['model'],
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
name: 'IDX_span_inputTokens',
|
|
540
|
+
columnNames: ['inputTokens'],
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
name: 'IDX_span_outputTokens',
|
|
544
|
+
columnNames: ['outputTokens'],
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
name: 'IDX_span_totalTokens',
|
|
548
|
+
columnNames: ['totalTokens'],
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
name: 'IDX_span_conversationId',
|
|
552
|
+
columnNames: ['conversationId'],
|
|
553
|
+
},
|
|
554
|
+
],
|
|
555
|
+
}), true);
|
|
556
|
+
console.log('New table structure created successfully');
|
|
557
|
+
// ========================================
|
|
558
|
+
// Step 5: Migrate historical data
|
|
559
|
+
// ========================================
|
|
560
|
+
console.log('Step 5: Migrating historical data...');
|
|
561
|
+
const oldRecords = yield queryRunner.query(`SELECT * FROM ${oldTableName}`);
|
|
562
|
+
if (oldRecords.length === 0) {
|
|
563
|
+
console.log('No data to migrate. Dropping backup table');
|
|
564
|
+
yield queryRunner.dropTable(oldTableName, true);
|
|
565
|
+
console.log('✅ Migration completed!');
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
console.log(`Found ${oldRecords.length} records to migrate`);
|
|
569
|
+
let migratedCount = 0;
|
|
570
|
+
let errorCount = 0;
|
|
571
|
+
const batchSize = 100;
|
|
572
|
+
for (let i = 0; i < oldRecords.length; i += batchSize) {
|
|
573
|
+
const batch = oldRecords.slice(i, i + batchSize);
|
|
574
|
+
const spanTableArray = [];
|
|
575
|
+
for (const oldRecord of batch) {
|
|
576
|
+
try {
|
|
577
|
+
const spanTable = convertOldRecordToSpanTable(oldRecord);
|
|
578
|
+
spanTableArray.push(spanTable);
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
console.error(`Failed to convert record (id: ${(oldRecord === null || oldRecord === void 0 ? void 0 : oldRecord.id) || 'unknown'}):`, error);
|
|
582
|
+
errorCount++;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (spanTableArray.length > 0) {
|
|
586
|
+
try {
|
|
587
|
+
// Use queryRunner.manager to save data
|
|
588
|
+
yield queryRunner.manager.save(Trace_1.SpanTable, spanTableArray);
|
|
589
|
+
migratedCount += spanTableArray.length;
|
|
590
|
+
}
|
|
591
|
+
catch (error) {
|
|
592
|
+
console.error(`Batch save failed:`, error);
|
|
593
|
+
errorCount += spanTableArray.length;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if ((i + batchSize) % 1000 === 0 ||
|
|
597
|
+
i + batchSize >= oldRecords.length) {
|
|
598
|
+
console.log(`Progress: Migrated ${Math.min(i + batchSize, oldRecords.length)}/${oldRecords.length} records`);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
console.log(`Data migration completed. Success: ${migratedCount}, Failed: ${errorCount}`);
|
|
602
|
+
// ========================================
|
|
603
|
+
// Step 6: Validate and drop backup table
|
|
604
|
+
// ========================================
|
|
605
|
+
console.log('Step 6: Validating data and dropping backup table...');
|
|
606
|
+
const newTableCount = yield queryRunner.query(`SELECT COUNT(*) as count FROM ${tableName}`);
|
|
607
|
+
const count = ((_a = newTableCount[0]) === null || _a === void 0 ? void 0 : _a.count) || ((_b = newTableCount[0]) === null || _b === void 0 ? void 0 : _b.COUNT) || 0;
|
|
608
|
+
if (count !== migratedCount) {
|
|
609
|
+
console.warn(`Warning: New table record count (${count}) does not match migrated count (${migratedCount})`);
|
|
610
|
+
}
|
|
611
|
+
yield queryRunner.dropTable(oldTableName, true);
|
|
612
|
+
console.log('Backup table dropped');
|
|
613
|
+
console.log('✅ Migration completed!');
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
down(queryRunner) {
|
|
617
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
618
|
+
console.log('Starting migration rollback...');
|
|
619
|
+
const tableName = 'span_table';
|
|
620
|
+
const oldTableName = 'span_table_old_backup';
|
|
621
|
+
// If backup table exists, restore it
|
|
622
|
+
if (yield queryRunner.hasTable(oldTableName)) {
|
|
623
|
+
// Drop new table
|
|
624
|
+
if (yield queryRunner.hasTable(tableName)) {
|
|
625
|
+
yield queryRunner.dropTable(tableName, true);
|
|
626
|
+
}
|
|
627
|
+
// Restore old table
|
|
628
|
+
yield queryRunner.query(`ALTER TABLE "${oldTableName}" RENAME TO "${tableName}"`);
|
|
629
|
+
console.log('Restored old table structure');
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
console.warn('Backup table does not exist. Cannot rollback');
|
|
633
|
+
}
|
|
634
|
+
console.log('✅ Rollback completed');
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
exports.MigrateSpanTable1740000000000 = MigrateSpanTable1740000000000;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 迁移管理中心
|
|
4
|
+
*
|
|
5
|
+
* 所有迁移文件在这里统一管理和导出
|
|
6
|
+
* 添加新迁移时,按时间戳顺序添加到数组中
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.migrations = void 0;
|
|
10
|
+
const _1730000000000_AddMessageReplyForeignKey_1 = require("./1730000000000-AddMessageReplyForeignKey");
|
|
11
|
+
const _1740000000000_MigrateSpanTable_1 = require("./1740000000000-MigrateSpanTable");
|
|
12
|
+
/**
|
|
13
|
+
* 所有迁移列表(按时间戳顺序)
|
|
14
|
+
*/
|
|
15
|
+
exports.migrations = [
|
|
16
|
+
_1730000000000_AddMessageReplyForeignKey_1.AddMessageReplyForeignKey1730000000000,
|
|
17
|
+
_1740000000000_MigrateSpanTable_1.MigrateSpanTable1740000000000,
|
|
18
|
+
// 未来的迁移在这里添加
|
|
19
|
+
];
|