-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_db.mjs
More file actions
40 lines (35 loc) · 952 Bytes
/
check_db.mjs
File metadata and controls
40 lines (35 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import mysql from 'mysql2/promise';
const url = process.env.DATABASE_URL;
if (!url) {
console.log('DATABASE_URL not set');
process.exit(1);
}
const match = url.match(/mysql:\/\/([^:]+):([^@]+)@([^:]+):(\d+)\/(.+)/);
if (!match) {
console.log('Invalid DATABASE_URL format');
process.exit(1);
}
const config = {
host: match[3],
user: match[1],
password: match[2],
database: match[5],
port: parseInt(match[4]),
ssl: 'Amazon RDS',
};
(async () => {
try {
const connection = await mysql.createConnection(config);
const [tables] = await connection.execute('SHOW TABLES');
console.log('✓ Database Connected Successfully');
console.log('\nExisting Tables:');
tables.forEach(row => {
const tableName = Object.values(row)[0];
console.log(' -', tableName);
});
await connection.end();
} catch (error) {
console.error('✗ Database Error:', error.message);
process.exit(1);
}
})();