@vezlo/assistant-server 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,10 +74,11 @@ async function validateDatabase() {
74
74
  // Test database connection and validate tables
75
75
  log('Validating database tables...', 'yellow');
76
76
 
77
+ let client;
77
78
  try {
78
79
  const { Client } = require('pg');
79
80
 
80
- const client = new Client({
81
+ client = new Client({
81
82
  host: process.env.SUPABASE_DB_HOST,
82
83
  port: parseInt(process.env.SUPABASE_DB_PORT || '5432'),
83
84
  database: process.env.SUPABASE_DB_NAME || 'postgres',
@@ -86,14 +87,19 @@ async function validateDatabase() {
86
87
  ssl: { rejectUnauthorized: false }
87
88
  });
88
89
 
90
+ // Handle connection errors
91
+ client.on('error', (err) => {
92
+ console.error('Database connection error:', err.message);
93
+ });
94
+
89
95
  await client.connect();
90
96
 
91
97
  // Check required tables
92
98
  const requiredTables = [
93
- 'conversations',
94
- 'messages',
95
- 'message_feedback',
96
- 'knowledge_items'
99
+ 'vezlo_conversations',
100
+ 'vezlo_messages',
101
+ 'vezlo_message_feedback',
102
+ 'vezlo_knowledge_items'
97
103
  ];
98
104
 
99
105
  const result = await client.query(`
@@ -111,7 +117,9 @@ async function validateDatabase() {
111
117
  log(`\n❌ Missing required tables:`, 'red');
112
118
  missingTables.forEach(table => log(` - ${table}`, 'red'));
113
119
  log('\nRun the setup wizard: ' + colors.bright + 'npx vezlo-setup' + colors.reset + '\n', 'yellow');
114
- await client.end();
120
+ if (client) {
121
+ await client.end();
122
+ }
115
123
  process.exit(1);
116
124
  }
117
125
 
@@ -156,10 +164,19 @@ async function validateDatabase() {
156
164
  log('Your server is ready to start:', 'cyan');
157
165
  log(' ' + colors.bright + 'vezlo-server' + colors.reset + '\n');
158
166
 
159
- await client.end();
167
+ if (client) {
168
+ await client.end();
169
+ }
160
170
 
161
171
  } catch (error) {
162
172
  log(`\n❌ Database validation failed: ${error.message}\n`, 'red');
173
+ if (client) {
174
+ try {
175
+ await client.end();
176
+ } catch (closeError) {
177
+ // Ignore close errors
178
+ }
179
+ }
163
180
  process.exit(1);
164
181
  }
165
182
  }