init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
require('dotenv').config();
|
||||
const { User, syncModels, testConnection } = require('../src/models');
|
||||
|
||||
async function createSuperAdmin() {
|
||||
try {
|
||||
// 데이터베이스 연결 테스트
|
||||
console.log('데이터베이스 연결 테스트 중...');
|
||||
await testConnection();
|
||||
|
||||
// 모델 동기화 (필요한 경우)
|
||||
// console.log('데이터베이스 모델 동기화 중...');
|
||||
// await syncModels();
|
||||
|
||||
// 기존 superadmin 계정 확인
|
||||
const existingAdmin = await User.findOne({
|
||||
where: { email: process.env.ADMIN_EMAIL }
|
||||
});
|
||||
|
||||
if (existingAdmin) {
|
||||
console.log('이미 superadmin 계정이 존재합니다:', existingAdmin.email);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// superadmin 계정 생성
|
||||
const superAdmin = await User.create({
|
||||
username: 'master',
|
||||
password: process.env.ADMIN_PASSWORD,
|
||||
name: '최고관리자',
|
||||
email: process.env.ADMIN_EMAIL,
|
||||
role: 'superadmin',
|
||||
active: true
|
||||
});
|
||||
|
||||
console.log('superadmin 계정이 성공적으로 생성되었습니다:');
|
||||
console.log('- 이메일:', superAdmin.email);
|
||||
console.log('- 역할:', superAdmin.role);
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error('superadmin 계정 생성 중 오류 발생:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 스크립트 실행
|
||||
createSuperAdmin();
|
||||
Reference in New Issue
Block a user