Browse Source

fix: [vps] add more code to drop indexes and mitigate some migration issues

pull/6/head
Valentin Lab 9 months ago
parent
commit
83c41f54f2
  1. 40
      bin/vps

40
bin/vps

@ -887,8 +887,44 @@ export -f cyclos:unlock
rocketchat:drop-indexes() {
local project_name="$1" dbname="$2"
echo "db.users.dropIndexes()" |
compose:mongo "${project_name}" "${dbname}"
compose:mongo "${project_name}" "${dbname}" <<'EOF'
db.users.dropIndexes();
// Check if the 'rocketchat_uploads' collection exists
var collections = db.getCollectionNames();
if (collections.indexOf('rocketchat_uploads') !== -1) {
db.rocketchat_uploads.dropIndexes();
}
if (collections.indexOf('rocketchat_read_receipts') !== -1) {
db.rocketchat_read_receipts.dropIndexes();
var duplicates = [];
db.getCollection("rocketchat_read_receipts").aggregate([
{
"$group": {
"_id": { "roomId": "$roomId", "userId": "$userId", "messageId": "$messageId" },
"uniqueIds": { "$addToSet": "$_id" },
"count": { "$sum": 1 }
}
},
{ "$match": { "count": { "$gt": 1 } } }
],
{ allowDiskUse: true }
).forEach(function (doc) {
// remove 1st element
doc.uniqueIds.shift();
doc.uniqueIds.forEach(function (dupId) {
duplicates.push(dupId);
}
)
})
// printjson(duplicates);
db.getCollection("rocketchat_read_receipts").remove({ _id: { $in: duplicates } });
}
EOF
}
export -f rocketchat:drop-indexes

Loading…
Cancel
Save