@abtnode/core 1.16.47-beta-20250721-073316-a6de1fa3 → 1.16.47-beta-20250721-130532-61549a96
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.
|
@@ -10,6 +10,9 @@ const path = require('path');
|
|
|
10
10
|
|
|
11
11
|
const ignoreErrorTableNames = new Set(['runtime_insights', 'notification_receivers', 'notifications']);
|
|
12
12
|
const needCleanDataTableNames = new Set(['sessions']);
|
|
13
|
+
const notCheckPrimaryKeyTableNames = new Set(['tagging']);
|
|
14
|
+
|
|
15
|
+
const needBreakErrors = [];
|
|
13
16
|
|
|
14
17
|
function sortTableNames(tableNames, sort) {
|
|
15
18
|
return [...tableNames].sort((a, b) => {
|
|
@@ -49,10 +52,8 @@ async function migrateAllTablesNoModels(dbPath) {
|
|
|
49
52
|
// 把 tableNames 排序, 把被依赖的表放前面
|
|
50
53
|
tableNames = sortTableNames(tableNames, ['users', 'notification_receivers']);
|
|
51
54
|
|
|
52
|
-
console.log('Start migration database: ', dbPath);
|
|
53
|
-
|
|
54
55
|
for (const tableName of tableNames) {
|
|
55
|
-
console.log(`\n➡️ Starting migration for table: ${tableName}`);
|
|
56
|
+
console.log(`\n➡️ Starting migration for table: ${dbPath} ${tableName}`);
|
|
56
57
|
|
|
57
58
|
const colInfos = await sqliteDb.query(`PRAGMA TABLE_INFO("${tableName}")`, { type: QueryTypes.SELECT });
|
|
58
59
|
const sqliteSchema = {};
|
|
@@ -80,6 +81,14 @@ async function migrateAllTablesNoModels(dbPath) {
|
|
|
80
81
|
// Describe PG table to detect JSON/auto-inc
|
|
81
82
|
const pgSchema = await pgQI.describeTable(tableName);
|
|
82
83
|
|
|
84
|
+
const varcharLimits = {};
|
|
85
|
+
for (const [col, def] of Object.entries(pgSchema)) {
|
|
86
|
+
const m = def.type.match(/character varying\((\d+)\)/i);
|
|
87
|
+
if (m) {
|
|
88
|
+
varcharLimits[col] = parseInt(m[1], 10);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
83
92
|
// find JSON/JSONB
|
|
84
93
|
const jsonCols = Object.entries(pgSchema)
|
|
85
94
|
.filter(([, def]) => def.type && ['JSON', 'JSONB'].includes(def.type.toUpperCase()))
|
|
@@ -115,12 +124,22 @@ async function migrateAllTablesNoModels(dbPath) {
|
|
|
115
124
|
return jc ? `"${c}" = EXCLUDED."${c}"::${jc.type.toLowerCase()}` : `"${c}" = EXCLUDED."${c}"`;
|
|
116
125
|
})
|
|
117
126
|
.join(',');
|
|
118
|
-
|
|
127
|
+
if (notCheckPrimaryKeyTableNames.has(tableName)) {
|
|
128
|
+
console.log(' ❌ Not check primary key for, can not upsert only insert:', tableName);
|
|
129
|
+
// 只做普通插入
|
|
130
|
+
upsertSQL = `
|
|
131
|
+
INSERT INTO "${tableName}" (${insertColsList})
|
|
132
|
+
VALUES (${placeholders});
|
|
133
|
+
`;
|
|
134
|
+
} else {
|
|
135
|
+
// 正常的 upsert 逻辑
|
|
136
|
+
upsertSQL = `
|
|
119
137
|
INSERT INTO "${tableName}" (${insertColsList})
|
|
120
138
|
VALUES (${placeholders})
|
|
121
139
|
ON CONFLICT (${conflictKeys})
|
|
122
140
|
DO UPDATE SET ${updateSet};
|
|
123
141
|
`;
|
|
142
|
+
}
|
|
124
143
|
} else {
|
|
125
144
|
upsertSQL = `
|
|
126
145
|
INSERT INTO "${tableName}" (${insertColsList})
|
|
@@ -153,6 +172,18 @@ async function migrateAllTablesNoModels(dbPath) {
|
|
|
153
172
|
row.feedType = '';
|
|
154
173
|
}
|
|
155
174
|
|
|
175
|
+
// 对所有需插入的列, 操过长度的做截断
|
|
176
|
+
for (const col of insertCols) {
|
|
177
|
+
const val = row[col];
|
|
178
|
+
const limit = varcharLimits[col];
|
|
179
|
+
if (typeof val === 'string' && limit && val.length > limit) {
|
|
180
|
+
console.warn(`⚠️ Truncate "${col}" from length ${val.length} → ${limit}`);
|
|
181
|
+
console.log(' ❌ Old value:', val);
|
|
182
|
+
// 暂时不截断, 这样插入会失败, 后续会忽略这条数据的插入
|
|
183
|
+
// row[col] = val.slice(0, limit);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
156
187
|
for (const jc of jsonCols) {
|
|
157
188
|
const raw = row[jc.name];
|
|
158
189
|
let parsed = null;
|
|
@@ -265,7 +296,34 @@ async function migrateAllTablesNoModels(dbPath) {
|
|
|
265
296
|
}
|
|
266
297
|
continue;
|
|
267
298
|
}
|
|
268
|
-
|
|
299
|
+
if (err.message.includes('user_sessions_userDid_fkey')) {
|
|
300
|
+
const violationFilePath = dbPath.replace('.db', '.user_sessions_userDid_fkey.json');
|
|
301
|
+
console.log(
|
|
302
|
+
' ❌ Ignore error for user_sessions_userDid_fkey',
|
|
303
|
+
err.message,
|
|
304
|
+
'save to:',
|
|
305
|
+
violationFilePath,
|
|
306
|
+
'count: '
|
|
307
|
+
);
|
|
308
|
+
try {
|
|
309
|
+
await fsp.appendFile(
|
|
310
|
+
violationFilePath,
|
|
311
|
+
// eslint-disable-next-line prefer-template
|
|
312
|
+
JSON.stringify({ table: tableName, row, error: 'user_sessions_userDid_fkey' }) + '\n',
|
|
313
|
+
'utf8'
|
|
314
|
+
);
|
|
315
|
+
} catch (writeErr) {
|
|
316
|
+
console.warn(' ⚠️ Failed to write violation record:', writeErr);
|
|
317
|
+
}
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (needBreakErrors.length < 2000) {
|
|
322
|
+
console.error(' ❌ Error:', err.message);
|
|
323
|
+
needBreakErrors.push(err.message);
|
|
324
|
+
} else {
|
|
325
|
+
throw err;
|
|
326
|
+
}
|
|
269
327
|
}
|
|
270
328
|
}
|
|
271
329
|
|
|
@@ -418,6 +476,12 @@ async function migrationSqliteToPostgres(dataDir, dbPaths) {
|
|
|
418
476
|
await validateTableRowCounts(dbPath);
|
|
419
477
|
}
|
|
420
478
|
|
|
479
|
+
if (needBreakErrors.length > 0) {
|
|
480
|
+
console.error(' ❌ Has some errors, please check the violation files');
|
|
481
|
+
console.error(needBreakErrors.join('\n'));
|
|
482
|
+
throw new Error('Has some errors, please check the error log');
|
|
483
|
+
}
|
|
484
|
+
|
|
421
485
|
savePostgresLock(dataDir);
|
|
422
486
|
}
|
|
423
487
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.47-beta-20250721-
|
|
6
|
+
"version": "1.16.47-beta-20250721-130532-61549a96",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,22 +19,22 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/analytics": "1.16.47-beta-20250721-
|
|
23
|
-
"@abtnode/auth": "1.16.47-beta-20250721-
|
|
24
|
-
"@abtnode/certificate-manager": "1.16.47-beta-20250721-
|
|
25
|
-
"@abtnode/client": "1.16.47-beta-20250721-
|
|
26
|
-
"@abtnode/constant": "1.16.47-beta-20250721-
|
|
27
|
-
"@abtnode/cron": "1.16.47-beta-20250721-
|
|
28
|
-
"@abtnode/db-cache": "1.16.47-beta-20250721-
|
|
29
|
-
"@abtnode/docker-utils": "1.16.47-beta-20250721-
|
|
30
|
-
"@abtnode/logger": "1.16.47-beta-20250721-
|
|
31
|
-
"@abtnode/models": "1.16.47-beta-20250721-
|
|
32
|
-
"@abtnode/queue": "1.16.47-beta-20250721-
|
|
33
|
-
"@abtnode/rbac": "1.16.47-beta-20250721-
|
|
34
|
-
"@abtnode/router-provider": "1.16.47-beta-20250721-
|
|
35
|
-
"@abtnode/static-server": "1.16.47-beta-20250721-
|
|
36
|
-
"@abtnode/timemachine": "1.16.47-beta-20250721-
|
|
37
|
-
"@abtnode/util": "1.16.47-beta-20250721-
|
|
22
|
+
"@abtnode/analytics": "1.16.47-beta-20250721-130532-61549a96",
|
|
23
|
+
"@abtnode/auth": "1.16.47-beta-20250721-130532-61549a96",
|
|
24
|
+
"@abtnode/certificate-manager": "1.16.47-beta-20250721-130532-61549a96",
|
|
25
|
+
"@abtnode/client": "1.16.47-beta-20250721-130532-61549a96",
|
|
26
|
+
"@abtnode/constant": "1.16.47-beta-20250721-130532-61549a96",
|
|
27
|
+
"@abtnode/cron": "1.16.47-beta-20250721-130532-61549a96",
|
|
28
|
+
"@abtnode/db-cache": "1.16.47-beta-20250721-130532-61549a96",
|
|
29
|
+
"@abtnode/docker-utils": "1.16.47-beta-20250721-130532-61549a96",
|
|
30
|
+
"@abtnode/logger": "1.16.47-beta-20250721-130532-61549a96",
|
|
31
|
+
"@abtnode/models": "1.16.47-beta-20250721-130532-61549a96",
|
|
32
|
+
"@abtnode/queue": "1.16.47-beta-20250721-130532-61549a96",
|
|
33
|
+
"@abtnode/rbac": "1.16.47-beta-20250721-130532-61549a96",
|
|
34
|
+
"@abtnode/router-provider": "1.16.47-beta-20250721-130532-61549a96",
|
|
35
|
+
"@abtnode/static-server": "1.16.47-beta-20250721-130532-61549a96",
|
|
36
|
+
"@abtnode/timemachine": "1.16.47-beta-20250721-130532-61549a96",
|
|
37
|
+
"@abtnode/util": "1.16.47-beta-20250721-130532-61549a96",
|
|
38
38
|
"@arcblock/did": "1.20.16",
|
|
39
39
|
"@arcblock/did-auth": "1.20.16",
|
|
40
40
|
"@arcblock/did-ext": "1.20.16",
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"@arcblock/pm2-events": "^0.0.5",
|
|
46
46
|
"@arcblock/validator": "1.20.16",
|
|
47
47
|
"@arcblock/vc": "1.20.16",
|
|
48
|
-
"@blocklet/constant": "1.16.47-beta-20250721-
|
|
48
|
+
"@blocklet/constant": "1.16.47-beta-20250721-130532-61549a96",
|
|
49
49
|
"@blocklet/did-space-js": "^1.1.7",
|
|
50
|
-
"@blocklet/env": "1.16.47-beta-20250721-
|
|
50
|
+
"@blocklet/env": "1.16.47-beta-20250721-130532-61549a96",
|
|
51
51
|
"@blocklet/error": "^0.2.5",
|
|
52
|
-
"@blocklet/meta": "1.16.47-beta-20250721-
|
|
53
|
-
"@blocklet/resolver": "1.16.47-beta-20250721-
|
|
54
|
-
"@blocklet/sdk": "1.16.47-beta-20250721-
|
|
55
|
-
"@blocklet/store": "1.16.47-beta-20250721-
|
|
52
|
+
"@blocklet/meta": "1.16.47-beta-20250721-130532-61549a96",
|
|
53
|
+
"@blocklet/resolver": "1.16.47-beta-20250721-130532-61549a96",
|
|
54
|
+
"@blocklet/sdk": "1.16.47-beta-20250721-130532-61549a96",
|
|
55
|
+
"@blocklet/store": "1.16.47-beta-20250721-130532-61549a96",
|
|
56
56
|
"@blocklet/theme": "^3.0.26",
|
|
57
57
|
"@fidm/x509": "^1.2.1",
|
|
58
58
|
"@ocap/mcrypto": "1.20.16",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"jest": "^29.7.0",
|
|
117
117
|
"unzipper": "^0.10.11"
|
|
118
118
|
},
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "78041763148c9b98245c28ff176ff0fc9acbd071"
|
|
120
120
|
}
|