52 lines
1.5 KiB
TypeScript
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();
|
|
});
|