-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck-db.js
More file actions
49 lines (41 loc) · 1.34 KB
/
check-db.js
File metadata and controls
49 lines (41 loc) · 1.34 KB
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
41
42
43
44
45
46
47
48
49
const { Pool } = require('pg');
require('dotenv').config({ path: '.env' });
async function checkDatabase() {
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false }
});
try {
console.log('🔌 Connecting to database...');
// Test connection
const client = await pool.connect();
console.log('✅ Database connection successful!');
// Get all tables
const tablesResult = await client.query(`
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name;
`);
console.log('\n📋 Current tables in database:');
tablesResult.rows.forEach(row => {
console.log(` - ${row.table_name}`);
});
// Get table counts
console.log('\n📊 Table record counts:');
for (const table of tablesResult.rows) {
try {
const countResult = await client.query(`SELECT COUNT(*) FROM "${table.table_name}"`);
console.log(` ${table.table_name}: ${countResult.rows[0].count} records`);
} catch (err) {
console.log(` ${table.table_name}: Error getting count - ${err.message}`);
}
}
client.release();
} catch (err) {
console.error('❌ Database connection failed:', err.message);
} finally {
await pool.end();
}
}
checkDatabase();