script_for_migration.js 790 B

12345678910111213141516171819202122232425262728
  1. /* subscription.freeTrialExpiresAt
  2. * Example script for a migration:
  3. *
  4. * This script demonstrates how to write a script that is runnable either via
  5. * the CLI, or via a migration. The related migration is `script_example`
  6. * in the migrations directory.
  7. */
  8. const { User } = require('../../app/src/models/User')
  9. // const somePackage = require('some-package')
  10. const runScript = async () => {
  11. const user = await User.findOne({}, { first_name: 1 }).exec()
  12. const name = user ? user.first_name : 'World'
  13. console.log(`Hello ${name}!`)
  14. }
  15. if (!module.parent) {
  16. // we are in the root module, which means that we're running as a script
  17. runScript()
  18. .then(() => process.exit())
  19. .catch(err => {
  20. console.error(err)
  21. process.exit(1)
  22. })
  23. }
  24. module.exports = runScript