замечания 3

This commit is contained in:
2025-11-02 12:40:42 +03:00
parent 35493a09b5
commit 0d1dcf21c1
29 changed files with 1498 additions and 1827 deletions

View File

@@ -6,17 +6,14 @@ const mongoUrl = process.env.MONGODB_URI || 'mongodb://localhost:27017/procureme
async function migrateMessages() {
try {
// 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');
}
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();
@@ -84,18 +81,13 @@ 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;
process.exit(1);
}
}
module.exports = { migrateMessages };
// Run directly if called as script
if (require.main === module) {
migrateMessages().catch(err => {
console.error('Migration failed:', err);
process.exit(1);
});
}
migrateMessages();