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
05540ca8
Commit
05540ca8
authored
Jan 30, 2017
by
James Allen
Browse files
Add migration to remove holding accounts
parent
fa89f55a
Changes
2
Hide whitespace changes
Inline
Side-by-side
migrations/5_remove_holding_accounts.coffee
0 → 100644
View file @
05540ca8
Settings
=
require
"settings-sharelatex"
mongojs
=
require
(
"mongojs"
)
ObjectId
=
mongojs
.
ObjectId
db
=
mongojs
(
Settings
.
mongo
.
url
,
[
'users'
,
'projects'
])
async
=
require
"async"
findHoldingAccounts
=
(
callback
=
(
error
,
users
)
->
)
->
db
.
users
.
find
({
holdingAccount
:
true
},
{
holdingAccount
:
1
,
email
:
1
},
callback
)
deleteUserProjects
=
(
user_id
,
callback
=
(
error
)
->
)
->
# Holding accounts can't own projects, so only remove from
# collaberator_refs and readOnly_refs
console
.
log
"[Removing user from projects]"
,
user_id
db
.
projects
.
update
{
$or
:
[
{
collaberator_refs
:
user_id
},
{
readOnly_refs
:
user_id
}
]
},
{
$pull
:
{
collaberator_refs
:
user_id
,
readOnly_refs
:
user_id
}
},
{
multi
:
true
},
(
error
,
result
)
->
console
.
log
"[Removed user from projects]"
,
user_id
,
result
callback
(
error
)
deleteUser
=
(
user_id
,
callback
=
(
error
)
->
)
->
if
!
user_id
?
throw
new
Error
(
"must have user_id"
)
console
.
log
"[Removing user]"
,
user_id
db
.
users
.
remove
{
_id
:
user_id
},
(
error
,
result
)
->
console
.
log
"[Removed user]"
,
user_id
,
result
callback
(
error
)
exports
.
migrate
=
(
client
,
done
=
()
->
)
->
findHoldingAccounts
(
error
,
users
)
->
throw
error
if
error
?
console
.
log
"[Got list of holding accounts]"
,
users
.
map
(
u
)
->
u
.
_id
jobs
=
users
.
map
(
u
)
->
(
cb
)
->
deleteUserProjects
u
.
_id
,
(
error
)
->
return
cb
(
error
)
if
error
?
deleteUser
u
.
_id
,
cb
async
.
series
jobs
,
(
error
)
->
throw
error
if
error
?
console
.
log
"[Removed holding accounts]"
done
()
exports
.
rollback
=
(
client
,
done
)
->
done
()
migrations/about_migrations.md
View file @
05540ca8
*
if migration is stopped mid way it will start at the beginging next time
*
to see the run migrations do db.getCollection('_migrations').find() you can't do db._migrations.find()
\ No newline at end of file
If migration is stopped mid way it will start at the beginging next time
To see the run migrations do db.getCollection('_migrations').find() you can't do db._migrations.find()
When testing, to roll back a migration run:
```
./node_modules/east/bin/east rollback 5 --adapter east-mongo --url mongodb://localhost:27017/sharelatex
```
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