Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hub
overleaf
Commits
7ef02127
Commit
7ef02127
authored
Jun 14, 2017
by
James Allen
Browse files
Update migration script for holding accounts to migrate group invites
parent
65d21f71
Changes
1
Hide whitespace changes
Inline
Side-by-side
migrations/5_remove_holding_accounts.coffee
View file @
7ef02127
Settings
=
require
"settings-sharelatex"
mongojs
=
require
(
"mongojs"
)
ObjectId
=
mongojs
.
ObjectId
db
=
mongojs
(
Settings
.
mongo
.
url
,
[
'users'
,
'projects'
])
db
=
mongojs
(
Settings
.
mongo
.
url
,
[
'users'
,
'projects'
,
'subscriptions'
])
async
=
require
"async"
module
.
exports
=
HoldingAccountMigration
=
...
...
@@ -58,6 +58,21 @@ module.exports = HoldingAccountMigration =
else
console
.
log
"[Would have removed user]"
,
user_id
callback
()
migrateGroupInvites
:
(
user_id
,
email
,
callback
=
(
error
)
->
)
->
if
!
user_id
?
throw
new
Error
(
"must have user_id"
)
if
!
HoldingAccountMigration
.
DRY_RUN
db
.
subscriptions
.
update
{
member_ids
:
user_id
},
{
$pull
:
{
member_ids
:
user_id
},
$addToSet
:
{
invited_emails
:
email
}
},
{
multi
:
true
},
(
error
,
result
)
->
return
callback
(
error
)
if
error
?
console
.
log
"[Migrated user in group accounts]"
,
user_id
,
email
,
result
callback
()
else
console
.
log
"[Would have migrated user in group accounts]"
,
user_id
,
email
callback
()
run
:
(
done
=
()
->
)
->
console
.
log
"[Getting list of holding accounts]"
...
...
@@ -68,11 +83,13 @@ module.exports = HoldingAccountMigration =
jobs
=
users
.
map
(
u
)
->
(
cb
)
->
console
.
log
"[Removing user
#{
i
++
}
/
#{
users
.
length
}
]"
HoldingAccountMigration
.
deleteUser
u
.
_id
,
(
error
)
->
HoldingAccountMigration
.
migrateGroupInvites
u
.
_id
,
u
.
email
,
(
error
)
->
return
cb
(
error
)
if
error
?
HoldingAccountMigration
.
deleteUser
Projects
u
.
_id
,
(
error
)
->
HoldingAccountMigration
.
deleteUser
u
.
_id
,
(
error
)
->
return
cb
(
error
)
if
error
?
setTimeout
cb
,
50
# Small delay to not hammer DB
HoldingAccountMigration
.
deleteUserProjects
u
.
_id
,
(
error
)
->
return
cb
(
error
)
if
error
?
setTimeout
cb
,
50
# Small delay to not hammer DB
async
.
series
jobs
,
(
error
)
->
throw
error
if
error
?
console
.
log
"[FINISHED]"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment