feat: seed에 운영자 계정 추가 (admin@admin.com / SUPER_ADMIN)

This commit is contained in:
Johngreen
2026-03-09 00:18:35 +09:00
parent 7794a3dd8c
commit 7ce2bd23f8
3 changed files with 36 additions and 6 deletions
+1
View File
@@ -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",
+32
View File
@@ -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');
}