49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
/**
|
|
* Check and create Context table if not exists
|
|
*/
|
|
|
|
const { sequelize } = require('./config/database');
|
|
const { Context } = require('./models');
|
|
|
|
async function checkAndCreateTable() {
|
|
try {
|
|
console.log('🔍 Checking Context table...\n');
|
|
|
|
await sequelize.authenticate();
|
|
console.log('✅ Database connection OK\n');
|
|
|
|
// Check if table exists
|
|
const [results] = await sequelize.query(
|
|
"SHOW TABLES LIKE 'context'"
|
|
);
|
|
|
|
if (results.length === 0) {
|
|
console.log('⚠️ Table "context" does not exist');
|
|
console.log('📊 Creating table...\n');
|
|
|
|
await Context.sync({ force: false });
|
|
|
|
console.log('✅ Table "context" created successfully!');
|
|
} else {
|
|
console.log('✅ Table "context" already exists');
|
|
|
|
// Show table info
|
|
const [tableInfo] = await sequelize.query('DESCRIBE context');
|
|
console.log('\n📋 Table structure:');
|
|
console.log(tableInfo);
|
|
|
|
// Count records
|
|
const count = await Context.count();
|
|
console.log(`\n📊 Current records: ${count}`);
|
|
}
|
|
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('❌ Error:', error.message);
|
|
console.error(error.stack);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
checkAndCreateTable();
|