templates2.Base.Next/prisma/seed.ts
w4c-templates 219be916cb
Some checks are pending
CI / quality (push) Waiting to run
chore(template): publish Base.Next
2026-10-11 23:23:30 +03:00

52 lines
1.5 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
const db = new PrismaClient();
async function main() {
const password = await bcrypt.hash('password', 10);
const admin = await db.user.upsert({
where: { email: 'admin@example.com' },
update: { role: 'admin' },
create: { email: 'admin@example.com', name: 'Admin User', role: 'admin', passwordHash: password },
});
const user = await db.user.upsert({
where: { email: 'user@example.com' },
update: {},
create: { email: 'user@example.com', name: 'Demo User', role: 'user', passwordHash: password },
});
await db.subscription.upsert({
where: { userId: admin.id },
update: {},
create: { userId: admin.id, plan: 'pro', status: 'active', provider: 'mock' },
});
await db.subscription.upsert({
where: { userId: user.id },
update: {},
create: { userId: user.id, plan: 'free', status: 'active', provider: 'mock' },
});
if ((await db.auditLog.count()) === 0) {
await db.auditLog.createMany({
data: [
{ actorId: admin.id, action: 'seed', target: 'system', meta: 'Initial demo data' },
{ actorId: admin.id, action: 'user.create', target: user.email, meta: 'Seeded demo user' },
],
});
}
console.log(`Seeded: ${admin.email} (admin), ${user.email} (user) — password: "password"`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await db.$disconnect();
});