Files
overleaf-cep/services/web/scripts/example/script_for_migration.mjs
Andrew Rumble ae6dec9dcb Merge pull request #29656 from overleaf/revert-29521-ar-models-es-conversion
Revert "[web] Convert models and self-referential test files to ESM "

GitOrigin-RevId: 5455cccbb513bd9ca36ce526ff1553065f83d233
2025-11-13 09:06:36 +00:00

31 lines
787 B
JavaScript

/* subscription.freeTrialExpiresAt
* Example script for a migration:
*
* This script demonstrates how to write a script that is runnable either via
* the CLI, or via a migration. The related migration is `script_example`
* in the migrations directory.
*/
import { User } from '../../app/src/models/User.js'
import { fileURLToPath } from 'node:url'
// const somePackage = require('some-package')
const runScript = async () => {
const user = await User.findOne({}, { first_name: 1 }).exec()
const name = user ? user.first_name : 'World'
console.log(`Hello ${name}!`)
}
if (fileURLToPath(import.meta.url) === process.argv[1]) {
try {
await runScript()
process.exit()
} catch (error) {
console.error(error)
process.exit(1)
}
}
export default runScript