overleaf/migrations/7_add_token_indexes.coffee

52 lines
1.3 KiB
CoffeeScript
Raw Normal View History

Settings = require "settings-sharelatex"
fs = require("fs")
mongojs = require("mongojs")
ObjectId = mongojs.ObjectId
db = mongojs(Settings.mongo.url, ['docs','docHistory', 'docHistoryStats'])
_ = require("underscore")
async = require("async")
exec = require("child_process").exec
bson = require('bson')
BSON = new bson()
handleExit = () ->
console.log('Got signal. Shutting down.')
exports.migrate = (client, done=()->) ->
console.log ">> Adding indexes for token-based project access: "
db.projects.ensureIndex {'tokens.readAndWrite': 1}, {
2018-08-02 05:10:19 -04:00
partialFilterExpression: { 'tokens.readAndWrite': { $exists: true } },
unique: true,
background: true
}, (err) ->
if err?
return done(err)
db.projects.ensureIndex {'tokens.readOnly': 1}, {
partialFilterExpression: { 'tokens.readOnly': { $exists: true } },
unique: true,
background: true
}, (err) ->
if err?
return done(err)
2017-11-08 06:55:08 -05:00
db.projects.ensureIndex {tokenAccessReadAndWrite_refs: 1}, {
background: true
}, (err) ->
if err?
return done(err)
db.projects.ensureIndex {tokenAccessOnly_refs: 1}, {
background: true
}, (err) ->
console.log ">> done adding indexes for token-based project access"
done()
exports.rollback = (client, done) ->
done()
process.on 'SIGINT', handleExit
process.on 'SIGHUP', handleExit