@datatruck/cli 0.22.0 → 0.22.1
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/Task/MysqlDumpTask.js +5 -2
- package/package.json +1 -1
- package/utils/mysql.d.ts +1 -1
- package/utils/mysql.js +22 -9
package/Task/MysqlDumpTask.js
CHANGED
|
@@ -55,9 +55,12 @@ class MysqlDumpTask extends TaskAbstract_1.TaskAbstract {
|
|
|
55
55
|
});
|
|
56
56
|
if (sharedDir) {
|
|
57
57
|
const tableSharedPath = (0, path_1.join)(sharedDir, `tmp-dtt-backup-${data.snapshot.id.slice(0, 8)}-${tableName}`);
|
|
58
|
-
if (data.options.verbose)
|
|
59
|
-
(0, cli_1.logExec)("mkdir", [tableSharedPath]);
|
|
58
|
+
if (data.options.verbose) {
|
|
59
|
+
(0, cli_1.logExec)("mkdir", ["-p", tableSharedPath]);
|
|
60
|
+
(0, cli_1.logExec)("chmod", ["777", tableSharedPath]);
|
|
61
|
+
}
|
|
60
62
|
await (0, promises_1.mkdir)(tableSharedPath, { recursive: true });
|
|
63
|
+
await (0, promises_1.chmod)(tableSharedPath, 0o777);
|
|
61
64
|
try {
|
|
62
65
|
await sql.csvDump({
|
|
63
66
|
sharedPath: tableSharedPath,
|
package/package.json
CHANGED
package/utils/mysql.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function createMysqlCli(options: MysqlCliOptions): {
|
|
|
11
11
|
options: MysqlCliOptions;
|
|
12
12
|
initSharedDir: (sharedDir?: string) => Promise<string>;
|
|
13
13
|
args: () => Promise<string[]>;
|
|
14
|
-
run: (query: string, database?: string) => Promise<import("./process").ExecResultType>;
|
|
14
|
+
run: (query: string, database?: string, extra?: string[]) => Promise<import("./process").ExecResultType>;
|
|
15
15
|
fetchAll: (query: string, database?: string) => Promise<string[][]>;
|
|
16
16
|
dump: (input: {
|
|
17
17
|
output: string;
|
package/utils/mysql.js
CHANGED
|
@@ -11,19 +11,31 @@ const promises_1 = require("fs/promises");
|
|
|
11
11
|
const os_1 = require("os");
|
|
12
12
|
const path_1 = require("path");
|
|
13
13
|
function createMysqlCli(options) {
|
|
14
|
-
|
|
14
|
+
let defaultsFilePath;
|
|
15
|
+
async function getDefaultsFilePath() {
|
|
16
|
+
if (defaultsFilePath)
|
|
17
|
+
return defaultsFilePath;
|
|
18
|
+
const dir = await (0, fs_1.mkTmpDir)("mysql-cli");
|
|
15
19
|
const password = await (0, fs_1.fetchData)(options.password, (p) => p.path);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const data = [
|
|
21
|
+
`[client]`,
|
|
22
|
+
`host = "${options.hostname}"`,
|
|
23
|
+
...(options.port ? [`port = "${options.port}"`] : []),
|
|
24
|
+
`user = "${options.username}"`,
|
|
25
|
+
`password = "${password}"`,
|
|
21
26
|
];
|
|
27
|
+
console.log(data.join("\n"));
|
|
28
|
+
await (0, promises_1.writeFile)((defaultsFilePath = (0, path_1.join)(dir, "mysql.conf")), data.join("\n"));
|
|
29
|
+
return defaultsFilePath;
|
|
30
|
+
}
|
|
31
|
+
async function args() {
|
|
32
|
+
return [`--defaults-file=${await getDefaultsFilePath()}`];
|
|
22
33
|
}
|
|
23
|
-
async function run(query, database) {
|
|
34
|
+
async function run(query, database, extra = []) {
|
|
24
35
|
return await (0, process_1.exec)("mysql", [
|
|
25
36
|
...(await args()),
|
|
26
37
|
...(database ? [database] : []),
|
|
38
|
+
...(extra || []),
|
|
27
39
|
"-e",
|
|
28
40
|
query.replace(/\s{1,}/g, " "),
|
|
29
41
|
"-N",
|
|
@@ -109,12 +121,12 @@ function createMysqlCli(options) {
|
|
|
109
121
|
}
|
|
110
122
|
async function importFile(path, database) {
|
|
111
123
|
return await (0, process_1.exec)("mysql", [
|
|
124
|
+
...(await args()),
|
|
112
125
|
`--init-command=SET ${[
|
|
113
126
|
"autocommit=0",
|
|
114
127
|
"unique_checks=0",
|
|
115
128
|
"foreign_key_checks=0",
|
|
116
129
|
].join(",")};`,
|
|
117
|
-
...(await args()),
|
|
118
130
|
database,
|
|
119
131
|
], null, {
|
|
120
132
|
pipe: {
|
|
@@ -139,7 +151,7 @@ function createMysqlCli(options) {
|
|
|
139
151
|
INTO TABLE ${table}
|
|
140
152
|
FIELDS TERMINATED BY ','
|
|
141
153
|
ENCLOSED BY '"'
|
|
142
|
-
LINES TERMINATED BY '\\n'`, database);
|
|
154
|
+
LINES TERMINATED BY '\\n'`, database, ["--local-infile"]);
|
|
143
155
|
}
|
|
144
156
|
async function isDatabaseEmpty(database) {
|
|
145
157
|
const [total] = await fetchAll(`
|
|
@@ -180,6 +192,7 @@ function createMysqlCli(options) {
|
|
|
180
192
|
const outFileVar = JSON.stringify(outFile.replaceAll("\\", "/"));
|
|
181
193
|
try {
|
|
182
194
|
await (0, fs_1.mkdirIfNotExists)(dir);
|
|
195
|
+
await (0, promises_1.chmod)(dir, 0o777);
|
|
183
196
|
await run(`SELECT 1 INTO OUTFILE ${outFileVar}`);
|
|
184
197
|
const exists = await (0, fs_1.existsFile)(outFile);
|
|
185
198
|
if (!exists)
|