/** * Lightweight production migration runner. * * Uses a minimal inline Payload config — no lexical editor, no plugins, no * collections/globals — to avoid loading heavy modules in a memory-constrained * environment (the full config would OOM a small VPS via SIGKILL). * * Run via: NODE_OPTIONS="--experimental-strip-types --no-require-module" node src/scripts/migrate.ts */ import path from 'path'; import { fileURLToPath } from 'url'; import { buildConfig, getPayload } from 'payload'; import { postgresAdapter } from '@payloadcms/db-postgres'; const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename); // Minimal config: only the DB adapter + explicit migrations path. // No editor, no plugins, no collections/globals needed to run raw SQL migrations. const config = buildConfig({ secret: process.env.PAYLOAD_SECRET || 'migrate-secret', db: postgresAdapter({ pool: { connectionString: process.env.DATABASE_URI }, migrationDir: path.resolve(dirname, '../migrations'), }), collections: [], globals: [], }); const payload = await getPayload({ config }); console.log('[migrator] Running database migrations...'); await payload.db.migrate(); console.log('[migrator] Migrations complete.'); process.exit(0);