30 lines
723 B
TypeScript
30 lines
723 B
TypeScript
import 'dotenv/config';
|
|
import { PrismaClient } from '@prisma/client';
|
|
import bcrypt from 'bcryptjs';
|
|
|
|
// Manually read .env if needed, but dotenv/config should handle it
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
const password = await bcrypt.hash('admin123', 10);
|
|
const user = await prisma.user.upsert({
|
|
where: { username: 'admin' },
|
|
update: {},
|
|
create: {
|
|
username: 'admin',
|
|
password,
|
|
},
|
|
});
|
|
console.log('Admin user created:', user);
|
|
}
|
|
|
|
main()
|
|
.then(async () => {
|
|
await prisma.$disconnect();
|
|
})
|
|
.catch(async (e) => {
|
|
console.error(e);
|
|
await prisma.$disconnect();
|
|
process.exit(1);
|
|
});
|