import { getPayload } from "payload"; import config from "@payload-config"; const DEFAULT_USMC_RANKS = [ { name: "Recruit", abbreviation: "Rct", }, { name: "Private", abbreviation: "Pvt", }, { name: "Private First Class", abbreviation: "PFC", }, { name: "Lance Corporal", abbreviation: "LCpl", }, { name: "Corporal", abbreviation: "Cpl", }, { name: "Sergeant", abbreviation: "Sgt", }, { name: "Staff Sergeant", abbreviation: "SSgt", }, { name: "Gunnery Sergeant", abbreviation: "GySgt", }, { name: "Master Sergeant", abbreviation: "MSgt", }, { name: "First Sergeant", abbreviation: "1stSgt", }, { name: "Sergeant Major", abbreviation: "SgtMaj", }, { name: "Master Gunnery Sergeant", abbreviation: "MGySgt", }, { name: "Second Lieutenant", abbreviation: "2ndLt", }, { name: "First Lieutenant", abbreviation: "1stLt", }, { name: "Captain", abbreviation: "Cpt", }, { name: "Major", abbreviation: "Maj", }, { name: "Lieutenant Colonel", abbreviation: "LtCol", }, { name: "Colonel", abbreviation: "Col", }, { name: "Brigadier General", abbreviation: "BGen", }, { name: "Major General", abbreviation: "MajGen", }, { name: "Lieutenant General", abbreviation: "LtGen", }, { name: "General", abbreviation: "Gen", }, ]; export const seedRanks = async () => { const payload = await getPayload({ config }); payload.logger.info("Seeding rank data..."); payload.logger.warn("Deleting all existing ranks..."); await payload.delete({ collection: "ranks", where: { name: { exists: true }, }, }); payload.logger.info(`Creating ${DEFAULT_USMC_RANKS.length} new ranks...`); for (const rank of DEFAULT_USMC_RANKS) { const result = await payload.create({ collection: "ranks", data: { ...rank, description: "A rank that needs a description. ", }, }); payload.logger.info(`Rank '${result.name}' created.`); } }; await seedRanks();