@datatruck/cli 0.40.2 → 0.40.4
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 +30 -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 }));
|
|
@@ -102,6 +114,8 @@ async function createMysqlCli(options) {
|
|
|
102
114
|
"--no-data",
|
|
103
115
|
"--no-create-db",
|
|
104
116
|
"--skip-opt",
|
|
117
|
+
// https://jira.mariadb.org/browse/MDEV-35091
|
|
118
|
+
"--create-options",
|
|
105
119
|
]
|
|
106
120
|
: []),
|
|
107
121
|
...(input.items || []),
|
|
@@ -184,14 +198,14 @@ async function createMysqlCli(options) {
|
|
|
184
198
|
SELECT
|
|
185
199
|
COUNT(*) AS total
|
|
186
200
|
FROM
|
|
187
|
-
information_schema.
|
|
201
|
+
information_schema.TABLES
|
|
188
202
|
WHERE
|
|
189
|
-
|
|
203
|
+
TABLE_SCHEMA = ?
|
|
190
204
|
`, [database]);
|
|
191
205
|
return Number(row.total) ? false : true;
|
|
192
206
|
}
|
|
193
207
|
async function createDatabase(database) {
|
|
194
|
-
await
|
|
208
|
+
await execute(`
|
|
195
209
|
CREATE DATABASE IF NOT EXISTS \`${database.name}\`
|
|
196
210
|
CHARACTER SET ${database.charset ?? "utf8"}
|
|
197
211
|
COLLATE ${database.charset ?? "utf8_general_ci"}
|
|
@@ -221,7 +235,7 @@ async function createMysqlCli(options) {
|
|
|
221
235
|
try {
|
|
222
236
|
await (0, fs_1.mkdirIfNotExists)(dir);
|
|
223
237
|
await (0, promises_1.chmod)(dir, 0o777);
|
|
224
|
-
await
|
|
238
|
+
await execute(`SELECT 1 INTO OUTFILE ${outFileVar}`);
|
|
225
239
|
const exists = await (0, fs_1.existsFile)(outFile);
|
|
226
240
|
if (!exists)
|
|
227
241
|
throw new error_1.AppError(`MySQL shared dir is not reached: ${dir}`);
|
|
@@ -234,14 +248,8 @@ async function createMysqlCli(options) {
|
|
|
234
248
|
}
|
|
235
249
|
}
|
|
236
250
|
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
|
-
}
|
|
251
|
+
if (options.verbose)
|
|
252
|
+
(0, cli_1.logExec)("> sql.execute", [query, JSON.stringify({ params }, null, 2)]);
|
|
245
253
|
await sql.execute(query, params);
|
|
246
254
|
}
|
|
247
255
|
async function insert(tableName, item) {
|
|
@@ -255,10 +263,14 @@ async function createMysqlCli(options) {
|
|
|
255
263
|
await execute(`INSERT INTO ${tableName} (${columnsExpr}) VALUES (${paramsExpr})`, params);
|
|
256
264
|
}
|
|
257
265
|
async function changeDatabase(name) {
|
|
266
|
+
if (options.verbose)
|
|
267
|
+
(0, cli_1.logExec)("sql.changeUser", [name]);
|
|
258
268
|
await sql.changeUser({ database: name });
|
|
259
269
|
}
|
|
260
270
|
return {
|
|
261
271
|
async [Symbol.asyncDispose]() {
|
|
272
|
+
if (options.verbose)
|
|
273
|
+
(0, cli_1.logExec)("sql.end");
|
|
262
274
|
await sql.end();
|
|
263
275
|
},
|
|
264
276
|
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.4",
|
|
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",
|