From 9a015b57989d1e52ff2a61d678e16886c2427754 Mon Sep 17 00:00:00 2001 From: Pablo Costa Date: Mon, 28 Oct 2024 18:09:34 -0300 Subject: [PATCH] Remove report attribution (#3184) --- ...0.25T21.09.57.remove-report-attribution.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 site/gatsby-site/migrations/2024.10.25T21.09.57.remove-report-attribution.js diff --git a/site/gatsby-site/migrations/2024.10.25T21.09.57.remove-report-attribution.js b/site/gatsby-site/migrations/2024.10.25T21.09.57.remove-report-attribution.js new file mode 100644 index 0000000000..4d2aa82e76 --- /dev/null +++ b/site/gatsby-site/migrations/2024.10.25T21.09.57.remove-report-attribution.js @@ -0,0 +1,24 @@ +const config = require('../config'); + +/** @type {import('umzug').MigrationFn} */ +exports.up = async ({ context: { client } }) => { + const reportsCollection = client.db(config.realm.production_db.db_name).collection('reports'); + + // Change "AIAAIC" to "Anonymous" if it is the only element in the `submitters` array + const result1 = await reportsCollection.updateMany( + { submitters: ['AIAAIC'] }, + { $set: { submitters: ['Anonymous'] } } + ); + + console.log(`Modified ${result1.modifiedCount} documents where "AIAAIC" was the only submitter`); + + // Remove "AIAAIC" from the `submitters` array if there are multiple elements + const result2 = await reportsCollection.updateMany( + { submitters: 'AIAAIC' }, + { $pull: { submitters: 'AIAAIC' } } + ); + + console.log( + `Modified ${result2.modifiedCount} documents where "AIAAIC" was one of the submitters` + ); +};