Add comprehensive database setup and user management system
- Implement PostgreSQL database schema with users and bookmarks tables - Add database connection pooling with retry logic and error handling - Create migration system with automatic schema initialization - Add database CLI tools for management (init, status, validate, etc.) - Include comprehensive error handling and diagnostics - Add development seed data and testing utilities - Implement health monitoring and connection pool statistics - Create detailed documentation and troubleshooting guide Database features: - Users table with authentication fields and email verification - Bookmarks table with user association and metadata - Proper indexes for performance optimization - Automatic timestamp triggers - Transaction support with rollback handling - Connection pooling (20 max connections, 30s idle timeout) - Graceful shutdown handling CLI commands available: - npm run db:init - Initialize database - npm run db:status - Check database status - npm run db:validate - Validate schema - npm run db:test - Run database tests - npm run db:diagnostics - Full diagnostics
This commit is contained in:
45
backend/server.js
Normal file
45
backend/server.js
Normal file
@ -0,0 +1,45 @@
|
||||
const app = require('./src/app');
|
||||
const dbInitializer = require('./src/database/init');
|
||||
const dbConnection = require('./src/database/connection');
|
||||
|
||||
const PORT = process.env.PORT || 3001;
|
||||
|
||||
// Initialize database and start server
|
||||
async function startServer() {
|
||||
try {
|
||||
console.log('🚀 Starting Bookmark Manager Backend...');
|
||||
|
||||
// Initialize database
|
||||
await dbInitializer.initialize();
|
||||
|
||||
// Start the server
|
||||
const server = app.listen(PORT, () => {
|
||||
console.log(`✅ Server is running on port ${PORT}`);
|
||||
console.log(`🌍 Environment: ${process.env.NODE_ENV || 'development'}`);
|
||||
console.log(`🔗 Health check: http://localhost:${PORT}/health`);
|
||||
});
|
||||
|
||||
// Graceful shutdown handling
|
||||
process.on('SIGTERM', async () => {
|
||||
console.log('🛑 SIGTERM received, shutting down gracefully...');
|
||||
server.close(async () => {
|
||||
await dbConnection.close();
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('🛑 SIGINT received, shutting down gracefully...');
|
||||
server.close(async () => {
|
||||
await dbConnection.close();
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
startServer();
|
||||
Reference in New Issue
Block a user