الملفات
FlowSync/serverUtils/restoreDatabase.js
Mino484 1fda64ec43
فشلت بعض الفحوصات
Release Please / release-please (push) Has been cancelled
Docker Build and Push (Development) / build-and-push-dev (push) Has been cancelled
working v1
2025-11-17 17:19:47 +03:00

56 أسطر
1.2 KiB
JavaScript

const mongoose = require("../backend/db/mongooseServerUtils");
const prompts = require("prompts");
const restoreFromTempDirectory = require("./restoreFromTempDirectory");
const conn = mongoose.connection;
const waitForDatabase = () => {
return new Promise((resolve, reject) => {
if (conn.readyState !== 1) {
conn.once("open", () => {
resolve();
})
} else {
resolve();
}
})
}
const restoreDatabase = async() => {
const userConfimation = await prompts({
type: 'text',
message: "Warning: This will delete ALL data," +
" other than the Data Backup created by CopyDatabase. \nMake sure to first run CopyDatabase, and backup" +
" your data, \nWould you like to continue? (Yes/No)",
name: "value"
})
if (!userConfimation.value || userConfimation.value.toLowerCase() !== "yes") {
console.log("Exiting...")
process.exit()
return;
} else {
await waitForDatabase();
await restoreFromTempDirectory();
console.log("Finished Restoring Data, Exiting...");
process.exit();
}
}
restoreDatabase()