This commit is contained in:
Ken
2026-01-19 09:33:35 +07:00
parent 374dc12b2d
commit 70838a4bc1
103 changed files with 16929 additions and 2 deletions

View File

@@ -0,0 +1,58 @@
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 };