|
@@ -1,6 +1,5 @@
|
|
|
-const { db, ObjectId } = require('../app/src/infrastructure/mongojs')
|
|
|
|
|
|
|
+const { db, ObjectId, waitForDb } = require('../app/src/infrastructure/mongodb')
|
|
|
const minimist = require('minimist')
|
|
const minimist = require('minimist')
|
|
|
-const _ = require('lodash')
|
|
|
|
|
const argv = minimist(process.argv.slice(2))
|
|
const argv = minimist(process.argv.slice(2))
|
|
|
const commit = argv.commit !== undefined
|
|
const commit = argv.commit !== undefined
|
|
|
const projectIds = argv._.map(x => {
|
|
const projectIds = argv._.map(x => {
|
|
@@ -11,57 +10,44 @@ if (!commit) {
|
|
|
console.log('Doing dry run without --commit')
|
|
console.log('Doing dry run without --commit')
|
|
|
}
|
|
}
|
|
|
console.log('checking', projectIds.length, 'projects')
|
|
console.log('checking', projectIds.length, 'projects')
|
|
|
-db.projects.find(
|
|
|
|
|
- {
|
|
|
|
|
- _id: { $in: projectIds }
|
|
|
|
|
- },
|
|
|
|
|
- (err, affectedProjects) => {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- throw err
|
|
|
|
|
- }
|
|
|
|
|
- console.log('Found ' + affectedProjects.length + ' affected projects')
|
|
|
|
|
- affectedProjects.forEach(x => {
|
|
|
|
|
- console.log(
|
|
|
|
|
- JSON.stringify(
|
|
|
|
|
- _.pick(x, [
|
|
|
|
|
- '_id',
|
|
|
|
|
- 'owner_ref',
|
|
|
|
|
- 'tokenAccessReadOnly_refs',
|
|
|
|
|
- 'tokenAccessReadAndWrite_refs'
|
|
|
|
|
- ])
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
- if (!commit) {
|
|
|
|
|
- console.log('dry run, not updating')
|
|
|
|
|
- process.exit(0)
|
|
|
|
|
- } else {
|
|
|
|
|
- db.projects.update(
|
|
|
|
|
- {
|
|
|
|
|
- _id: {
|
|
|
|
|
- $in: affectedProjects.map(x => {
|
|
|
|
|
- return x._id
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
|
|
+waitForDb().then(async () => {
|
|
|
|
|
+ const affectedProjects = await db.projects
|
|
|
|
|
+ .find(
|
|
|
|
|
+ { _id: { $in: projectIds } },
|
|
|
|
|
+ {
|
|
|
|
|
+ projection: {
|
|
|
|
|
+ _id: 1,
|
|
|
|
|
+ owner_ref: 1,
|
|
|
|
|
+ tokenAccessReadOnly_refs: 1,
|
|
|
|
|
+ tokenAccessReadAndWrite_refs: 1
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ .toArray()
|
|
|
|
|
+ console.log('Found ' + affectedProjects.length + ' affected projects')
|
|
|
|
|
+ affectedProjects.forEach(project => {
|
|
|
|
|
+ console.log(JSON.stringify(project))
|
|
|
|
|
+ })
|
|
|
|
|
+ if (!commit) {
|
|
|
|
|
+ console.log('dry run, not updating')
|
|
|
|
|
+ process.exit(0)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const result = await db.projects.updateMany(
|
|
|
|
|
+ { _id: { $in: affectedProjects.map(project => project._id) } },
|
|
|
{
|
|
{
|
|
|
$set: {
|
|
$set: {
|
|
|
publicAccesLevel: 'private', // note the spelling in the db is publicAccesLevel (with one 's')
|
|
publicAccesLevel: 'private', // note the spelling in the db is publicAccesLevel (with one 's')
|
|
|
tokenAccessReadOnly_refs: [],
|
|
tokenAccessReadOnly_refs: [],
|
|
|
tokenAccessReadAndWrite_refs: []
|
|
tokenAccessReadAndWrite_refs: []
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- multi: true
|
|
|
|
|
- },
|
|
|
|
|
- (err, result) => {
|
|
|
|
|
- console.log('err', err, 'result', result)
|
|
|
|
|
- db.close()
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- process.exit(0)
|
|
|
|
|
- }, 5000)
|
|
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
+ console.log('result', JSON.stringify(result))
|
|
|
|
|
+ process.exit(0)
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ console.error('err', err)
|
|
|
|
|
+ process.exit(1)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-)
|
|
|
|
|
|
|
+})
|