script_for_migration.mjs 782 B

123456789101112131415161718192021222324252627282930
  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. import { User } from '../../app/src/models/User.js'
  9. import { fileURLToPath } from 'url'
  10. // const somePackage = require('some-package')
  11. const runScript = async () => {
  12. const user = await User.findOne({}, { first_name: 1 }).exec()
  13. const name = user ? user.first_name : 'World'
  14. console.log(`Hello ${name}!`)
  15. }
  16. if (fileURLToPath(import.meta.url) === process.argv[1]) {
  17. try {
  18. await runScript()
  19. process.exit()
  20. } catch (error) {
  21. console.error(error)
  22. process.exit(1)
  23. }
  24. }
  25. export default runScript