Add deploy startup seed guard

This commit is contained in:
2026-07-07 23:11:36 +03:00
parent 8dd43c57ca
commit 1322f5d8cc
3 changed files with 44 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
import { PrismaClient } from "@prisma/client";
import { spawn } from "node:child_process";
const prisma = new PrismaClient();
async function runSeed() {
await new Promise<void>((resolve, reject) => {
const child = spawn("npx", ["tsx", "prisma/seed.ts"], {
stdio: "inherit",
shell: true
});
child.on("exit", (code) => {
if (code === 0) resolve();
else reject(new Error(`Seed failed with exit code ${code}`));
});
});
}
async function main() {
const [plans, users, ads] = await Promise.all([
prisma.plan.count(),
prisma.user.count(),
prisma.ad.count()
]);
if (plans > 0 && users > 0 && ads > 0) {
console.log("✅ Database already seeded. Skipping demo seed.");
return;
}
console.log("🌱 Empty database detected. Running demo seed...");
await runSeed();
}
main()
.catch((error) => {
console.error(error);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});