-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2658 from responsible-ai-collaborative/staging
Deploy to Production
- Loading branch information
Showing
11 changed files
with
293 additions
and
86 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
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
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
180 changes: 180 additions & 0 deletions
180
...atsby-site/migrations/2024.02.01T20.03.56.set-incidents-submissions-reports-created_at.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
const config = require('../config'); | ||
/** | ||
* | ||
* @param {{context: {client: import('mongodb').MongoClient}}} context | ||
*/ | ||
|
||
exports.up = async ({ context: { client } }) => { | ||
await client.connect(); | ||
|
||
// New created_at field on incidents, reports, submissions collections from production db and history db | ||
const incidentsCollection = client.db(config.realm.production_db.db_name).collection('incidents'); | ||
|
||
const submissionsCollection = client | ||
.db(config.realm.production_db.db_name) | ||
.collection('submissions'); | ||
|
||
const reportsCollection = client.db(config.realm.production_db.db_name).collection('reports'); | ||
|
||
const incidentsHistoryCollection = client | ||
.db(config.realm.production_db.db_history_name) | ||
.collection('incidents'); | ||
|
||
const submissionsHistoryCollection = client | ||
.db(config.realm.production_db.db_history_name) | ||
.collection('submissions'); | ||
|
||
const reportsHistoryCollection = client | ||
.db(config.realm.production_db.db_history_name) | ||
.collection('reports'); | ||
|
||
const incidentsCursor = incidentsCollection.find({}); | ||
|
||
const incidentsHistoryCursor = incidentsHistoryCollection.find({}); | ||
|
||
const submissionsCursor = submissionsCollection.find({}); | ||
|
||
const submissionsHistoryCursor = submissionsHistoryCollection.find({}); | ||
|
||
const reportsCursor = reportsCollection.find({}); | ||
|
||
const reportsHistoryCursor = reportsHistoryCollection.find({}); | ||
|
||
let updatedCount = 0; | ||
|
||
while (await incidentsCursor.hasNext()) { | ||
const incident = await incidentsCursor.next(); | ||
|
||
const created_at = new Date(incident.date); | ||
|
||
await incidentsCollection.updateOne( | ||
{ _id: incident._id }, | ||
{ | ||
$set: { | ||
created_at: created_at, | ||
}, | ||
} | ||
); | ||
|
||
incident.created_at = created_at; | ||
|
||
updatedCount++; | ||
} | ||
|
||
console.log(`Updated ${updatedCount} incidents with new created_at field`); | ||
|
||
updatedCount = 0; | ||
|
||
while (await incidentsHistoryCursor.hasNext()) { | ||
const incident = await incidentsHistoryCursor.next(); | ||
|
||
const created_at = new Date(incident.date); | ||
|
||
await incidentsHistoryCollection.updateOne( | ||
{ _id: incident._id }, | ||
{ | ||
$set: { | ||
created_at: created_at, | ||
}, | ||
} | ||
); | ||
|
||
incident.created_at = created_at; | ||
|
||
updatedCount++; | ||
} | ||
|
||
console.log(`Updated ${updatedCount} incidents history with new created_at field`); | ||
|
||
updatedCount = 0; | ||
|
||
while (await submissionsCursor.hasNext()) { | ||
const submission = await submissionsCursor.next(); | ||
|
||
const created_at = new Date(submission.date_submitted); | ||
|
||
await submissionsCollection.updateOne( | ||
{ _id: submission._id }, | ||
{ | ||
$set: { | ||
created_at: created_at, | ||
}, | ||
} | ||
); | ||
|
||
submission.created_at = created_at; | ||
|
||
updatedCount++; | ||
} | ||
|
||
console.log(`Updated ${updatedCount} submissions with new created_at field`); | ||
|
||
updatedCount = 0; | ||
|
||
while (await submissionsHistoryCursor.hasNext()) { | ||
const submission = await submissionsHistoryCursor.next(); | ||
|
||
const created_at = new Date(submission.date_submitted); | ||
|
||
await submissionsHistoryCollection.updateOne( | ||
{ _id: submission._id }, | ||
{ | ||
$set: { | ||
created_at: created_at, | ||
}, | ||
} | ||
); | ||
|
||
submission.created_at = created_at; | ||
|
||
updatedCount++; | ||
} | ||
|
||
console.log(`Updated ${updatedCount} submissions history with new created_at field`); | ||
|
||
updatedCount = 0; | ||
|
||
while (await reportsCursor.hasNext()) { | ||
const report = await reportsCursor.next(); | ||
|
||
const created_at = new Date(report.date_submitted); | ||
|
||
await reportsCollection.updateOne( | ||
{ _id: report._id }, | ||
{ | ||
$set: { | ||
created_at: created_at, | ||
}, | ||
} | ||
); | ||
|
||
report.created_at = created_at; | ||
|
||
updatedCount++; | ||
} | ||
|
||
console.log(`Updated ${updatedCount} reports with new created_at field`); | ||
|
||
updatedCount = 0; | ||
|
||
while (await reportsHistoryCursor.hasNext()) { | ||
const report = await reportsHistoryCursor.next(); | ||
|
||
const created_at = new Date(report.date_submitted); | ||
|
||
await reportsHistoryCollection.updateOne( | ||
{ _id: report._id }, | ||
{ | ||
$set: { | ||
created_at: created_at, | ||
}, | ||
} | ||
); | ||
|
||
report.created_at = created_at; | ||
|
||
updatedCount++; | ||
} | ||
|
||
console.log(`Updated ${updatedCount} reports history with new created_at field`); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.