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');
|
||||
}
|
||||
|
||||
Generated
+3
-6
@@ -202,6 +202,9 @@ importers:
|
||||
'@types/node':
|
||||
specifier: ^22.10.2
|
||||
version: 22.19.15
|
||||
argon2:
|
||||
specifier: ^0.44.0
|
||||
version: 0.44.0
|
||||
prisma:
|
||||
specifier: ^6.1.0
|
||||
version: 6.19.2(typescript@5.9.3)
|
||||
@@ -391,7 +394,6 @@ packages:
|
||||
|
||||
/@epic-web/invariant@1.0.0:
|
||||
resolution: {integrity: sha512-lrTPqgvfFQtR/eY/qkIzp98OGdNJu0m5ji3q/nJI8v3SXkRKEnWiOxMmbvcSoAIzv/cGiuvRy57k4suKQSAdwA==}
|
||||
dev: false
|
||||
|
||||
/@esbuild/aix-ppc64@0.21.5:
|
||||
resolution: {integrity: sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==}
|
||||
@@ -1282,7 +1284,6 @@ packages:
|
||||
/@phc/format@1.0.0:
|
||||
resolution: {integrity: sha512-m7X9U6BG2+J+R1lSOdCiITLLrxm+cWlNI3HUFA92oLO77ObGNzaKdh8pMLqdZcshtkKuV84olNNXDfMc4FezBQ==}
|
||||
engines: {node: '>=10'}
|
||||
dev: false
|
||||
|
||||
/@prisma/client@6.19.2(prisma@6.19.2)(typescript@5.9.3):
|
||||
resolution: {integrity: sha512-gR2EMvfK/aTxsuooaDA32D8v+us/8AAet+C3J1cc04SW35FPdZYgLF+iN4NDLUgAaUGTKdAB0CYenu1TAgGdMg==}
|
||||
@@ -2139,7 +2140,6 @@ packages:
|
||||
cross-env: 10.1.0
|
||||
node-addon-api: 8.6.0
|
||||
node-gyp-build: 4.8.4
|
||||
dev: false
|
||||
|
||||
/argparse@2.0.1:
|
||||
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
|
||||
@@ -2452,7 +2452,6 @@ packages:
|
||||
dependencies:
|
||||
'@epic-web/invariant': 1.0.0
|
||||
cross-spawn: 7.0.6
|
||||
dev: false
|
||||
|
||||
/cross-spawn@7.0.6:
|
||||
resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==}
|
||||
@@ -4054,7 +4053,6 @@ packages:
|
||||
/node-addon-api@8.6.0:
|
||||
resolution: {integrity: sha512-gBVjCaqDlRUk0EwoPNKzIr9KkS9041G/q31IBShPs1Xz6UTA+EXdZADbzqAJQrpDRq71CIMnOP5VMut3SL0z5Q==}
|
||||
engines: {node: ^18 || ^20 || >= 21}
|
||||
dev: false
|
||||
|
||||
/node-exports-info@1.6.0:
|
||||
resolution: {integrity: sha512-pyFS63ptit/P5WqUkt+UUfe+4oevH+bFeIiPPdfb0pFeYEu/1ELnJu5l+5EcTKYL5M7zaAa7S8ddywgXypqKCw==}
|
||||
@@ -4072,7 +4070,6 @@ packages:
|
||||
/node-gyp-build@4.8.4:
|
||||
resolution: {integrity: sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==}
|
||||
hasBin: true
|
||||
dev: false
|
||||
|
||||
/nypm@0.6.5:
|
||||
resolution: {integrity: sha512-K6AJy1GMVyfyMXRVB88700BJqNUkByijGJM8kEHpLdcAt+vSQAVfkWWHYzuRXHSY6xA2sNc5RjTj0p9rE2izVQ==}
|
||||
|
||||
Reference in New Issue
Block a user