Skip to content

Payload Scripts

This page explains the scripts available in frontend/payload/src/scripts, what each one does, and how to run it. A package command such as pnpm seed:master starts the full entry-point script configured for that command. Helper files such as seedMaster.ts are called by other scripts and are not separate commands.

Run commands from the Payload project directory:

Terminal window
cd frontend/payload

Install dependencies if this is a fresh checkout, then start the Payload service in a separate terminal when running scripts that call the HTTP API:

Terminal window
pnpm install
pnpm dev

Most seed and alert scripts read these variables from the local .env file:

VariablePurpose
TARGET_API_URLPayload API base URL. Defaults to http://localhost:3000/api. Check this value before running a script so it does not target a shared or production environment by mistake.
SEED_ADMIN_EMAILAdmin account used by seed and alert scripts to sign in.
SEED_ADMIN_PASSWORDPassword for that admin account.
ALERT_TEST_USER_EMAILOptional target user for the saved-search alert test. It can instead be passed as a command-line argument.

The repository’s .env.example does not currently list the seed-specific variables. Add them to your local .env as needed; never put real credentials in documentation or commit them. Seed scripts generally create records rather than replacing existing data, so repeated runs can add duplicate listings or media.

Run these package commands from frontend/payload:

CommandWhat it runsNotes
pnpm seed:mastersrc/scripts/seed-master.tsAdds default locations, amenities, property types, and listing categories. It checks for existing names before creating most records. Requires a working API and admin credentials.
pnpm seed:providingsrc/scripts/seed.tsCreates a sample providing hierarchy: homes, rooms, and beds. Requires master data and images in src/scripts/assets/homes, rooms, and beds. Run pnpm seed:master first if master data is missing.
pnpm seed:seekingsrc/scripts/seed-seeking.tsCreates 10 random seeking listings. Requires master locations and listing categories.
pnpm seed:nidsrc/scripts/seed-nid.tsDownloads sample images and attempts to create three NID test accounts and verification records. Requires outbound access to picsum.photos, a working API, and admin credentials. The current image-collection and existing-user ID issues described below can cause the NID seed to fail; treat it as unverified.
pnpm test:alert [email protected]src/scripts/test-saved-search-alert.tsCreates a saved search for the target account and a matching home listing, then exercises the notification/email hook. Requires admin credentials, a target user, master data, and working email configuration or development email logging. It also uploads sample images and leaves the created test records in the database.

For the alert test, the target email can also be set with ALERT_TEST_USER_EMAIL and the command run as pnpm test:alert. See the Saved Searches documentation for more detail about the alert flow.

The combined entry point runs master data, providing listings, seeking listings, and NID verification seed data in sequence. It does not have a package.json alias, so run it directly with tsx:

Terminal window
pnpm exec tsx src/scripts/seed-all.ts

This command requires the same API and admin credentials as the individual seed scripts. It also requires local image folders under src/scripts/assets for homes, rooms, beds, and NID samples. The helper modules seedMaster.ts, seedProviding.ts, seedSeeking.ts, and seedNID.ts are invoked by this combined entry point; they are not configured as individual pnpm commands.

The NID seeding code currently needs attention before relying on it: both the standalone seed-nid.ts and the combined seed’s seedNID.ts upload through the general media collection, while NID verification records expect image relationships from nid-media. The standalone script also reads an existing user’s ID from the wrong shape of the docs array. Treat NID seeding as unverified until those mismatches are fixed; use test-only data and check the output and Admin records.

These scripts do not have package aliases. Run them directly from frontend/payload:

Terminal window
pnpm exec tsx src/scripts/cleanupOtps.ts
pnpm exec tsx src/scripts/clean.ts
ScriptWhat it doesImportant caution
cleanupOtps.tsUses the local Payload configuration to clear expired otp_code and otp_expiration values from user records.This is a one-off cleanup, not a scheduled job. Run it with the correct database environment configured. Expired OTPs are rejected by the OTP flow even before cleanup runs.
clean.tsLogs in with the seed admin credentials and deletes records from bed, room, home, and seeking listings, NID verifications, and general media.Destructive. TARGET_API_URL defaults to local development; confirm it before running. It does not clean every collection and does not delete nid-media. The script only fetches up to 500 records per collection.

Do not run clean.ts against shared, staging, or production data unless the team has explicitly approved the cleanup and confirmed the target.

The Payload package also defines these test commands:

CommandWhat it runs
pnpm test:intVitest integration tests.
pnpm test:e2ePlaywright end-to-end tests.
pnpm testRuns integration tests, then end-to-end tests.

These are test suites rather than data-seeding scripts. Their environment requirements are defined by the Payload test configuration.

FileRole
src/scripts/seed-master.tsStandalone master-data seeder; package alias seed:master.
src/scripts/seed.tsProviding-listing seeder; package alias seed:providing.
src/scripts/seed-seeking.tsSeeking-listing seeder; package alias seed:seeking.
src/scripts/seed-nid.tsStandalone NID seeder; package alias seed:nid.
src/scripts/seed-all.tsCombined seed entry point; run using pnpm exec tsx.
src/scripts/seedMaster.ts, seedProviding.ts, seedSeeking.ts, seedNID.tsHelper modules used by seed-all.ts.
src/scripts/test-saved-search-alert.tsSaved-search notification test; package alias test:alert.
src/scripts/cleanupOtps.ts, clean.tsOne-off cleanup scripts; run using pnpm exec tsx.