diff --git a/packages/rocketchat-lib/server/models/Subscriptions.coffee b/packages/rocketchat-lib/server/models/Subscriptions.coffee index 596f7f779e1..fb43407722b 100644 --- a/packages/rocketchat-lib/server/models/Subscriptions.coffee +++ b/packages/rocketchat-lib/server/models/Subscriptions.coffee @@ -3,6 +3,13 @@ RocketChat.models.Subscriptions = new class asd extends RocketChat.models._Base constructor: -> @model = new Meteor.Collection 'rocketchat_subscription' + @tryEnsureIndex { 'rid': 1, 'u._id': 1 }, { unique: 1 } + @tryEnsureIndex { 'u._id': 1, 'name': 1, 't': 1 }, { unique: 1 } + @tryEnsureIndex { 'open': 1 } + @tryEnsureIndex { 'alert': 1 } + @tryEnsureIndex { 'unread': 1 } + @tryEnsureIndex { 'ts': 1 } + # FIND findByUserId: (userId, options) -> diff --git a/server/startup/indexes.coffee b/server/startup/indexes.coffee index 28eca27eefa..4676e241e68 100644 --- a/server/startup/indexes.coffee +++ b/server/startup/indexes.coffee @@ -3,13 +3,6 @@ Meteor.startup -> try ChatRoom._ensureIndex { 'name': 1 }, { unique: 1, sparse: 1 } catch e then console.log e try ChatRoom._ensureIndex { 'u._id': 1 } catch e then console.log e - try ChatSubscription._ensureIndex { 'rid': 1, 'u._id': 1 }, { unique: 1 } catch e then console.log e - try ChatSubscription._ensureIndex { 'u._id': 1, 'name': 1, 't': 1 }, { unique: 1 } catch e then console.log e - try ChatSubscription._ensureIndex { 'open': 1 } catch e then console.log e - try ChatSubscription._ensureIndex { 'alert': 1 } catch e then console.log e - try ChatSubscription._ensureIndex { 'unread': 1 } catch e then console.log e - try ChatSubscription._ensureIndex { 'ts': 1 } catch e then console.log e - try ChatMessage._ensureIndex { 'rid': 1, 'ts': 1 } catch e then console.log e try ChatMessage._ensureIndex { 'ets': 1 }, { sparse: 1 } catch e then console.log e try ChatMessage._ensureIndex { 'rid': 1, 't': 1, 'u._id': 1 } catch e then console.log e diff --git a/server/startup/migrations/v3.coffee b/server/startup/migrations/v3.coffee index edddfe6b121..ed06ded1c0e 100644 --- a/server/startup/migrations/v3.coffee +++ b/server/startup/migrations/v3.coffee @@ -3,10 +3,9 @@ Meteor.startup -> version: 3 up: -> - try - ChatSubscription._dropIndex 'uid_1' - try - ChatSubscription._dropIndex 'rid_1_uid_1' + + RocketChat.models.Subscriptions.tryDropIndex 'uid_1' + RocketChat.models.Subscriptions.tryDropIndex 'rid_1_uid_1' console.log 'Fixing ChatSubscription uid' diff --git a/server/startup/migrations/v4.coffee b/server/startup/migrations/v4.coffee index f607aa0c687..f2575482fd9 100644 --- a/server/startup/migrations/v4.coffee +++ b/server/startup/migrations/v4.coffee @@ -4,7 +4,7 @@ Meteor.startup -> up: -> try ChatMessage._dropIndex 'rid_1' - try ChatSubscription._dropIndex 'u._id_1' + RocketChat.models.Subscriptions.tryDropIndex 'u._id_1' console.log 'Rename rn to name'