First commit
This commit is contained in:
40
setup_database.js
Normal file
40
setup_database.js
Normal file
@@ -0,0 +1,40 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user