feat: seed에 운영자 계정 추가 (admin@admin.com / SUPER_ADMIN)
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.10.2",
|
||||
"argon2": "^0.44.0",
|
||||
"prisma": "^6.1.0",
|
||||
"tsup": "^8.3.5",
|
||||
"tsx": "^4.19.0",
|
||||
|
||||
@@ -2,6 +2,7 @@ import { PrismaClient } from '@prisma/client';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { resolve, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import argon2 from 'argon2';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
@@ -138,11 +139,42 @@ async function seedIndustries(): Promise<void> {
|
||||
console.log(`Seeded ${sorted.length} industries`);
|
||||
}
|
||||
|
||||
async function seedAdminUser(): Promise<void> {
|
||||
const email = 'admin@admin.com';
|
||||
const emailNormalized = email.toLowerCase().trim();
|
||||
|
||||
const existing = await prisma.user.findFirst({
|
||||
where: { emailNormalized },
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
console.log(`Admin user already exists (id: ${existing.id})`);
|
||||
return;
|
||||
}
|
||||
|
||||
const passwordHash = await argon2.hash('admin123');
|
||||
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
email,
|
||||
emailNormalized,
|
||||
name: '운영자',
|
||||
passwordHash,
|
||||
primaryRole: 'SUPER_ADMIN',
|
||||
status: 'ACTIVE',
|
||||
emailVerifiedAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Admin user created (id: ${user.id}, email: ${email})`);
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
console.log('Starting seed...');
|
||||
|
||||
await seedRegions();
|
||||
await seedIndustries();
|
||||
await seedAdminUser();
|
||||
|
||||
console.log('Seed completed successfully');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user