37 lines
958 B
JavaScript
37 lines
958 B
JavaScript
import mysql from 'mysql2/promise';
|
|
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
|
|
|
const { DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT } = process.env;
|
|
|
|
async function probeDB() {
|
|
const connection = await mysql.createConnection({
|
|
host: DB_HOST,
|
|
user: DB_USER,
|
|
password: DB_PASS,
|
|
database: DB_NAME,
|
|
port: parseInt(DB_PORT || '3306')
|
|
});
|
|
|
|
console.log('--- Database Probe Start ---');
|
|
|
|
const [tables] = await connection.query('SHOW TABLES');
|
|
const tableNames = tables.map(t => Object.values(t)[0]);
|
|
|
|
console.log('Existing Tables:', tableNames);
|
|
|
|
for (const table of tableNames) {
|
|
const [columns] = await connection.query(`DESCRIBE ${table}`);
|
|
console.log(`\n[Table: ${table}]`);
|
|
columns.forEach(c => {
|
|
console.log(` - ${c.Field} (${c.Type}) ${c.Comment ? '// ' + c.Comment : ''}`);
|
|
});
|
|
}
|
|
|
|
await connection.end();
|
|
console.log('\n--- Database Probe End ---');
|
|
}
|
|
|
|
probeDB().catch(console.error);
|