Skip to content

Commit

Permalink
fixing migration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
engelgabriel committed Jun 23, 2015
1 parent 929be89 commit fd7c3b7
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 39 deletions.
4 changes: 2 additions & 2 deletions packages/rocketchat-hubot/hubot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ RocketChat.callbacks.add 'afterSaveMessage', RocketBotReceiver, RocketChat.callb
# keepalive = -> Meteor.call 'setPresence',
# u:
# username: 'rocketbot'
# rid: '57om6EQCcFami9wuT'
# rid: 'GENERAL'
# present: true
# foreground: true
# keepalive()
Expand All @@ -230,7 +230,7 @@ RocketChat.callbacks.add 'afterSaveMessage', RocketBotReceiver, RocketChat.callb
# adapter.receive tm
# startup = false
# Meteor.call "sendMessage",
# rid: '57om6EQCcFami9wuT'
# rid: 'GENERAL'
# msg: 'wakes up'
# u:
# username: "rocketbot"
Expand Down
8 changes: 4 additions & 4 deletions server/methods/setUsername.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Meteor.methods

if not user.username?
# put user in general channel
ChatRoom.update '57om6EQCcFami9wuT',
ChatRoom.update 'GENERAL',
$push:
usernames:
$each: [username]
$sort: 1

if not ChatSubscription.findOne(rid: '57om6EQCcFami9wuT', 'u._id': user._id)?
if not ChatSubscription.findOne(rid: 'GENERAL', 'u._id': user._id)?
ChatSubscription.insert
rid: '57om6EQCcFami9wuT'
rid: 'GENERAL'
name: 'general'
ts: new Date()
t: 'c'
Expand All @@ -39,7 +39,7 @@ Meteor.methods
username: username

ChatMessage.insert
rid: '57om6EQCcFami9wuT'
rid: 'GENERAL'
ts: new Date()
t: 'uj'
msg: ''
Expand Down
10 changes: 0 additions & 10 deletions server/startup/generalRoom.coffee

This file was deleted.

40 changes: 25 additions & 15 deletions server/startup/initialData.coffee
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
lineSep = '---------------------------'

Meteor.startup ->
if not Meteor.users.findOne()?
console.log lineSep.red
console.log 'Inserting user admin'.red
console.log 'email: admin@admin.com | password: admin'.red
Meteor.defer ->


if not ChatRoom.findOne('name': 'general')?
ChatRoom.insert
_id: 'GENERAL'
usernames: []
ts: new Date()
t: 'c'
name: 'general'
msgs: 0


# if not Meteor.users.findOne()?
# console.log 'Inserting user admin'.red
# console.log 'email: admin@admin.com | password: admin'.red

id = Meteor.users.insert
createdAt: new Date
emails: [
address: 'admin@admin.com'
verified: true
],
name: 'Admin'
avatarOrigin: 'none'
# id = Meteor.users.insert
# createdAt: new Date
# emails: [
# address: 'admin@admin.com'
# verified: true
# ],
# name: 'Admin'
# avatarOrigin: 'none'

Accounts.setPassword id, 'admin'
# Accounts.setPassword id, 'admin'
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions server/startup/migrations/v4.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,4 @@ Meteor.startup ->
ChatSubscription.update {rid: item._id}, {$set: {name: name}}, {multi: true}


console.log 'Dropping test rooms with less than 10 messages'
ChatRoom.find({msgs: {'$lt': 10}}).forEach (room) ->
ChatRoom.remove room._id
ChatMessage.remove {rid: room._id}
ChatSubscription.remove {rid: room._id}


console.log 'End'
17 changes: 17 additions & 0 deletions server/startup/migrations/v6.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Meteor.startup ->
Migrations.add
version: 6
up: ->

console.log 'Changin _id of #general channel room from 57om6EQCcFami9wuT to GENERAL'
room = ChatRoom.findOne('57om6EQCcFami9wuT')
newId = 'GENERAL'
if room
ChatSubscription.update({'rid':room._id},{'$set':{'rid':newId}},{'multi':1})
ChatMessage.update({'rid':room._id},{'$set':{'rid':newId}},{'multi':1})
ChatRoom.remove({'_id':room._id})
delete room._id
ChatRoom.upsert({'_id':newId}, { $set: room})


console.log 'End'
7 changes: 6 additions & 1 deletion server/startup/migrations/xrun.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Meteor.startup ->
Meteor.defer ->
Migrations.migrateTo 'latest'
if Migrations.getVersion() isnt 0
Migrations.migrateTo 'latest'
else
control = Migrations._getControl()
control.version = _.last(Migrations._list).version
Migrations._setControl control

0 comments on commit fd7c3b7

Please sign in to comment.