80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
const { sequelize } = require('../config/database');
|
|
const School = require('../models/School');
|
|
|
|
/**
|
|
* Script thêm trung tâm SenaAI vào database
|
|
* Chạy: node src/scripts/add-senaai-center.js
|
|
*/
|
|
|
|
async function addSenaAICenter() {
|
|
try {
|
|
console.log('🚀 Đang thêm trung tâm SenaAI...\n');
|
|
|
|
// Kết nối database
|
|
await sequelize.authenticate();
|
|
console.log('✅ Kết nối database thành công\n');
|
|
|
|
// Kiểm tra trung tâm đã tồn tại chưa
|
|
const existingCenter = await School.findOne({
|
|
where: { school_code: 'SENAAI' }
|
|
});
|
|
|
|
if (existingCenter) {
|
|
console.log('⚠️ Trung tâm SenaAI đã tồn tại!');
|
|
console.log(` Tên: ${existingCenter.school_name}`);
|
|
console.log(` Mã: ${existingCenter.school_code}`);
|
|
console.log(` Địa chỉ: ${existingCenter.address || 'N/A'}`);
|
|
console.log('\n');
|
|
} else {
|
|
// Tạo mới trung tâm SenaAI
|
|
const senaAI = await School.create({
|
|
school_code: 'SENAAI',
|
|
school_name: 'Trung tâm Giáo dục SenaAI',
|
|
school_type: 'primary',
|
|
address: 'Thành phố Hồ Chí Minh',
|
|
city: 'Thành phố Hồ Chí Minh',
|
|
district: 'Đang cập nhật',
|
|
phone: '',
|
|
config: {
|
|
type: 'education_center',
|
|
services: ['AI Education', 'Technology Training', 'School Management']
|
|
},
|
|
is_active: true,
|
|
});
|
|
|
|
console.log('✅ Đã tạo trung tâm SenaAI thành công!');
|
|
console.log(` ID: ${senaAI.id}`);
|
|
console.log(` Tên: ${senaAI.school_name}`);
|
|
console.log(` Mã: ${senaAI.school_code}`);
|
|
console.log('\n');
|
|
}
|
|
|
|
// Hiển thị tổng số trường
|
|
const totalSchools = await School.count();
|
|
console.log(`📊 Tổng số trường trong hệ thống: ${totalSchools}`);
|
|
console.log('\n✅ Hoàn thành!\n');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Lỗi:', error);
|
|
throw error;
|
|
} finally {
|
|
await sequelize.close();
|
|
console.log('🔌 Đã đóng kết nối database');
|
|
}
|
|
}
|
|
|
|
// Chạy script
|
|
if (require.main === module) {
|
|
addSenaAICenter()
|
|
.then(() => {
|
|
console.log('\n🎉 Script hoàn thành thành công!');
|
|
process.exit(0);
|
|
})
|
|
.catch((error) => {
|
|
console.error('\n💥 Script thất bại:', error);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
module.exports = { addSenaAICenter };
|