Skip to content

Commit

Permalink
chore: remove migration
Browse files Browse the repository at this point in the history
  • Loading branch information
realabdullah committed Dec 18, 2023
1 parent 512b1e8 commit e750236
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ import 'dotenv/config';
// eslint-disable-next-line no-unused-vars
import mongoose from './db.js';

const CommentSchema = new mongoose.Schema({
message: {
type: String,
require: true,
},
task: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Task',
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
},
createdAt: Date,
});

const app = express();
const port = process.env.PORT || 3000;

Expand All @@ -41,20 +25,4 @@ app.use('/tasks', task);
app.use('/teams', team);
app.use('/invite', invite);

async function migrateCollections(sourceCollectionName, destinationCollectionName) {
try {
const SourceModel = mongoose.model(sourceCollectionName, CommentSchema);
const DestinationModel = mongoose.model(destinationCollectionName, CommentSchema);

const documents = await SourceModel.find().lean().exec();
await DestinationModel.insertMany(documents);

console.log(`Migration complete: ${documents.length} documents migrated.`);
} catch (error) {
console.error('Migration error:', error);
}
}

await migrateCollections('chats', 'comments');

app.listen(port, () => console.log(`Server is running on port ${port}`));

0 comments on commit e750236

Please sign in to comment.