@datatruck/cli 0.36.1 → 0.36.2

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.
@@ -1,4 +1,49 @@
1
1
  "use strict";
2
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
3
+ if (value !== null && value !== void 0) {
4
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
5
+ var dispose;
6
+ if (async) {
7
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
8
+ dispose = value[Symbol.asyncDispose];
9
+ }
10
+ if (dispose === void 0) {
11
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
12
+ dispose = value[Symbol.dispose];
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ env.stack.push({ value: value, dispose: dispose, async: async });
16
+ }
17
+ else if (async) {
18
+ env.stack.push({ async: true });
19
+ }
20
+ return value;
21
+ };
22
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
23
+ return function (env) {
24
+ function fail(e) {
25
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
26
+ env.hasError = true;
27
+ }
28
+ function next() {
29
+ while (env.stack.length) {
30
+ var rec = env.stack.pop();
31
+ try {
32
+ var result = rec.dispose && rec.dispose.call(rec.value);
33
+ if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
34
+ }
35
+ catch (e) {
36
+ fail(e);
37
+ }
38
+ }
39
+ if (env.hasError) throw env.error;
40
+ }
41
+ return next();
42
+ };
43
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
44
+ var e = new Error(message);
45
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
46
+ });
2
47
  Object.defineProperty(exports, "__esModule", { value: true });
3
48
  exports.MysqlDumpTask = exports.mysqlDumpTaskName = void 0;
4
49
  const async_1 = require("../utils/async");
@@ -24,149 +69,161 @@ const suffix = {
24
69
  };
25
70
  class MysqlDumpTask extends TaskAbstract_1.TaskAbstract {
26
71
  async backup(data) {
27
- const compressAndClean = this.config.compress
28
- ? async (path) => {
29
- await (0, tar_1.createTar)({
30
- include: [(0, path_1.relative)(snapshotPath, path)],
31
- output: `${path}.tar.gz`,
32
- path: (0, path_1.dirname)(path),
33
- compress: this.config.compress,
34
- verbose: data.options.verbose,
35
- });
36
- await (0, promises_1.rm)(path);
37
- }
38
- : undefined;
39
- const snapshotPath = data.package.path ??
40
- (await (0, temp_1.mkTmpDir)(exports.mysqlDumpTaskName, "task", "backup", "snapshot"));
41
- await (0, fs_1.mkdirIfNotExists)(snapshotPath);
42
- await (0, fs_1.ensureEmptyDir)(snapshotPath);
43
- const sql = await (0, mysql_1.createMysqlCli)({
44
- ...this.config,
45
- database: undefined,
46
- verbose: data.options.verbose,
47
- });
48
- const tableNames = await sql.fetchTableNames(this.config.database, this.config.includeTables, this.config.excludeTables);
49
- const concurrency = this.config.concurrency ?? 4;
50
- const dataFormat = this.config.dataFormat ?? "sql";
51
- const sharedDir = dataFormat === "csv"
52
- ? await sql.initSharedDir(this.config.csvSharedPath)
53
- : undefined;
54
- if (this.config.oneFileByTable || sharedDir) {
55
- await (0, async_1.runParallel)({
56
- items: tableNames,
57
- concurrency,
58
- onChange: ({ processed: proccesed, buffer }) => data.onProgress({
59
- relative: {
60
- description: buffer.size > 1 ? `Exporting (${buffer.size})` : "Exporting",
61
- payload: [...buffer.keys()].join(", "),
62
- },
63
- absolute: {
64
- total: tableNames.length,
65
- current: proccesed,
66
- percent: (0, math_1.progressPercent)(tableNames.length, proccesed),
67
- },
68
- }),
69
- onItem: async ({ item: tableName, index, controller }) => {
70
- if (sharedDir) {
71
- const tableSharedPath = (0, path_1.join)(sharedDir, `tmp-dtt-backup-${data.snapshot.id.slice(0, 8)}-${tableName}`);
72
- if (data.options.verbose) {
73
- (0, cli_1.logExec)("mkdir", ["-p", tableSharedPath]);
74
- (0, cli_1.logExec)("chmod", ["777", tableSharedPath]);
72
+ const env_1 = { stack: [], error: void 0, hasError: false };
73
+ try {
74
+ const compressAndClean = this.config.compress
75
+ ? async (path) => {
76
+ await (0, tar_1.createTar)({
77
+ include: [(0, path_1.relative)(snapshotPath, path)],
78
+ output: `${path}.tar.gz`,
79
+ path: (0, path_1.dirname)(path),
80
+ compress: this.config.compress,
81
+ verbose: data.options.verbose,
82
+ });
83
+ await (0, promises_1.rm)(path);
84
+ }
85
+ : undefined;
86
+ const snapshotPath = data.package.path ??
87
+ (await (0, temp_1.mkTmpDir)(exports.mysqlDumpTaskName, "task", "backup", "snapshot"));
88
+ await (0, fs_1.mkdirIfNotExists)(snapshotPath);
89
+ await (0, fs_1.ensureEmptyDir)(snapshotPath);
90
+ const sql = __addDisposableResource(env_1, await (0, mysql_1.createMysqlCli)({
91
+ ...this.config,
92
+ database: undefined,
93
+ verbose: data.options.verbose,
94
+ }), true);
95
+ const tableNames = await sql.fetchTableNames(this.config.database, this.config.includeTables, this.config.excludeTables);
96
+ const concurrency = this.config.concurrency ?? 4;
97
+ const dataFormat = this.config.dataFormat ?? "sql";
98
+ const sharedDir = dataFormat === "csv"
99
+ ? await sql.initSharedDir(this.config.csvSharedPath)
100
+ : undefined;
101
+ if (this.config.oneFileByTable || sharedDir) {
102
+ await (0, async_1.runParallel)({
103
+ items: tableNames,
104
+ concurrency,
105
+ onChange: ({ processed: proccesed, buffer }) => data.onProgress({
106
+ relative: {
107
+ description: buffer.size > 1 ? `Exporting (${buffer.size})` : "Exporting",
108
+ payload: [...buffer.keys()].join(", "),
109
+ },
110
+ absolute: {
111
+ total: tableNames.length,
112
+ current: proccesed,
113
+ percent: (0, math_1.progressPercent)(tableNames.length, proccesed),
114
+ },
115
+ }),
116
+ onItem: async ({ item: tableName, index, controller }) => {
117
+ if (sharedDir) {
118
+ const tableSharedPath = (0, path_1.join)(sharedDir, `tmp-dtt-backup-${data.snapshot.id.slice(0, 8)}-${tableName}`);
119
+ if (data.options.verbose) {
120
+ (0, cli_1.logExec)("mkdir", ["-p", tableSharedPath]);
121
+ (0, cli_1.logExec)("chmod", ["777", tableSharedPath]);
122
+ }
123
+ await (0, promises_1.mkdir)(tableSharedPath, { recursive: true });
124
+ try {
125
+ await (0, promises_1.chmod)(tableSharedPath, 0o777);
126
+ await sql.csvDump({
127
+ sharedPath: tableSharedPath,
128
+ items: [tableName],
129
+ database: this.config.database,
130
+ controller,
131
+ });
132
+ const files = await (0, promises_1.readdir)(tableSharedPath);
133
+ const schemaFile = `${tableName}.sql`;
134
+ const dataFile = `${tableName}.txt`;
135
+ const successCsvDump = files.length === 2 &&
136
+ files.every((file) => file === schemaFile || file === dataFile);
137
+ if (!successCsvDump)
138
+ throw new error_1.AppError(`Invalid csv dump files: ${files.join(", ")}`);
139
+ const schemaPath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.tableSchema}`);
140
+ await (0, fs_1.safeRename)((0, path_1.join)(tableSharedPath, schemaFile), schemaPath);
141
+ await compressAndClean?.(schemaPath);
142
+ const tablePath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.tableData}`);
143
+ await (0, fs_1.safeRename)((0, path_1.join)(tableSharedPath, dataFile), tablePath);
144
+ await compressAndClean?.(tablePath);
145
+ }
146
+ finally {
147
+ await (0, promises_1.rm)(tableSharedPath, { recursive: true });
148
+ }
75
149
  }
76
- await (0, promises_1.mkdir)(tableSharedPath, { recursive: true });
77
- try {
78
- await (0, promises_1.chmod)(tableSharedPath, 0o777);
79
- await sql.csvDump({
80
- sharedPath: tableSharedPath,
150
+ else {
151
+ const outPath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.table}`);
152
+ await sql.dump({
153
+ output: outPath,
81
154
  items: [tableName],
82
155
  database: this.config.database,
83
156
  controller,
157
+ ...(concurrency === 1 && {
158
+ onProgress(progress) {
159
+ data.onProgress({
160
+ relative: {
161
+ description: "Exporting",
162
+ payload: tableName,
163
+ current: progress.totalBytes,
164
+ format: "size",
165
+ },
166
+ absolute: {
167
+ total: tableNames.length,
168
+ current: index,
169
+ percent: (0, math_1.progressPercent)(tableNames.length, index),
170
+ },
171
+ });
172
+ },
173
+ }),
84
174
  });
85
- const files = await (0, promises_1.readdir)(tableSharedPath);
86
- const schemaFile = `${tableName}.sql`;
87
- const dataFile = `${tableName}.txt`;
88
- const successCsvDump = files.length === 2 &&
89
- files.every((file) => file === schemaFile || file === dataFile);
90
- if (!successCsvDump)
91
- throw new error_1.AppError(`Invalid csv dump files: ${files.join(", ")}`);
92
- const schemaPath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.tableSchema}`);
93
- await (0, fs_1.safeRename)((0, path_1.join)(tableSharedPath, schemaFile), schemaPath);
94
- await compressAndClean?.(schemaPath);
95
- const tablePath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.tableData}`);
96
- await (0, fs_1.safeRename)((0, path_1.join)(tableSharedPath, dataFile), tablePath);
97
- await compressAndClean?.(tablePath);
175
+ await sql.assertDumpFile(outPath);
176
+ await compressAndClean?.(outPath);
98
177
  }
99
- finally {
100
- await (0, promises_1.rm)(tableSharedPath, { recursive: true });
101
- }
102
- }
103
- else {
104
- const outPath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.table}`);
105
- await sql.dump({
106
- output: outPath,
107
- items: [tableName],
108
- database: this.config.database,
109
- controller,
110
- ...(concurrency === 1 && {
111
- onProgress(progress) {
112
- data.onProgress({
113
- relative: {
114
- description: "Exporting",
115
- payload: tableName,
116
- current: progress.totalBytes,
117
- format: "size",
118
- },
119
- absolute: {
120
- total: tableNames.length,
121
- current: index,
122
- percent: (0, math_1.progressPercent)(tableNames.length, index),
123
- },
124
- });
125
- },
126
- }),
127
- });
128
- await sql.assertDumpFile(outPath);
129
- await compressAndClean?.(outPath);
130
- }
131
- },
132
- });
133
- }
134
- else {
135
- data.onProgress({
136
- relative: { description: "Exporting" },
137
- });
138
- const outPath = (0, path_1.join)(snapshotPath, `${this.config.database}${suffix.database}`);
139
- await sql.dump({
140
- output: outPath,
141
- items: tableNames,
142
- database: this.config.database,
143
- onProgress: (progress) => data.onProgress({
144
- absolute: {
145
- description: "Exporting in single file",
146
- current: progress.totalBytes,
147
- format: "size",
148
178
  },
149
- }),
150
- });
151
- await sql.assertDumpFile(outPath);
152
- await compressAndClean?.(outPath);
179
+ });
180
+ }
181
+ else {
182
+ data.onProgress({
183
+ relative: { description: "Exporting" },
184
+ });
185
+ const outPath = (0, path_1.join)(snapshotPath, `${this.config.database}${suffix.database}`);
186
+ await sql.dump({
187
+ output: outPath,
188
+ items: tableNames,
189
+ database: this.config.database,
190
+ onProgress: (progress) => data.onProgress({
191
+ absolute: {
192
+ description: "Exporting in single file",
193
+ current: progress.totalBytes,
194
+ format: "size",
195
+ },
196
+ }),
197
+ });
198
+ await sql.assertDumpFile(outPath);
199
+ await compressAndClean?.(outPath);
200
+ }
201
+ if (this.config.storedPrograms ?? true) {
202
+ data.onProgress({
203
+ relative: { description: "Exporting stored programs" },
204
+ });
205
+ const outPath = (0, path_1.join)(snapshotPath, `${this.config.database}${suffix.stored}`);
206
+ await sql.dump({
207
+ database: this.config.database,
208
+ output: outPath,
209
+ onlyStoredPrograms: true,
210
+ });
211
+ await sql.assertDumpFile(outPath);
212
+ await compressAndClean?.(outPath);
213
+ }
214
+ return {
215
+ snapshotPath,
216
+ };
153
217
  }
154
- if (this.config.storedPrograms ?? true) {
155
- data.onProgress({
156
- relative: { description: "Exporting stored programs" },
157
- });
158
- const outPath = (0, path_1.join)(snapshotPath, `${this.config.database}${suffix.stored}`);
159
- await sql.dump({
160
- database: this.config.database,
161
- output: outPath,
162
- onlyStoredPrograms: true,
163
- });
164
- await sql.assertDumpFile(outPath);
165
- await compressAndClean?.(outPath);
218
+ catch (e_1) {
219
+ env_1.error = e_1;
220
+ env_1.hasError = true;
221
+ }
222
+ finally {
223
+ const result_1 = __disposeResources(env_1);
224
+ if (result_1)
225
+ await result_1;
166
226
  }
167
- return {
168
- snapshotPath,
169
- };
170
227
  }
171
228
  async prepareRestore(data) {
172
229
  return {
@@ -175,145 +232,157 @@ class MysqlDumpTask extends TaskAbstract_1.TaskAbstract {
175
232
  };
176
233
  }
177
234
  async restore(data) {
178
- const sql = await (0, mysql_1.createMysqlCli)({
179
- ...this.config,
180
- database: undefined,
181
- verbose: data.options.verbose,
182
- });
183
- const snapshotPath = data.snapshotPath;
184
- const params = {
185
- packageName: data.package.name,
186
- snapshotId: data.options.snapshotId,
187
- snapshotDate: data.snapshot.date,
188
- action: "restore",
189
- database: undefined,
190
- };
191
- const database = {
192
- name: (0, config_1.resolveDatabaseName)(this.config.database, params),
193
- };
194
- if (this.config.targetDatabase && !data.options.initial)
195
- database.name = (0, config_1.resolveDatabaseName)(this.config.targetDatabase.name, {
196
- ...params,
197
- database: database.name,
198
- });
199
- const [files, compressed] = (0, fs_1.groupFiles)(await (0, fs_1.readDir)(snapshotPath), Object.values(suffix));
200
- // Database check
201
- if (files.some((f) => f.endsWith(suffix.database)) &&
202
- !(await sql.isDatabaseEmpty(database.name)))
203
- throw new error_1.AppError(`Target database is not empty: ${database.name}`);
204
- // Table check
205
- const restoreTables = [
206
- ...new Set(...files
207
- .filter((f) => (0, string_1.endsWith)(f, [suffix.table, suffix.tableSchema, suffix.tableData]))
208
- .map((f) => f.split(".")[0])),
209
- ];
210
- const serverTables = await sql.fetchTableNames(database.name);
211
- const errorTables = restoreTables.filter((v) => serverTables.includes(v));
212
- if (errorTables.length)
213
- throw new error_1.AppError(`Target table already exists: ${errorTables.join(", ")}`);
214
- // Data check
215
- const dataFiles = files.filter((f) => f.endsWith(suffix.tableData));
216
- const sharedDir = dataFiles.length
217
- ? await sql.initSharedDir(this.config.csvSharedPath)
218
- : undefined;
219
- await sql.createDatabase(database);
220
- if (data.options.verbose)
221
- (0, cli_1.logExec)("readdir", [snapshotPath]);
222
- const concurrency = this.config.concurrency ?? 1;
223
- let processed = 0;
224
- await (0, async_1.runParallel)({
225
- items: files.filter((f) => !f.endsWith(suffix.tableData)),
226
- concurrency,
227
- onFinished: () => {
228
- processed++;
229
- },
230
- onChange: ({ buffer }) => data.onProgress({
231
- relative: {
232
- description: buffer.size > 1 ? `Importing (${buffer.size})` : "Importing",
233
- payload: [...buffer.keys()].join(", "),
234
- },
235
- absolute: {
236
- total: files.length,
237
- current: processed,
238
- percent: (0, math_1.progressPercent)(files.length, processed),
235
+ const env_2 = { stack: [], error: void 0, hasError: false };
236
+ try {
237
+ const sql = __addDisposableResource(env_2, await (0, mysql_1.createMysqlCli)({
238
+ ...this.config,
239
+ database: undefined,
240
+ verbose: data.options.verbose,
241
+ }), true);
242
+ const snapshotPath = data.snapshotPath;
243
+ const params = {
244
+ packageName: data.package.name,
245
+ snapshotId: data.options.snapshotId,
246
+ snapshotDate: data.snapshot.date,
247
+ action: "restore",
248
+ database: undefined,
249
+ };
250
+ const database = {
251
+ name: (0, config_1.resolveDatabaseName)(this.config.database, params),
252
+ };
253
+ if (this.config.targetDatabase && !data.options.initial)
254
+ database.name = (0, config_1.resolveDatabaseName)(this.config.targetDatabase.name, {
255
+ ...params,
256
+ database: database.name,
257
+ });
258
+ const [files, compressed] = (0, fs_1.groupFiles)(await (0, fs_1.readDir)(snapshotPath), Object.values(suffix));
259
+ // Database check
260
+ if (files.some((f) => f.endsWith(suffix.database)) &&
261
+ !(await sql.isDatabaseEmpty(database.name)))
262
+ throw new error_1.AppError(`Target database is not empty: ${database.name}`);
263
+ // Table check
264
+ const restoreTables = [
265
+ ...new Set(...files
266
+ .filter((f) => (0, string_1.endsWith)(f, [suffix.table, suffix.tableSchema, suffix.tableData]))
267
+ .map((f) => f.split(".")[0])),
268
+ ];
269
+ const serverTables = await sql.fetchTableNames(database.name);
270
+ const errorTables = restoreTables.filter((v) => serverTables.includes(v));
271
+ if (errorTables.length)
272
+ throw new error_1.AppError(`Target table already exists: ${errorTables.join(", ")}`);
273
+ // Data check
274
+ const dataFiles = files.filter((f) => f.endsWith(suffix.tableData));
275
+ const sharedDir = dataFiles.length
276
+ ? await sql.initSharedDir(this.config.csvSharedPath)
277
+ : undefined;
278
+ await sql.createDatabase(database);
279
+ if (data.options.verbose)
280
+ (0, cli_1.logExec)("readdir", [snapshotPath]);
281
+ const concurrency = this.config.concurrency ?? 1;
282
+ let processed = 0;
283
+ await (0, async_1.runParallel)({
284
+ items: files.filter((f) => !f.endsWith(suffix.tableData)),
285
+ concurrency,
286
+ onFinished: () => {
287
+ processed++;
239
288
  },
240
- }),
241
- onItem: async ({ item: file, controller }) => {
242
- let path = (0, path_1.join)(snapshotPath, file);
243
- const tempDir = compressed[file]
244
- ? await (0, temp_1.useTempDir)(exports.mysqlDumpTaskName, "task", "restore", "decompress")
245
- : undefined;
246
- try {
247
- if (tempDir) {
248
- await (0, tar_1.extractTar)({
249
- input: (0, path_1.join)(snapshotPath, compressed[file]),
250
- output: tempDir.path,
251
- decompress: true,
252
- verbose: data.options.verbose,
289
+ onChange: ({ buffer }) => data.onProgress({
290
+ relative: {
291
+ description: buffer.size > 1 ? `Importing (${buffer.size})` : "Importing",
292
+ payload: [...buffer.keys()].join(", "),
293
+ },
294
+ absolute: {
295
+ total: files.length,
296
+ current: processed,
297
+ percent: (0, math_1.progressPercent)(files.length, processed),
298
+ },
299
+ }),
300
+ onItem: async ({ item: file, controller }) => {
301
+ let path = (0, path_1.join)(snapshotPath, file);
302
+ const tempDir = compressed[file]
303
+ ? await (0, temp_1.useTempDir)(exports.mysqlDumpTaskName, "task", "restore", "decompress")
304
+ : undefined;
305
+ try {
306
+ if (tempDir) {
307
+ await (0, tar_1.extractTar)({
308
+ input: (0, path_1.join)(snapshotPath, compressed[file]),
309
+ output: tempDir.path,
310
+ decompress: true,
311
+ verbose: data.options.verbose,
312
+ });
313
+ path = await (0, fs_1.ensureSingleFile)(tempDir.path);
314
+ }
315
+ await sql.importFile({
316
+ path,
317
+ database: database.name,
318
+ controller,
253
319
  });
254
- path = await (0, fs_1.ensureSingleFile)(tempDir.path);
255
320
  }
256
- await sql.importFile({
257
- path,
258
- database: database.name,
259
- controller,
260
- });
261
- }
262
- finally {
263
- await tempDir?.[Symbol.asyncDispose]();
264
- }
265
- },
266
- });
267
- await (0, async_1.runParallel)({
268
- items: dataFiles,
269
- concurrency,
270
- onFinished: () => {
271
- processed++;
272
- },
273
- onChange: ({ buffer }) => data.onProgress({
274
- relative: {
275
- description: buffer.size > 1 ? `Importing (${buffer.size})` : "Importing",
276
- payload: [...buffer.keys()].join(", "),
321
+ finally {
322
+ await tempDir?.[Symbol.asyncDispose]();
323
+ }
277
324
  },
278
- absolute: {
279
- total: files.length,
280
- current: processed,
281
- percent: (0, math_1.progressPercent)(files.length, processed),
325
+ });
326
+ await (0, async_1.runParallel)({
327
+ items: dataFiles,
328
+ concurrency,
329
+ onFinished: () => {
330
+ processed++;
282
331
  },
283
- }),
284
- onItem: async ({ item: file, controller }) => {
285
- const id = data.snapshot.id.slice(0, 8);
286
- const tableName = file.slice(0, suffix.tableData.length * -1);
287
- const sharedName = `tmp-dtt-restore-${id}-${tableName}.data.csv`;
288
- const temp = (0, temp_1.useTempFile)((0, path_1.join)(sharedDir, sharedName));
289
- try {
290
- let csvFile = temp.path;
291
- if (compressed[file]) {
292
- await (0, fs_1.mkdirIfNotExists)(temp.path);
293
- await (0, tar_1.extractTar)({
294
- input: (0, path_1.join)(snapshotPath, compressed[file]),
295
- output: temp.path,
296
- decompress: true,
297
- verbose: data.options.verbose,
332
+ onChange: ({ buffer }) => data.onProgress({
333
+ relative: {
334
+ description: buffer.size > 1 ? `Importing (${buffer.size})` : "Importing",
335
+ payload: [...buffer.keys()].join(", "),
336
+ },
337
+ absolute: {
338
+ total: files.length,
339
+ current: processed,
340
+ percent: (0, math_1.progressPercent)(files.length, processed),
341
+ },
342
+ }),
343
+ onItem: async ({ item: file, controller }) => {
344
+ const id = data.snapshot.id.slice(0, 8);
345
+ const tableName = file.slice(0, suffix.tableData.length * -1);
346
+ const sharedName = `tmp-dtt-restore-${id}-${tableName}.data.csv`;
347
+ const temp = (0, temp_1.useTempFile)((0, path_1.join)(sharedDir, sharedName));
348
+ try {
349
+ let csvFile = temp.path;
350
+ if (compressed[file]) {
351
+ await (0, fs_1.mkdirIfNotExists)(temp.path);
352
+ await (0, tar_1.extractTar)({
353
+ input: (0, path_1.join)(snapshotPath, compressed[file]),
354
+ output: temp.path,
355
+ decompress: true,
356
+ verbose: data.options.verbose,
357
+ });
358
+ csvFile = await (0, fs_1.ensureSingleFile)(temp.path);
359
+ }
360
+ else {
361
+ const sourceFile = (0, path_1.join)(snapshotPath, file);
362
+ await (0, fs_1.safeRename)(sourceFile, temp.path);
363
+ }
364
+ await sql.importCsvFile({
365
+ path: csvFile,
366
+ database: database.name,
367
+ table: tableName,
368
+ controller,
298
369
  });
299
- csvFile = await (0, fs_1.ensureSingleFile)(temp.path);
300
370
  }
301
- else {
302
- const sourceFile = (0, path_1.join)(snapshotPath, file);
303
- await (0, fs_1.safeRename)(sourceFile, temp.path);
371
+ finally {
372
+ await temp[Symbol.asyncDispose]();
304
373
  }
305
- await sql.importCsvFile({
306
- path: csvFile,
307
- database: database.name,
308
- table: tableName,
309
- controller,
310
- });
311
- }
312
- finally {
313
- await temp[Symbol.asyncDispose]();
314
- }
315
- },
316
- });
374
+ },
375
+ });
376
+ }
377
+ catch (e_2) {
378
+ env_2.error = e_2;
379
+ env_2.hasError = true;
380
+ }
381
+ finally {
382
+ const result_2 = __disposeResources(env_2);
383
+ if (result_2)
384
+ await result_2;
385
+ }
317
386
  }
318
387
  }
319
388
  exports.MysqlDumpTask = MysqlDumpTask;
@@ -11,6 +11,7 @@ export type MysqlCliOptions = {
11
11
  };
12
12
  export declare function assertDumpFile(path: string): Promise<void>;
13
13
  export declare function createMysqlCli(options: MysqlCliOptions): Promise<{
14
+ [Symbol.asyncDispose](): Promise<void>;
14
15
  options: MysqlCliOptions;
15
16
  initSharedDir: (sharedDir?: string) => Promise<string>;
16
17
  args: () => Promise<string[]>;
@@ -258,6 +258,9 @@ async function createMysqlCli(options) {
258
258
  await sql.changeUser({ database: name });
259
259
  }
260
260
  return {
261
+ async [Symbol.asyncDispose]() {
262
+ await sql.end();
263
+ },
261
264
  options,
262
265
  initSharedDir,
263
266
  args,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.36.1",
3
+ "version": "0.36.2",
4
4
  "description": "Tool for creating and managing backups",
5
5
  "homepage": "https://github.com/swordev/datatruck#readme",
6
6
  "bugs": {