@blocklet/cli 1.16.45 → 1.16.46-beta-20250703-050038-4ba2582f
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/README.md +1 -1
- package/lib/commands/server/command.js +7 -0
- package/lib/commands/server/migration.js +55 -0
- package/lib/commands/server/start.js +10 -0
- package/lib/node.js +7 -0
- package/package.json +17 -16
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ const logs = require('./logs');
|
|
|
18
18
|
const status = require('./status');
|
|
19
19
|
const upgrade = require('./upgrade');
|
|
20
20
|
const rescue = require('./rescue');
|
|
21
|
+
const migration = require('./migration');
|
|
21
22
|
const { printVersionTip } = require('../../util');
|
|
22
23
|
|
|
23
24
|
module.exports = (parentCommand = '') => {
|
|
@@ -128,6 +129,12 @@ module.exports = (parentCommand = '') => {
|
|
|
128
129
|
.description('Do some server level cleanup work')
|
|
129
130
|
.action(parseOptions(cleanup.run));
|
|
130
131
|
|
|
132
|
+
program
|
|
133
|
+
.command('migration')
|
|
134
|
+
.option('--dialect <dialect>', 'Which dialect to migrate, available options: sqlite, postgres')
|
|
135
|
+
.description('Migrate database from sqlite to postgres')
|
|
136
|
+
.action(parseOptions(migration.run));
|
|
137
|
+
|
|
131
138
|
program.command('upgrade').description('Self-Upgrade Blocklet Server').action(parseOptions(upgrade.run));
|
|
132
139
|
|
|
133
140
|
program.on('--help', () => {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { sequelizeInstances } = require('@abtnode/models');
|
|
3
|
+
const { runSchemaMigrations } = require('@abtnode/core/lib/migrations');
|
|
4
|
+
const { removePostgresLock } = require('@abtnode/core/lib/util/migration-sqlite-to-postgres');
|
|
5
|
+
|
|
6
|
+
const { printInfo, printSuccess, printError } = require('../../util');
|
|
7
|
+
const { getNode } = require('../../node');
|
|
8
|
+
|
|
9
|
+
exports.run = async ({ dialect }) => {
|
|
10
|
+
const allowDialects = {
|
|
11
|
+
postgres: true,
|
|
12
|
+
sqlite: true,
|
|
13
|
+
};
|
|
14
|
+
if (!allowDialects[dialect]) {
|
|
15
|
+
printError(`Invalid dialect: ${dialect}, allowed dialects: ${Object.keys(allowDialects).join(', ')}`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { node } = await getNode({ dir: process.cwd() });
|
|
20
|
+
const dataDir = path.join(node.dataDirs.core, '..');
|
|
21
|
+
removePostgresLock(dataDir);
|
|
22
|
+
sequelizeInstances.clear();
|
|
23
|
+
|
|
24
|
+
const LAST_ABT_NODE_POSTGRES_URL = process.env.ABT_NODE_POSTGRES_URL;
|
|
25
|
+
process.env.ABT_NODE_POSTGRES_URL = '';
|
|
26
|
+
|
|
27
|
+
printInfo('Getting blocklets...');
|
|
28
|
+
let blocklets = [];
|
|
29
|
+
try {
|
|
30
|
+
blocklets = await node.getBlocklets();
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (err.message.includes('dose not exist') || err.message.includes('SQLITE_ERROR: no such table')) {
|
|
33
|
+
printError(`Failed to get blocklets: ${err.message}, you need ensure blocklet server start once.`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
printError(`Failed to get blocklets: ${err.message}`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
process.env.ABT_NODE_POSTGRES_URL = LAST_ABT_NODE_POSTGRES_URL;
|
|
42
|
+
await runSchemaMigrations({ dataDir, printInfo, printSuccess, migrationPostgres: true, blocklets });
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (err.message.includes('dose not exist') || err.message.includes('SQLITE_ERROR: no such table')) {
|
|
45
|
+
printError(`Failed to run migrations: ${err.message}, you need ensure blocklet server start once.`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
printError(`Failed to run migrations: ${err.message}`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
printSuccess(`Migration ${dialect} completed`);
|
|
53
|
+
printInfo('Please start server, will use Postgres database: blocklet server start');
|
|
54
|
+
process.exit(0);
|
|
55
|
+
};
|
|
@@ -40,6 +40,7 @@ const {
|
|
|
40
40
|
|
|
41
41
|
const { canUseFileSystemIsolateApi, SAFE_NODE_VERSION } = require('@abtnode/util/lib/security');
|
|
42
42
|
const { ensureDockerRedis } = require('@abtnode/core/lib/util/docker/ensure-docker-redis');
|
|
43
|
+
const { ensureDockerPostgres } = require('@abtnode/core/lib/util/docker/ensure-docker-postgres');
|
|
43
44
|
|
|
44
45
|
const { version } = require('../../../package.json');
|
|
45
46
|
const debug = require('../../debug')('start');
|
|
@@ -415,6 +416,14 @@ const exec = async ({ workingDir, config, dataDir, mode, updateDb, forceIntranet
|
|
|
415
416
|
printSuccess(`Using Redis Cache: ${process.env.ABT_NODE_CACHE_REDIS_URL}`);
|
|
416
417
|
}
|
|
417
418
|
|
|
419
|
+
if (!process.env.ABT_NODE_POSTGRES_URL) {
|
|
420
|
+
const postgresUrl = await ensureDockerPostgres(dataDir);
|
|
421
|
+
process.env.ABT_NODE_POSTGRES_URL = postgresUrl;
|
|
422
|
+
}
|
|
423
|
+
if (process.env.ABT_NODE_POSTGRES_URL) {
|
|
424
|
+
printSuccess(`Using Postgres: ${process.env.ABT_NODE_POSTGRES_URL}`);
|
|
425
|
+
}
|
|
426
|
+
|
|
418
427
|
const configFile = await getConfigFile(workingDir);
|
|
419
428
|
|
|
420
429
|
const proxyMaxMemoryLimit = get(config, 'node.runtimeConfig.proxyMaxMemoryLimit', PROXY_MAX_MEM_LIMIT_IN_MB);
|
|
@@ -580,6 +589,7 @@ const exec = async ({ workingDir, config, dataDir, mode, updateDb, forceIntranet
|
|
|
580
589
|
ABT_NODE_SESSION_SECRET: config.node.secret,
|
|
581
590
|
ABT_NODE_DATA_DIR: dataDir,
|
|
582
591
|
ABT_NODE_CACHE_REDIS_URL: process.env.ABT_NODE_CACHE_REDIS_URL,
|
|
592
|
+
ABT_NODE_POSTGRES_URL: process.env.ABT_NODE_POSTGRES_URL,
|
|
583
593
|
ABT_NODE_KERNEL_MODE: process.env.ABT_NODE_KERNEL_MODE,
|
|
584
594
|
ABT_NODE_BLOCKLET_MODE: process.env.ABT_NODE_BLOCKLET_MODE,
|
|
585
595
|
ABT_NODE_CONFIG_FILE: configFile,
|
package/lib/node.js
CHANGED
|
@@ -7,6 +7,7 @@ const security = require('@abtnode/util/lib/security');
|
|
|
7
7
|
const { WsClient } = require('@arcblock/ws');
|
|
8
8
|
const { isFromPublicKey } = require('@arcblock/did');
|
|
9
9
|
const { getBaseUrls } = require('@abtnode/core/lib/util');
|
|
10
|
+
const { ensureDockerPostgres } = require('@abtnode/core/lib/util/docker/ensure-docker-postgres');
|
|
10
11
|
|
|
11
12
|
const debug = require('./debug')('node');
|
|
12
13
|
const { version } = require('../package.json');
|
|
@@ -99,10 +100,16 @@ async function getNode({ dir = process.cwd() } = {}) {
|
|
|
99
100
|
if (!process.env.ABT_NODE_CACHE_SQLITE_PATH) {
|
|
100
101
|
process.env.ABT_NODE_CACHE_SQLITE_PATH = path.join(dataDir, 'core', 'db-cache.db');
|
|
101
102
|
}
|
|
103
|
+
|
|
102
104
|
if (typeof config.env?.ABT_NODE_DID_DOCUMENT_UPDATE !== 'undefined') {
|
|
103
105
|
process.env.ABT_NODE_DID_DOCUMENT_UPDATE = config.env.ABT_NODE_DID_DOCUMENT_UPDATE;
|
|
104
106
|
}
|
|
105
107
|
|
|
108
|
+
if (!process.env.ABT_NODE_POSTGRES_URL) {
|
|
109
|
+
const postgresUrl = await ensureDockerPostgres(dataDir);
|
|
110
|
+
process.env.ABT_NODE_POSTGRES_URL = postgresUrl;
|
|
111
|
+
}
|
|
112
|
+
|
|
106
113
|
util.ensurePermission(dataDir);
|
|
107
114
|
|
|
108
115
|
printInfo('Server config from', chalk.cyan(configFile));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/cli",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
4
4
|
"description": "Command line tools to manage Blocklet Server",
|
|
5
5
|
"homepage": "https://github.com/ArcBlock/blocklet-server#readme",
|
|
6
6
|
"bin": {
|
|
@@ -35,27 +35,28 @@
|
|
|
35
35
|
"url": "https://github.com/ArcBlock/blocklet-server/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@abtnode/blocklet-services": "1.16.
|
|
39
|
-
"@abtnode/client": "1.16.
|
|
40
|
-
"@abtnode/constant": "1.16.
|
|
41
|
-
"@abtnode/core": "1.16.
|
|
42
|
-
"@abtnode/db-cache": "1.16.
|
|
43
|
-
"@abtnode/logger": "1.16.
|
|
44
|
-
"@abtnode/
|
|
45
|
-
"@abtnode/
|
|
46
|
-
"@abtnode/
|
|
38
|
+
"@abtnode/blocklet-services": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
39
|
+
"@abtnode/client": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
40
|
+
"@abtnode/constant": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
41
|
+
"@abtnode/core": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
42
|
+
"@abtnode/db-cache": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
43
|
+
"@abtnode/logger": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
44
|
+
"@abtnode/models": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
45
|
+
"@abtnode/router-provider": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
46
|
+
"@abtnode/util": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
47
|
+
"@abtnode/webapp": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
47
48
|
"@arcblock/did": "1.20.14",
|
|
48
49
|
"@arcblock/event-hub": "1.20.14",
|
|
49
50
|
"@arcblock/ipfs-only-hash": "^0.0.2",
|
|
50
51
|
"@arcblock/jwt": "1.20.14",
|
|
51
52
|
"@arcblock/ws": "1.20.14",
|
|
52
|
-
"@blocklet/constant": "1.16.
|
|
53
|
+
"@blocklet/constant": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
53
54
|
"@blocklet/error": "^0.2.5",
|
|
54
55
|
"@blocklet/form-collector": "^0.1.8",
|
|
55
|
-
"@blocklet/images": "1.16.
|
|
56
|
-
"@blocklet/meta": "1.16.
|
|
57
|
-
"@blocklet/resolver": "1.16.
|
|
58
|
-
"@blocklet/store": "1.16.
|
|
56
|
+
"@blocklet/images": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
57
|
+
"@blocklet/meta": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
58
|
+
"@blocklet/resolver": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
59
|
+
"@blocklet/store": "1.16.46-beta-20250703-050038-4ba2582f",
|
|
59
60
|
"@blocklet/theme-builder": "^0.2.1",
|
|
60
61
|
"@ocap/client": "1.20.14",
|
|
61
62
|
"@ocap/mcrypto": "1.20.14",
|
|
@@ -153,7 +154,7 @@
|
|
|
153
154
|
"engines": {
|
|
154
155
|
"node": ">=14"
|
|
155
156
|
},
|
|
156
|
-
"gitHead": "
|
|
157
|
+
"gitHead": "8d7838277e51ecabae489db51937f6deb51e015f",
|
|
157
158
|
"devDependencies": {
|
|
158
159
|
"@types/fs-extra": "^11.0.4",
|
|
159
160
|
"@types/jest": "^29.5.13"
|