genbox 1.0.76 → 1.0.78
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/dist/commands/create.js +5 -0
- package/dist/commands/rebuild.js +11 -0
- package/dist/commands/status.js +2 -2
- package/dist/db-utils.js +18 -0
- package/package.json +1 -1
package/dist/commands/create.js
CHANGED
|
@@ -555,6 +555,10 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
555
555
|
// Build payload
|
|
556
556
|
const payloadResolved = { ...resolved };
|
|
557
557
|
if (snapshotId && snapshotS3Key) {
|
|
558
|
+
// Extract database name from source URL for restore
|
|
559
|
+
const sourceDatabase = resolved.database?.url
|
|
560
|
+
? (0, db_utils_1.extractDatabaseName)(resolved.database.url)
|
|
561
|
+
: undefined;
|
|
558
562
|
// Use S3 snapshot mode
|
|
559
563
|
payloadResolved.database = {
|
|
560
564
|
...resolved.database,
|
|
@@ -562,6 +566,7 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
562
566
|
mode: 'snapshot',
|
|
563
567
|
snapshotId,
|
|
564
568
|
s3Key: snapshotS3Key,
|
|
569
|
+
sourceDatabase, // Pass the database name for correct restore
|
|
565
570
|
};
|
|
566
571
|
}
|
|
567
572
|
const payload = buildPayload(payloadResolved, config, publicKey, privateKeyContent, configLoader);
|
package/dist/commands/rebuild.js
CHANGED
|
@@ -328,6 +328,17 @@ async function runSoftRebuild(options) {
|
|
|
328
328
|
}
|
|
329
329
|
else {
|
|
330
330
|
log('✓ Database restored', 'success');
|
|
331
|
+
// Update MONGODB_URI in app .env files to point to the correct database
|
|
332
|
+
const sourceDatabase = resolved.database?.url
|
|
333
|
+
? (0, db_utils_1.extractDatabaseName)(resolved.database.url)
|
|
334
|
+
: undefined;
|
|
335
|
+
if (sourceDatabase) {
|
|
336
|
+
log('Updating MONGODB_URI in app .env files...', 'info');
|
|
337
|
+
const newMongoUri = `mongodb://localhost:${mongoPort}/${sourceDatabase}`;
|
|
338
|
+
const updateCmd = `find /home/dev -name ".env" -type f -exec grep -l "^MONGODB_URI=" {} \\; | xargs -I{} sed -i 's|^MONGODB_URI=.*|MONGODB_URI=${newMongoUri}|' {}`;
|
|
339
|
+
await sshExec(ip, keyPath, updateCmd, 30);
|
|
340
|
+
log(`✓ MONGODB_URI updated to ${newMongoUri}`, 'success');
|
|
341
|
+
}
|
|
331
342
|
}
|
|
332
343
|
// Cleanup
|
|
333
344
|
await sshExec(ip, keyPath, 'rm -f /tmp/db-snapshot.gz', 10);
|
package/dist/commands/status.js
CHANGED
|
@@ -308,11 +308,11 @@ exports.statusCommand = new commander_1.Command('status')
|
|
|
308
308
|
console.log(` Last activity: ${minutesInactive < 1 ? 'just now' : minutesInactive + ' min ago'}`);
|
|
309
309
|
console.log(` Total: ${billing.totalHoursUsed} hour${billing.totalHoursUsed !== 1 ? 's' : ''}, ${billing.totalCreditsUsed} credit${billing.totalCreditsUsed !== 1 ? 's' : ''}`);
|
|
310
310
|
if (billing.autoDestroyOnInactivity && billing.currentHourEnd) {
|
|
311
|
-
// Auto-destroy happens at 58 min mark into billing hour
|
|
311
|
+
// Auto-destroy happens at 58 min mark into billing hour if no activity after 50 min mark
|
|
312
312
|
const currentHourEnd = new Date(billing.currentHourEnd);
|
|
313
313
|
const currentHourStart = new Date(currentHourEnd.getTime() - 60 * 60 * 1000);
|
|
314
314
|
const minutesIntoBillingHour = Math.floor((now.getTime() - currentHourStart.getTime()) / (60 * 1000));
|
|
315
|
-
const minutesUntilDestroy = Math.max(0,
|
|
315
|
+
const minutesUntilDestroy = Math.max(0, 58 - minutesIntoBillingHour);
|
|
316
316
|
if (minutesInactive >= 5) {
|
|
317
317
|
console.log(chalk_1.default.yellow(` Auto-destroy in: ${minutesUntilDestroy} min (inactive)`));
|
|
318
318
|
}
|
package/dist/db-utils.js
CHANGED
|
@@ -42,6 +42,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
42
42
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.extractDatabaseName = extractDatabaseName;
|
|
45
46
|
exports.isMongoDumpAvailable = isMongoDumpAvailable;
|
|
46
47
|
exports.getMongoDumpInstallInstructions = getMongoDumpInstallInstructions;
|
|
47
48
|
exports.runLocalMongoDump = runLocalMongoDump;
|
|
@@ -59,6 +60,23 @@ const fs = __importStar(require("fs"));
|
|
|
59
60
|
const path = __importStar(require("path"));
|
|
60
61
|
const os = __importStar(require("os"));
|
|
61
62
|
const chalk_1 = __importDefault(require("chalk"));
|
|
63
|
+
/**
|
|
64
|
+
* Extract database name from MongoDB connection URL
|
|
65
|
+
* Handles both standard (mongodb://) and SRV (mongodb+srv://) URLs
|
|
66
|
+
* Example: mongodb://localhost:27037/genbox -> genbox
|
|
67
|
+
* Example: mongodb+srv://user:pass@cluster.mongodb.net/mydb?retryWrites=true -> mydb
|
|
68
|
+
*/
|
|
69
|
+
function extractDatabaseName(mongoUrl) {
|
|
70
|
+
try {
|
|
71
|
+
// Handle both mongodb:// and mongodb+srv:// URLs
|
|
72
|
+
// The database name comes after the host:port (or host for SRV) and before any query params
|
|
73
|
+
const match = mongoUrl.match(/mongodb(?:\+srv)?:\/\/[^/]+\/([^?/]+)/);
|
|
74
|
+
return match?.[1];
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
62
80
|
/**
|
|
63
81
|
* Check if mongodump is available locally
|
|
64
82
|
*/
|