-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-vercel-env.js
More file actions
83 lines (66 loc) · 3.2 KB
/
test-vercel-env.js
File metadata and controls
83 lines (66 loc) · 3.2 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env node
/**
* Test script to verify Vercel environment variables configuration
* This simulates how the application will run in Vercel with the new environment variables
*/
// Simulate Vercel environment variables
process.env.POSTGRES_URL = 'postgresql://[email protected]:6543/postgres?sslmode=require&pgbouncer=true';
process.env.DATABASE_URL = 'postgresql://[email protected]:6543/postgres?sslmode=require&pgbouncer=true';
process.env.VERCEL = '1';
process.env.NODE_ENV = 'production';
const { PrismaClient } = require('@prisma/client');
async function testConfiguration() {
console.log('🚀 Testing Vercel Environment Configuration');
console.log('==========================================');
// Check environment variables
console.log('📋 Environment Variables:');
console.log(` POSTGRES_URL: ${process.env.POSTGRES_URL ? '✅ Configured' : '❌ Missing'}`);
console.log(` DATABASE_URL: ${process.env.DATABASE_URL ? '✅ Configured' : '❌ Missing'}`);
console.log(` VERCEL: ${process.env.VERCEL ? '✅ Yes' : '❌ No'}`);
console.log(` NODE_ENV: ${process.env.NODE_ENV}`);
// Test Prisma configuration
console.log('\n🔍 Testing Prisma Configuration:');
try {
const prisma = new PrismaClient({
log: ['query', 'info', 'warn', 'error'],
});
console.log('⏳ Testing database connection...');
await prisma.$queryRaw`SELECT 1`;
console.log('✅ Database connection successful!');
// Test environment validation
console.log('\n🔍 Testing Environment Validation:');
const { validateEnv } = require('./src/lib/env');
const isValid = validateEnv();
console.log(`Environment validation: ${isValid ? '✅ Passed' : '❌ Failed'}`);
// Test tables
console.log('\n🔍 Testing Database Tables:');
const tables = ['telegram_users', 'bot_configurations', 'obs_connections', 'scenes', 'sources', 'command_histories', 'stream_sessions'];
for (const table of tables) {
try {
const result = await prisma.$queryRawUnsafe(`SELECT COUNT(*) as count FROM ${table}`);
console.log(` ✅ ${table}: OK (${result[0].count} records)`);
} catch (error) {
console.log(` ⚠️ ${table}: Table may not exist yet (${error.message})`);
}
}
await prisma.$disconnect();
console.log('\n📊 Test Results:');
console.log('================');
console.log('✅ Configuration test completed successfully!');
console.log('📝 Your application should work in Vercel with the current environment variables.');
return true;
} catch (error) {
console.error('❌ Configuration test failed:', error.message);
console.log('\n🔧 Troubleshooting:');
console.log('1. Check if POSTGRES_URL is correctly set in Vercel');
console.log('2. Verify your Supabase project is accessible');
console.log('3. Ensure the database password is correct');
return false;
}
}
// Handle errors
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
process.exit(1);
});
testConfiguration().catch(console.error);