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
e1af76f6
Commit
e1af76f6
authored
Mar 23, 2017
by
James Allen
Browse files
Address Henry's comments about robustness
parent
73443f5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
migrations/5_remove_holding_accounts.coffee
View file @
e1af76f6
...
...
@@ -24,7 +24,7 @@ module.exports = HoldingAccountMigration =
jobs
=
projects
.
map
(
project
)
->
(
cb
)
->
console
.
log
"[Removing user from project]"
,
user_id
,
JSON
.
stringify
(
project
)
if
!
project
.
_id
?
if
!
project
?
.
_id
?
throw
new
Error
(
"no project id"
)
if
!
HoldingAccountMigration
.
DRY_RUN
...
...
@@ -48,31 +48,31 @@ module.exports = HoldingAccountMigration =
deleteUser
:
(
user_id
,
callback
=
(
error
)
->
)
->
if
!
user_id
?
throw
new
Error
(
"must have user_id"
)
db
.
users
.
find
{
_id
:
user_id
},
(
error
,
user
)
->
return
callback
(
error
)
if
error
?
if
!
user
?
throw
new
Error
(
"expected user"
)
console
.
log
"[Removing user]"
,
user_id
,
JSON
.
stringify
(
user
)
if
!
HoldingAccountMigration
.
DRY_RUN
db
.
users
.
remove
{
_id
:
user_id
},
(
error
,
result
)
->
console
.
log
"[Removed user]"
,
user_id
,
result
callback
(
error
)
else
console
.
log
"[Would have removed user]"
,
user_id
if
!
HoldingAccountMigration
.
DRY_RUN
db
.
users
.
remove
{
_id
:
user_id
,
holdingAccount
:
true
},
(
error
,
result
)
->
return
callback
(
error
)
if
error
?
console
.
log
"[Removed user]"
,
user_id
,
result
if
result
.
n
!=
1
return
callback
(
new
Error
(
"failed to remove user as expected"
))
callback
()
else
console
.
log
"[Would have removed user]"
,
user_id
callback
()
run
:
(
done
)
->
run
:
(
done
=
()
->
)
->
HoldingAccountMigration
.
findHoldingAccounts
(
error
,
users
)
->
throw
error
if
error
?
console
.
log
"[Got list of holding accounts]"
,
users
.
map
(
u
)
->
u
.
_id
jobs
=
users
.
map
(
u
)
->
(
cb
)
->
HoldingAccountMigration
.
deleteUser
Projects
u
.
_id
,
(
error
)
->
HoldingAccountMigration
.
deleteUser
u
.
_id
,
(
error
)
->
return
cb
(
error
)
if
error
?
HoldingAccountMigration
.
deleteUser
u
.
_id
,
cb
HoldingAccountMigration
.
deleteUserProjects
u
.
_id
,
(
error
)
->
return
cb
(
error
)
if
error
?
setTimeout
cb
,
200
# Small delay to not hammer DB
async
.
series
jobs
,
(
error
)
->
throw
error
if
error
?
console
.
log
"[
Removed holding accounts
]"
console
.
log
"[
FINISHED
]"
done
()
migrate
:
(
client
,
done
=
()
->
)
->
...
...
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