시드 생성

This commit is contained in:
2025-04-24 12:01:51 +09:00
parent beac42d60c
commit 7fa99e6988
42 changed files with 938 additions and 1170 deletions
-27
View File
@@ -1,27 +0,0 @@
'use strict';
const bcrypt = require('bcrypt');
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up (queryInterface, Sequelize) {
// 관리자 계정 비밀번호 해시 생성
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash('Dlrwns0304#', salt);
// 관리자 계정 생성
await queryInterface.bulkInsert('users', [{
name: '관리자',
email: 'master@jaybe.dev',
password: hashedPassword,
role: 'admin',
status: 'active',
createdAt: new Date(),
updatedAt: new Date()
}], {});
},
async down (queryInterface, Sequelize) {
// 관리자 계정 삭제
await queryInterface.bulkDelete('users', { email: 'master@jaybe.dev' }, {});
}
};
@@ -0,0 +1,45 @@
'use strict';
const bcrypt = require('bcrypt');
module.exports = {
async up (queryInterface, Sequelize) {
// 환경변수 기반으로 관리자 계정 생성
const adminEmail = process.env.ADMIN_EMAIL;
const adminPassword = process.env.ADMIN_PASSWORD;
const adminName = process.env.ADMIN_NAME;
const adminUsername = process.env.ADMIN_USERNAME;
// 이미 존재하는지 체크
const [results] = await queryInterface.sequelize.query(
`SELECT id FROM Users WHERE email = :email LIMIT 1`,
{ replacements: { email: adminEmail } }
);
if (results.length > 0) return;
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash(adminPassword, salt);
await queryInterface.bulkInsert('Users', [{
username: adminUsername,
name: adminName,
email: adminEmail,
password: hashedPassword,
role: 'admin',
status: 'active',
createdAt: new Date(),
updatedAt: new Date()
}], {});
},
async down (queryInterface, Sequelize) {
const adminEmail = process.env.ADMIN_EMAIL;
// 먼저 ActivityLogs에서 admin 유저의 로그를 삭제
const [results] = await queryInterface.sequelize.query(
`SELECT id FROM Users WHERE email = :email LIMIT 1`,
{ replacements: { email: adminEmail } }
);
if (results.length > 0) {
const adminId = results[0].id;
await queryInterface.bulkDelete('ActivityLogs', { userId: adminId }, {});
}
await queryInterface.bulkDelete('Users', { email: adminEmail }, {});
}
};
+49
View File
@@ -0,0 +1,49 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.bulkInsert('Features', [
{
code: 'member_management',
name: '회원 관리',
description: '클럽 회원 관리 기능',
price: 0,
createdAt: new Date(),
updatedAt: new Date()
},
{
code: 'event_management',
name: '이벤트 관리',
description: '클럽 이벤트 관리 기능',
price: 0,
createdAt: new Date(),
updatedAt: new Date()
},
{
code: 'event_calendar',
name: '이벤트 캘린더',
description: '클럽 이벤트 캘린더 기능',
price: 1000,
createdAt: new Date(),
updatedAt: new Date()
},
{
code: 'statistics',
name: '통계',
description: '클럽 통계 기능',
price: 1000,
createdAt: new Date(),
updatedAt: new Date()
},
{
code: 'team_create',
name: '팀 생성',
description: '이벤트별 팀 생성 기능',
price: 1000,
createdAt: new Date(),
updatedAt: new Date()
}
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('Features', null, {});
}
};
@@ -0,0 +1,36 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.bulkInsert('SubscriptionPlan', [
{
name: 'Basic',
description: '기본적인 클럽 관리 기능을 제공합니다.',
price: 10000,
maxMembers: 10,
status: 'active',
createdAt: new Date(),
updatedAt: new Date()
},
{
name: 'Premium',
description: '고급 분석 기능과 함께 더 많은 회원을 관리할 수 있습니다.',
price: 25000,
maxMembers: 30,
status: 'active',
createdAt: new Date(),
updatedAt: new Date()
},
{
name: 'Enterprise',
description: '무제한 회원 관리와 모든 프리미엄 기능을 제공합니다.',
price: 50000,
maxMembers: 0,
status: 'active',
createdAt: new Date(),
updatedAt: new Date()
}
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('SubscriptionPlan', null, {});
}
};
@@ -0,0 +1,23 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
// 플랜별로 3개의 기능을 연결 (플랜 1: 기능 1,2,3 / 플랜 2: 기능 2,3,4 / 플랜 3: 기능 1,3,4)
const planFeatures = [
{ planId: 1, featureId: 1, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 1, featureId: 2, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 2, featureId: 1, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 2, featureId: 2, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 2, featureId: 3, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 2, featureId: 4, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 2, featureId: 5, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 3, featureId: 1, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 3, featureId: 2, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 3, featureId: 3, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 3, featureId: 4, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) },
{ planId: 3, featureId: 5, status: 'active', createdAt: new Date(2025, 0, 1), updatedAt: new Date(2025, 0, 1) }
];
await queryInterface.bulkInsert('SubscriptionPlanFeatures', planFeatures, {});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('SubscriptionPlanFeatures', null, {});
}
};
@@ -0,0 +1,26 @@
const bcrypt = require('bcrypt');
module.exports = {
up: async (queryInterface, Sequelize) => {
// 샘플 사용자 10명 생성
const users = [];
for (let i = 1; i <= 10; i++) {
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash('1234', salt);
users.push({
username: `user${i}`,
name: `샘플유저${i}`,
email: `user${i}@test.com`,
password: hashedPassword,
role: 'user',
status: 'active',
createdAt: new Date(),
updatedAt: new Date()
});
}
await queryInterface.bulkInsert('Users', users, {});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('Users', { email: { [Sequelize.Op.like]: 'user%@test.com' } }, {});
}
};
@@ -0,0 +1,22 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
// 샘플 클럽 5개 생성 (ownerId는 1~5)
const clubs = [];
for (let i = 1; i <= 5; i++) {
clubs.push({
name: `샘플 볼링 클럽 ${i}`,
description: `샘플 볼링 클럽 ${i} 설명입니다.`,
location: `도시${i}${i}`,
ownerId: i+1,
status: 'active',
memberCount: 10,
createdAt: new Date(),
updatedAt: new Date()
});
}
await queryInterface.bulkInsert('Clubs', clubs, {});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('Clubs', { name: { [Sequelize.Op.like]: '샘플 볼링 클럽 %' } }, {});
}
};
@@ -0,0 +1,24 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
// 각 클럽 5개에 대해 2개의 구독(플랜 1, 2)을 연결
const clubSubscriptions = [];
for (let clubId = 1; clubId <= 5; clubId++) {
const planId = Math.floor(Math.random() * 2) + 1; // 랜덤으로 플랜 1, 2 중 하나 선택
const startDate = new Date(2025, 3, 1 + clubId);
const endDate = new Date(startDate.getFullYear(), startDate.getMonth()+1, startDate.getDate());
clubSubscriptions.push({
clubId,
planId,
startDate,
endDate,
status: 'active',
createdAt: new Date(),
updatedAt: new Date()
});
}
await queryInterface.bulkInsert('ClubSubscriptions', clubSubscriptions, {});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('ClubSubscriptions', { }, {});
}
};
@@ -0,0 +1,31 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
// 각 클럽마다 3개의 이벤트 생성
const events = [];
for (let clubId = 1; clubId <= 5; clubId++) {
for (let i = 1; i <= 3; i++) {
events.push({
clubId,
title: `클럽${clubId} 이벤트${i}`,
description: `클럽${clubId}의 이벤트${i} 설명입니다.`,
eventType: '정기전', // ENUM 값 중 하나
startDate: new Date(2025, 3, 10 + i, 19, 0, 0),
endDate: new Date(2025, 3, 10 + i, 22, 0, 0),
location: `클럽${clubId} 이벤트장소${i}`,
gameCount: 3,
participantFee: 10000,
maxParticipants: 30,
registrationDeadline: new Date(2025, 3, 9 + i, 23, 59, 59),
participantCount: 0,
status: '활성', // ENUM 값 중 하나
createdAt: new Date(),
updatedAt: new Date()
});
}
}
await queryInterface.bulkInsert('Events', events, {});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('Events', { title: { [Sequelize.Op.like]: '클럽% 이벤트%' } }, {});
}
};
@@ -0,0 +1,27 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
// 샘플 멤버 30명 생성 (각 클럽마다 6명씩)
const members = [];
let userId = 2;
for (let clubId = 1; clubId <= 5; clubId++) {
for (let i = 1; i <= 6; i++) {
members.push({
clubId,
userId: userId <= 10 ? userId : null,
name: `클럽${clubId}멤버${i}`,
gender: i % 2 === 0 ? '여성' : '남성',
memberType: i === 1 ? '모임장' : (i % 2 === 0 ? '정회원' : '준회원'),
status: 'active',
joinDate: new Date(),
createdAt: new Date(),
updatedAt: new Date()
});
userId++;
}
}
await queryInterface.bulkInsert('Members', members, {});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('Members', { name: { [Sequelize.Op.like]: '클럽%멤버%' } }, {});
}
};
+95
View File
@@ -0,0 +1,95 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
// 1. 부모 메뉴 생성
await queryInterface.bulkInsert('Menus', [{
title: '클럽 관리',
icon: 'pi pi-building',
to: '/club',
role: 'user',
order: 1,
visible: true,
parentId: null,
createdAt: new Date(),
updatedAt: new Date()
}]);
// 2. 부모 메뉴 id select
const [results] = await queryInterface.sequelize.query(
"SELECT id FROM Menus WHERE title='클럽 관리' AND `to`='/club' ORDER BY id DESC LIMIT 1"
);
const clubMenuId = results[0].id;
// 3. 자식 메뉴들 생성
await queryInterface.bulkInsert('Menus', [
{
title: '대시보드',
icon: 'pi pi-home',
to: '/club',
role: 'user',
order: 1,
visible: true,
parentId: clubMenuId,
createdAt: new Date(),
updatedAt: new Date()
},
{
title: '회원 관리',
icon: 'pi pi-users',
to: '/club/members',
role: 'user',
order: 2,
visible: true,
parentId: clubMenuId,
featureCode: 'member_management',
requiredSubscriptionTier: 'basic',
createdAt: new Date(),
updatedAt: new Date()
},
{
title: '이벤트 관리',
icon: 'pi pi-calendar',
to: '/club/events',
role: 'user',
order: 3,
visible: true,
parentId: clubMenuId,
featureCode: 'event_management',
requiredSubscriptionTier: 'standard',
createdAt: new Date(),
updatedAt: new Date()
},
{
title: '이벤트 캘린더',
icon: 'pi pi-calendar-plus',
to: '/club/events/calendar',
role: 'user',
order: 4,
visible: true,
parentId: clubMenuId,
featureCode: 'event_calendar',
requiredSubscriptionTier: 'standard',
createdAt: new Date(),
updatedAt: new Date()
},
{
title: '통계',
icon: 'pi pi-chart-line',
to: '/club/statistics',
role: 'user',
order: 5,
visible: true,
parentId: clubMenuId,
featureCode: 'statistics',
requiredSubscriptionTier: 'premium',
createdAt: new Date(),
updatedAt: new Date()
}
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('Menus', null, {});
}
};