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

40
sync-database.js Normal file
View File

@@ -0,0 +1,40 @@
/**
* Sync all models to database (create tables)
* Run once to initialize database schema
*/
const { sequelize } = require('./config/database');
const { setupRelationships } = require('./models');
async function syncDatabase() {
try {
console.log('🔄 Starting database synchronization...');
// Test connection first
await sequelize.authenticate();
console.log('✅ Database connection OK');
// Setup relationships
setupRelationships();
console.log('✅ Model relationships configured');
// Sync all models (creates tables if not exist)
await sequelize.sync({ alter: false, force: false });
console.log('✅ All models synced successfully');
// Show created tables
const [tables] = await sequelize.query('SHOW TABLES');
console.log(`\n📊 Total tables: ${tables.length}`);
tables.forEach((table, index) => {
console.log(` ${index + 1}. ${Object.values(table)[0]}`);
});
console.log('\n✅ Database schema initialization complete!');
process.exit(0);
} catch (error) {
console.error('❌ Error syncing database:', error.message);
console.error(error.stack);
process.exit(1);
}
}
syncDatabase();