const { sequelize } = require('../config/database'); const UsersAuth = require('../models/UsersAuth'); const UserProfile = require('../models/UserProfile'); const TeacherDetail = require('../models/TeacherDetail'); /** * Script tạo các bảng user cần thiết trong database * Chạy: node src/scripts/sync-user-tables.js */ async function syncUserTables() { try { console.log('🚀 Đang tạo các bảng user trong database...\n'); // Kết nối database await sequelize.authenticate(); console.log('✅ Kết nối database thành công\n'); // Sync các bảng theo thứ tự phụ thuộc console.log('📋 Đang tạo bảng users_auth...'); await UsersAuth.sync({ alter: true }); console.log('✅ Đã tạo bảng users_auth\n'); console.log('📋 Đang tạo bảng user_profiles...'); await UserProfile.sync({ alter: true }); console.log('✅ Đã tạo bảng user_profiles\n'); console.log('📋 Đang tạo bảng teacher_details...'); await TeacherDetail.sync({ alter: true }); console.log('✅ Đã tạo bảng teacher_details\n'); console.log('='.repeat(60)); console.log('✅ Đã tạo tất cả các bảng thành công!'); console.log('='.repeat(60)); } catch (error) { console.error('❌ Lỗi:', error); throw error; } finally { await sequelize.close(); console.log('\n🔌 Đã đóng kết nối database'); } } // Chạy script if (require.main === module) { syncUserTables() .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 = { syncUserTables };