40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
const mysql = require('mysql2/promise');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
async function setupDatabase() {
|
|
let connection;
|
|
try {
|
|
// Create connection without database
|
|
connection = await mysql.createConnection({
|
|
host: '127.0.0.1',
|
|
port: 3306,
|
|
user: 'root',
|
|
password: 'semogabisayok321'
|
|
});
|
|
|
|
console.log('Connected to MySQL server');
|
|
|
|
// Read and execute check_table.sql
|
|
const checkTableSql = fs.readFileSync(path.join(__dirname, 'check_table.sql'), 'utf8');
|
|
const statements = checkTableSql.split(';').filter(stmt => stmt.trim());
|
|
|
|
for (const statement of statements) {
|
|
if (statement.trim()) {
|
|
console.log('Executing:', statement.substring(0, 50) + '...');
|
|
await connection.query(statement);
|
|
}
|
|
}
|
|
|
|
console.log('Database setup completed successfully');
|
|
} catch (error) {
|
|
console.error('Error setting up database:', error);
|
|
} finally {
|
|
if (connection) {
|
|
await connection.end();
|
|
console.log('Database connection closed');
|
|
}
|
|
}
|
|
}
|
|
|
|
setupDatabase();
|