/** * Sync Context model to database with ALTER * This will update the existing table structure */ const { sequelize } = require('./config/database'); const Context = require('./models/Context'); async function syncContext() { try { console.log('šŸ”„ Starting Context table sync with ALTER...'); // Test connection await sequelize.authenticate(); console.log('āœ… Database connection OK'); // Sync Context model with alter to update structure await Context.sync({ alter: true }); console.log('āœ… Context table synced successfully (grade column updated to INTEGER)'); // Show table structure const [columns] = await sequelize.query(` SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'context' AND TABLE_SCHEMA = DATABASE() ORDER BY ORDINAL_POSITION `); console.log('\nšŸ“Š Context table structure:'); columns.forEach((col, index) => { console.log(` ${index + 1}. ${col.COLUMN_NAME} - ${col.COLUMN_TYPE} ${col.IS_NULLABLE === 'NO' ? 'NOT NULL' : 'NULL'}`); if (col.COLUMN_COMMENT) { console.log(` Comment: ${col.COLUMN_COMMENT}`); } }); console.log('\nāœ… Context table update complete!'); process.exit(0); } catch (error) { console.error('āŒ Error syncing Context table:', error.message); console.error(error.stack); process.exit(1); } } syncContext();