Created
November 29, 2022 02:41
-
-
Save bfagundez/d1a5525bf3692e237f08fe2ff16ce99a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const { prisma } = require ('@upmetrics-platform/prisma/generated/prisma-client') | |
const { MongoClient, ObjectId } = require('mongodb') | |
void async function() { | |
let successCount = 0 | |
let failureCount = 0 | |
let skippedCount = 0 | |
let mongoOrgSettings = null | |
const d = new Date(); | |
const orgs = await prisma.organizations().$fragment(`{ id }`) | |
console.log('total orgs',orgs.length) | |
const mongoClient = await MongoClient.connect(process.env.MONGO_DB_SRV_URI, { | |
useNewUrlParser: true, | |
poolSize: 10 | |
}) | |
const db = mongoClient.db('orgs-'+process.env.DEV_STAGE); | |
const coll = db.collection('organization-settings-entity') | |
for(let org of orgs ){ | |
try { | |
mongoOrgSettings = await coll.findOne({'orgId':org.id}) | |
if(mongoOrgSettings){ | |
console.log('Settings already exist, skipping this org id:',org.id) | |
skippedCount += 1; | |
continue; | |
} else { | |
await coll.insertOne({ | |
'_id': new ObjectId(), | |
'createdAt': d, | |
'updatedAt': d, | |
'orgId': org.id, | |
'storySentimentAnalysisEnabled': true | |
}) | |
successCount += 1 | |
} | |
} catch(e){ | |
failureCount += 1 | |
console.log('did not create this org settings',org.id,e) | |
} | |
} | |
console.log('Successes: ', successCount) | |
console.log('Skipped: ', skippedCount) | |
console.log('Failures: ', failureCount) | |
console.log('Org settings created') | |
process.exit(0) | |
}(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment