Files
amayo/scripts/cleanInvalidMobs.ts
Shni 852b1d02a2 feat: Add scripts for mob dependency management and server setup
- Implemented `findMobDependencies.ts` to identify foreign key constraints referencing the Mob table and log dependent rows.
- Created `fullServerSetup.ts` for idempotent server setup, including economy items, item recipes, game areas, mobs, and optional demo mob attacks.
- Developed `removeInvalidMobsWithDeps.ts` to delete invalid mobs and their dependencies, backing up affected scheduled mob attacks.
- Added unit tests in `testMobUnit.ts` and `mob.test.ts` for mob functionality, including stats computation and instance retrieval.
- Introduced reward modification tests in `testRewardMods.ts` and `rewardMods.unit.ts` to validate drop selection and coin multiplier behavior.
- Enhanced command handling for mob deletion in `mobDelete.ts` and setup examples in `setup.ts`, ensuring proper permissions and feedback.
- Created utility functions in `testHelpers.ts` for deterministic drop selection from mob definitions.
2025-10-14 14:58:38 -05:00

55 lines
1.4 KiB
TypeScript

import { prisma } from "../src/core/database/prisma";
import { BaseMobDefinitionSchema } from "../src/game/mobs/mobData";
async function run() {
if (!process.env.XATA_DB) {
console.error("XATA_DB not set — aborting");
process.exit(1);
}
console.log("Scanning mobs table for invalid definitions...");
const rows: any[] = await (prisma as any).mob.findMany();
const invalid: any[] = [];
for (const r of rows) {
const cfg =
r.metadata ??
r.stats ??
r.drops ??
r.config ??
r.definition ??
r.data ??
null;
try {
BaseMobDefinitionSchema.parse(cfg as any);
} catch (e) {
invalid.push({ id: r.id, error: (e as any)?.errors ?? e, row: r });
}
}
if (invalid.length === 0) {
console.log("No invalid mob definitions found.");
process.exit(0);
}
console.log(
`Found ${invalid.length} invalid rows. Backing up and deleting...`
);
// backup
console.log("Backup file: invalid_mobs_backup.json");
require("fs").writeFileSync(
"invalid_mobs_backup.json",
JSON.stringify(invalid, null, 2)
);
for (const it of invalid) {
try {
await (prisma as any).mob.delete({ where: { id: it.id } });
console.log("Deleted invalid mob id=", it.id);
} catch (e) {
console.warn("Failed to delete id=", it.id, e);
}
}
console.log("Cleanup complete. Review invalid_mobs_backup.json");
}
run().catch((e) => {
console.error(e);
process.exit(1);
});