-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-database.js
More file actions
63 lines (51 loc) · 2.22 KB
/
test-database.js
File metadata and controls
63 lines (51 loc) · 2.22 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { Pool } = require('pg')
const crypto = require('crypto')
async function setupDatabase() {
console.log('🔍 Testing database connection...\n')
const connectionString = process.env.SUPREMESCAN_DB_URL ||
'postgresql://supremescan_user:supremescan_password@localhost:5432/supremescan'
const pool = new Pool({ connectionString })
try {
// Test connection
const timeRes = await pool.query('SELECT NOW()')
console.log('✅ Database connected successfully!')
console.log(` Time: ${timeRes.rows[0].now}\n`)
// Check tables
const tablesRes = await pool.query(`
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name
`)
console.log('📋 Tables found:')
tablesRes.rows.forEach(row => {
console.log(` - ${row.table_name}`)
})
console.log('')
// Check user count
const userCount = await pool.query('SELECT COUNT(*) FROM users')
console.log(`👥 Users in database: ${userCount.rows[0].count}`)
// Check project count
const projectCount = await pool.query('SELECT COUNT(*) FROM projects')
console.log(`📁 Projects in database: ${projectCount.rows[0].count}`)
// Check scan count
const scanCount = await pool.query('SELECT COUNT(*) FROM scans')
console.log(`🔍 Scans in database: ${scanCount.rows[0].count}\n`)
console.log('✅ Database setup verified!')
console.log('\n📝 Don\'t forget to add to .env:')
console.log(` SUPREMESCAN_DB_URL=${connectionString}`)
console.log(` ENCRYPTION_KEY=${crypto.randomBytes(32).toString('hex')}\n`)
} catch (error) {
console.error('❌ Database connection failed!')
console.error(` Error: ${error.message}\n`)
console.log('💡 Make sure:')
console.log(' 1. PostgreSQL is running')
console.log(' 2. Database "supremescan" exists')
console.log(' 3. User "supremescan_user" has access')
console.log(' 4. Migrations have been run\n')
console.log('Run: setup-database.bat (on Windows)\n')
} finally {
await pool.end()
}
}
setupDatabase()