Skip to content

Commit

Permalink
Adding a migration to add the "live" attribute to forms where necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
l-gorman committed Jun 30, 2022
1 parent 38bbbf9 commit d4232b4
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions migrations/add-live-feature-15-04-2022.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env node

// For the correct environment run with prefix
// NODE_ENV=<dev|prod|test>
// e.g.
// NODE_ENV=dev node migrations/add-live-feature-15-04-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 UpdatedDraftForms = await Form.updateMany(
{draft: true},
{live:false}
)

// If form is currently marked as draft false
// Need to set 'live' to true
const UpdatedFinalForms = await Form.updateMany(
{draft: false},
{live:true}
)

const forms = await Form.find()
console.log(forms)


db.close()



return
}

run(db)













0 comments on commit d4232b4

Please sign in to comment.