@datatruck/cli 0.40.2 → 0.40.3
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/lib/actions/BackupAction.js +1 -1
- package/lib/actions/ExportAction.js +1 -1
- package/lib/actions/RestoreAction.js +1 -1
- package/lib/utils/cli.js +1 -1
- package/lib/utils/mysql.js +28 -18
- package/lib/utils/temp.d.ts +2 -2
- package/lib/utils/temp.js +6 -5
- package/package.json +3 -3
|
@@ -249,7 +249,7 @@ class BackupAction {
|
|
|
249
249
|
}
|
|
250
250
|
async exec() {
|
|
251
251
|
const { options, settings } = this;
|
|
252
|
-
const gc = new temp_1.GargabeCollector();
|
|
252
|
+
const gc = new temp_1.GargabeCollector(this.options.verbose);
|
|
253
253
|
const pm = new progress_1.ProgressManager({
|
|
254
254
|
verbose: options.verbose,
|
|
255
255
|
tty: settings.tty,
|
|
@@ -155,7 +155,7 @@ class ExportAction {
|
|
|
155
155
|
}
|
|
156
156
|
async exec() {
|
|
157
157
|
const { options, settings } = this;
|
|
158
|
-
const gc = new temp_1.GargabeCollector();
|
|
158
|
+
const gc = new temp_1.GargabeCollector(this.options.verbose);
|
|
159
159
|
const pm = new progress_1.ProgressManager({
|
|
160
160
|
verbose: options.verbose,
|
|
161
161
|
tty: settings.tty,
|
|
@@ -168,7 +168,7 @@ class RestoreAction {
|
|
|
168
168
|
}
|
|
169
169
|
async exec() {
|
|
170
170
|
const { options, settings } = this;
|
|
171
|
-
const gc = new temp_1.GargabeCollector();
|
|
171
|
+
const gc = new temp_1.GargabeCollector(this.options.verbose);
|
|
172
172
|
const pm = new progress_1.ProgressManager({
|
|
173
173
|
verbose: options.verbose,
|
|
174
174
|
tty: settings.tty,
|
package/lib/utils/cli.js
CHANGED
|
@@ -52,7 +52,7 @@ function logExec(command, argv = [], env, logToStderr) {
|
|
|
52
52
|
}, [])
|
|
53
53
|
.join(" ")
|
|
54
54
|
: "";
|
|
55
|
-
const text = `+ ${envText ? envText + " " : ""}${chalk_1.default.yellow(`${command} ${argv.join(" ")}`)}`;
|
|
55
|
+
const text = `+ ${envText ? envText + " " : ""}${chalk_1.default.yellow(`${command} ${argv.map(String).join(" ")}`)}`;
|
|
56
56
|
logToStderr /* && process.env.VITEST !== "true"*/
|
|
57
57
|
? process.stderr.write(`${text}\n`)
|
|
58
58
|
: console.info(text);
|
package/lib/utils/mysql.js
CHANGED
|
@@ -43,13 +43,21 @@ async function assertDumpFile(path) {
|
|
|
43
43
|
async function createMysqlCli(options) {
|
|
44
44
|
let sqlConfigPath;
|
|
45
45
|
const password = (await (0, fs_1.fetchData)(options.password, (p) => p.path)) ?? "";
|
|
46
|
-
const
|
|
46
|
+
const connectionOptions = {
|
|
47
47
|
host: options.hostname,
|
|
48
48
|
user: options.username,
|
|
49
49
|
password,
|
|
50
50
|
port: options.port,
|
|
51
51
|
database: options.database,
|
|
52
|
-
}
|
|
52
|
+
};
|
|
53
|
+
if (options.verbose)
|
|
54
|
+
(0, cli_1.logExec)("sql.createConnection", [
|
|
55
|
+
JSON.stringify({
|
|
56
|
+
...connectionOptions,
|
|
57
|
+
password: "********",
|
|
58
|
+
}, null, 2),
|
|
59
|
+
]);
|
|
60
|
+
const sql = await (0, promise_1.createConnection)(connectionOptions);
|
|
53
61
|
async function createSqlConfig() {
|
|
54
62
|
if (sqlConfigPath)
|
|
55
63
|
return sqlConfigPath;
|
|
@@ -70,19 +78,23 @@ async function createMysqlCli(options) {
|
|
|
70
78
|
return [`--defaults-file=${await createSqlConfig()}`];
|
|
71
79
|
}
|
|
72
80
|
async function fetchAll(query, params) {
|
|
81
|
+
if (options.verbose)
|
|
82
|
+
(0, cli_1.logExec)("> sql.query", [query, JSON.stringify({ params }, null, 2)]);
|
|
73
83
|
const [rows] = await sql.query(query, params);
|
|
84
|
+
if (options.verbose)
|
|
85
|
+
(0, cli_1.logExec)("< sql.query", [JSON.stringify(rows, null, 2)]);
|
|
74
86
|
return rows;
|
|
75
87
|
}
|
|
76
88
|
async function fetchTableNames(database, include, exclude) {
|
|
77
89
|
return (await fetchAll(`
|
|
78
90
|
SELECT
|
|
79
|
-
table_name
|
|
91
|
+
TABLE_NAME AS table_name
|
|
80
92
|
FROM
|
|
81
|
-
information_schema.
|
|
93
|
+
information_schema.TABLES
|
|
82
94
|
WHERE
|
|
83
|
-
|
|
95
|
+
TABLE_SCHEMA = ?
|
|
84
96
|
ORDER BY
|
|
85
|
-
|
|
97
|
+
TABLE_NAME
|
|
86
98
|
`, [database]))
|
|
87
99
|
.map((r) => r.table_name)
|
|
88
100
|
.filter((0, string_1.createPatternFilter)({ include, exclude }));
|
|
@@ -184,14 +196,14 @@ async function createMysqlCli(options) {
|
|
|
184
196
|
SELECT
|
|
185
197
|
COUNT(*) AS total
|
|
186
198
|
FROM
|
|
187
|
-
information_schema.
|
|
199
|
+
information_schema.TABLES
|
|
188
200
|
WHERE
|
|
189
|
-
|
|
201
|
+
TABLE_SCHEMA = ?
|
|
190
202
|
`, [database]);
|
|
191
203
|
return Number(row.total) ? false : true;
|
|
192
204
|
}
|
|
193
205
|
async function createDatabase(database) {
|
|
194
|
-
await
|
|
206
|
+
await execute(`
|
|
195
207
|
CREATE DATABASE IF NOT EXISTS \`${database.name}\`
|
|
196
208
|
CHARACTER SET ${database.charset ?? "utf8"}
|
|
197
209
|
COLLATE ${database.charset ?? "utf8_general_ci"}
|
|
@@ -221,7 +233,7 @@ async function createMysqlCli(options) {
|
|
|
221
233
|
try {
|
|
222
234
|
await (0, fs_1.mkdirIfNotExists)(dir);
|
|
223
235
|
await (0, promises_1.chmod)(dir, 0o777);
|
|
224
|
-
await
|
|
236
|
+
await execute(`SELECT 1 INTO OUTFILE ${outFileVar}`);
|
|
225
237
|
const exists = await (0, fs_1.existsFile)(outFile);
|
|
226
238
|
if (!exists)
|
|
227
239
|
throw new error_1.AppError(`MySQL shared dir is not reached: ${dir}`);
|
|
@@ -234,14 +246,8 @@ async function createMysqlCli(options) {
|
|
|
234
246
|
}
|
|
235
247
|
}
|
|
236
248
|
async function execute(query, params = []) {
|
|
237
|
-
if (options.verbose)
|
|
238
|
-
(0, cli_1.logExec)(
|
|
239
|
-
...(await args()),
|
|
240
|
-
"-e",
|
|
241
|
-
`"${flatQuery(query)}"`,
|
|
242
|
-
...(sql.config.database ? [sql.config.database] : []),
|
|
243
|
-
]);
|
|
244
|
-
}
|
|
249
|
+
if (options.verbose)
|
|
250
|
+
(0, cli_1.logExec)("> sql.execute", [query, JSON.stringify({ params }, null, 2)]);
|
|
245
251
|
await sql.execute(query, params);
|
|
246
252
|
}
|
|
247
253
|
async function insert(tableName, item) {
|
|
@@ -255,10 +261,14 @@ async function createMysqlCli(options) {
|
|
|
255
261
|
await execute(`INSERT INTO ${tableName} (${columnsExpr}) VALUES (${paramsExpr})`, params);
|
|
256
262
|
}
|
|
257
263
|
async function changeDatabase(name) {
|
|
264
|
+
if (options.verbose)
|
|
265
|
+
(0, cli_1.logExec)("sql.changeUser", [name]);
|
|
258
266
|
await sql.changeUser({ database: name });
|
|
259
267
|
}
|
|
260
268
|
return {
|
|
261
269
|
async [Symbol.asyncDispose]() {
|
|
270
|
+
if (options.verbose)
|
|
271
|
+
(0, cli_1.logExec)("sql.end");
|
|
262
272
|
await sql.end();
|
|
263
273
|
},
|
|
264
274
|
options,
|
package/lib/utils/temp.d.ts
CHANGED
|
@@ -13,10 +13,10 @@ export declare function useTempFile(path: string): AsyncDisposable & {
|
|
|
13
13
|
path: string;
|
|
14
14
|
};
|
|
15
15
|
export declare class GargabeCollector {
|
|
16
|
-
protected
|
|
16
|
+
protected verbose?: boolean | undefined;
|
|
17
17
|
readonly paths: Set<string>;
|
|
18
18
|
readonly children: Set<GargabeCollector>;
|
|
19
|
-
constructor(
|
|
19
|
+
constructor(verbose?: boolean | undefined);
|
|
20
20
|
pending(): boolean;
|
|
21
21
|
cleanup(): Promise<void>;
|
|
22
22
|
dispose(): Promise<void>;
|
package/lib/utils/temp.js
CHANGED
|
@@ -85,11 +85,11 @@ function useTempFile(path) {
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
class GargabeCollector {
|
|
88
|
-
|
|
88
|
+
verbose;
|
|
89
89
|
paths = new Set();
|
|
90
90
|
children = new Set();
|
|
91
|
-
constructor(
|
|
92
|
-
this.
|
|
91
|
+
constructor(verbose) {
|
|
92
|
+
this.verbose = verbose;
|
|
93
93
|
exports.collectors.add(this);
|
|
94
94
|
}
|
|
95
95
|
pending() {
|
|
@@ -103,7 +103,8 @@ class GargabeCollector {
|
|
|
103
103
|
async cleanup() {
|
|
104
104
|
for (const path of this.paths) {
|
|
105
105
|
try {
|
|
106
|
-
|
|
106
|
+
if (!this.verbose)
|
|
107
|
+
await rmTmpDir(path);
|
|
107
108
|
this.paths.delete(path);
|
|
108
109
|
}
|
|
109
110
|
catch (_) { }
|
|
@@ -132,7 +133,7 @@ class GargabeCollector {
|
|
|
132
133
|
};
|
|
133
134
|
}
|
|
134
135
|
create() {
|
|
135
|
-
const gc = new GargabeCollector();
|
|
136
|
+
const gc = new GargabeCollector(this.verbose);
|
|
136
137
|
this.children.add(gc);
|
|
137
138
|
return gc;
|
|
138
139
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datatruck/cli",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.3",
|
|
4
4
|
"description": "Tool for creating and managing backups",
|
|
5
5
|
"homepage": "https://github.com/swordev/datatruck#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"async": "^3.2.6",
|
|
32
32
|
"chalk": "^4.1.2",
|
|
33
33
|
"commander": "^12.1.0",
|
|
34
|
-
"croner": "^8.1.
|
|
34
|
+
"croner": "^8.1.2",
|
|
35
35
|
"dayjs": "^1.11.13",
|
|
36
36
|
"fast-folder-size": "^2.2.0",
|
|
37
37
|
"fast-glob": "^3.3.2",
|
|
38
|
-
"listr2": "^8.2.
|
|
38
|
+
"listr2": "^8.2.5",
|
|
39
39
|
"micromatch": "^4.0.8",
|
|
40
40
|
"mongodb": "^6.9.0",
|
|
41
41
|
"mysql2": "^3.11.3",
|