script_for_migration.js 724 B

123456789101112131415161718192021222324252627
  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 (require.main === module) {
  16. runScript()
  17. .then(() => process.exit())
  18. .catch(err => {
  19. console.error(err)
  20. process.exit(1)
  21. })
  22. }
  23. module.exports = runScript