From 89fdb3d017daf8eb7e6108c49fed7160f9355f89 Mon Sep 17 00:00:00 2001 From: l-gorman Date: Tue, 12 Jul 2022 16:49:10 +0100 Subject: [PATCH] Adding a migration to fix the data collection details of finalised forms --- ...pdate-finalised-form-details-12-07-2022.js | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 migrations/update-finalised-form-details-12-07-2022.js diff --git a/migrations/update-finalised-form-details-12-07-2022.js b/migrations/update-finalised-form-details-12-07-2022.js new file mode 100644 index 0000000..4b5dd64 --- /dev/null +++ b/migrations/update-finalised-form-details-12-07-2022.js @@ -0,0 +1,66 @@ +#!/usr/bin/env node + +// For the correct environment run with prefix +// NODE_ENV= +// e.g. +// NODE_ENV=dev node migrations/update-finalised-form-details-12-07-2022.js +const GetConfigDetailsAndConnect = require('./setup.js') +const mongoose = require('mongoose') + +const Form = require('../models/Form') + +// RunScript('./migrations/setup.js', function (err) { +// if (err) throw err; +// console.log('Finished Running Setup'); +// }); + +const db = GetConfigDetailsAndConnect() + + +async function run(db) { + + + + // If form is currently marked as draft true + // Need to set 'live' to false + + const finalisedForms = await Form.find({live:true}) + + + finalisedForms.forEach(async (form)=>{ + + + const UpdatedFinalForms = await Form.updateOne( + {name: form.name, project: form.project}, + { $set: { "collectionDetails.general.server_url": form.collectionDetails.general.server_url + "/forms/" + form.name }, + draftVersion:null} + ) + + }) + + + const forms = await Form.find() + console.log(forms) + + + db.close() + + + + return +} + +run(db) + + + + + + + + + + + + +