This repository has been archived on 2026-05-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Nest/nest-backend/prisma/seed.ts

30 lines
885 B
TypeScript

import 'dotenv/config';
import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
const prisma = new PrismaClient();
async function main() {
const username = process.env.ADMIN_USERNAME;
const email = process.env.ADMIN_EMAIL;
const password = process.env.ADMIN_PASSWORD;
if (!username || !email || !password) {
throw new Error('ADMIN_USERNAME, ADMIN_EMAIL and ADMIN_PASSWORD must be set in .env');
}
const hashed = await bcrypt.hash(password, 10);
const user = await prisma.user.upsert({
where: { email },
update: { username, password: hashed, role: 'dev', isAdmin: true },
create: { username, email, password: hashed, role: 'dev', isAdmin: true },
});
console.log(`Admin user ready: ${user.username} <${user.email}>`);
}
main()
.catch((e) => { console.error(e); process.exit(1); })
.finally(() => prisma.$disconnect());