ante-erp-cli 1.11.4 → 1.11.6
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/package.json
CHANGED
|
@@ -249,7 +249,8 @@ export async function cloneMongodb(sourceUrl, options = {}) {
|
|
|
249
249
|
|
|
250
250
|
const restoreSpinner = ora('Restoring database (collections will be dropped and recreated)...').start();
|
|
251
251
|
const restoreStartTime = Date.now();
|
|
252
|
-
|
|
252
|
+
// Pass source database name to locate dump, but restore to local database
|
|
253
|
+
const restoreResult = await restoreDatabase(dumpDirectory, localInfo, true, composeFile, sourceInfo.database);
|
|
253
254
|
|
|
254
255
|
if (!restoreResult.success) {
|
|
255
256
|
restoreSpinner.fail(chalk.red('Database restore failed'));
|
package/src/utils/mongodb.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execa } from 'execa';
|
|
2
|
-
import { existsSync, mkdirSync, readdirSync } from 'fs';
|
|
2
|
+
import { existsSync, mkdirSync, readdirSync, chmodSync } from 'fs';
|
|
3
3
|
import { join, dirname, resolve } from 'path';
|
|
4
4
|
import { stat } from 'fs/promises';
|
|
5
5
|
|
|
@@ -145,10 +145,12 @@ export async function dumpDatabase(connectionInfo, outputDir) {
|
|
|
145
145
|
try {
|
|
146
146
|
const { user, password, host, port, database, authDatabase, isSrv } = connectionInfo;
|
|
147
147
|
|
|
148
|
-
// Ensure backup directory exists
|
|
148
|
+
// Ensure backup directory exists with proper permissions
|
|
149
149
|
if (!existsSync(outputDir)) {
|
|
150
150
|
mkdirSync(outputDir, { recursive: true });
|
|
151
151
|
}
|
|
152
|
+
// Set permissions to 777 to allow Docker container to create subdirectories
|
|
153
|
+
chmodSync(outputDir, 0o777);
|
|
152
154
|
|
|
153
155
|
// Convert to absolute path for Docker volume mount
|
|
154
156
|
const absoluteOutputDir = resolve(outputDir);
|
|
@@ -278,14 +280,18 @@ export async function dumpDatabase(connectionInfo, outputDir) {
|
|
|
278
280
|
* @param {Object} connectionInfo - Target database connection details
|
|
279
281
|
* @param {boolean} dropBeforeRestore - Whether to drop collections before restore (default: true)
|
|
280
282
|
* @param {string} composeFile - Optional path to docker-compose.yml for Docker Compose network access
|
|
283
|
+
* @param {string} sourceDatabaseName - Optional source database name (if different from target database)
|
|
281
284
|
* @returns {Promise<{success: boolean, error?: string}>}
|
|
282
285
|
*/
|
|
283
|
-
export async function restoreDatabase(dumpDir, connectionInfo, dropBeforeRestore = true, composeFile = null) {
|
|
286
|
+
export async function restoreDatabase(dumpDir, connectionInfo, dropBeforeRestore = true, composeFile = null, sourceDatabaseName = null) {
|
|
284
287
|
try {
|
|
285
288
|
const { user, password, host, port, database, authDatabase, isSrv } = connectionInfo;
|
|
286
289
|
|
|
290
|
+
// Use source database name for finding dump directory, or fall back to target database name
|
|
291
|
+
const dumpDbName = sourceDatabaseName || database;
|
|
292
|
+
|
|
287
293
|
// Verify dump directory exists
|
|
288
|
-
const dumpDbDir = join(dumpDir,
|
|
294
|
+
const dumpDbDir = join(dumpDir, dumpDbName);
|
|
289
295
|
if (!existsSync(dumpDbDir)) {
|
|
290
296
|
throw new Error(`Dump directory not found: ${dumpDbDir}`);
|
|
291
297
|
}
|
|
@@ -331,8 +337,8 @@ export async function restoreDatabase(dumpDir, connectionInfo, dropBeforeRestore
|
|
|
331
337
|
restoreArgs.push('--drop');
|
|
332
338
|
}
|
|
333
339
|
|
|
334
|
-
// Add dump directory path
|
|
335
|
-
restoreArgs.push(`${containerDumpDir}/${
|
|
340
|
+
// Add dump directory path (use source database name for dump location)
|
|
341
|
+
restoreArgs.push(`${containerDumpDir}/${dumpDbName}`);
|
|
336
342
|
|
|
337
343
|
// Restore from inside the container
|
|
338
344
|
await execa('docker', restoreArgs, {
|
|
@@ -397,8 +403,8 @@ export async function restoreDatabase(dumpDir, connectionInfo, dropBeforeRestore
|
|
|
397
403
|
restoreArgs.push('--drop');
|
|
398
404
|
}
|
|
399
405
|
|
|
400
|
-
// Add dump directory path
|
|
401
|
-
restoreArgs.push(`/backups/${
|
|
406
|
+
// Add dump directory path (use source database name for dump location)
|
|
407
|
+
restoreArgs.push(`/backups/${dumpDbName}`);
|
|
402
408
|
|
|
403
409
|
// Execute mongorestore
|
|
404
410
|
await execa('docker', restoreArgs, {
|