This commit is contained in:
2025-10-27 20:04:02 +03:00
parent 390d97e6d5
commit 35493a09b5
6 changed files with 48 additions and 51 deletions

View File

@@ -6,14 +6,17 @@ const mongoUrl = process.env.MONGODB_URI || 'mongodb://localhost:27017/procureme
async function migrateMessages() {
try {
console.log('[Migration] Connecting to MongoDB...');
await mongoose.connect(mongoUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 5000,
connectTimeoutMS: 5000,
});
console.log('[Migration] Connected to MongoDB');
// Check if connection exists, if not connect
if (mongoose.connection.readyState === 0) {
console.log('[Migration] Connecting to MongoDB...');
await mongoose.connect(mongoUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 5000,
connectTimeoutMS: 5000,
});
console.log('[Migration] Connected to MongoDB');
}
// Найти все сообщения
const allMessages = await Message.find().exec();
@@ -81,9 +84,6 @@ async function migrateMessages() {
console.log('[Migration] ✅ Migration completed!');
console.log('[Migration] Fixed:', fixedCount, 'messages');
console.log('[Migration] Errors:', errorCount);
await mongoose.connection.close();
console.log('[Migration] Disconnected from MongoDB');
} catch (err) {
console.error('[Migration] ❌ Error:', err.message);
throw err;