Promise that resolves to true
if all database
tests pass successfully, false
if any connectivity or basic query tests fail.
Note that missing schema (unmigrated database) is treated as a warning, not a failure.
Only throws if there are unexpected runtime errors. Normal
database connectivity failures are caught and returned as false
.
// Programmatic usage in deployment scripts
import { testDatabaseConnection } from '@/shared/database/testConnection';
async function deploymentHealthCheck() {
const isHealthy = await testDatabaseConnection();
if (!isHealthy) {
console.error('Database connection failed - deployment aborted');
process.exit(1);
}
console.log('Database verified - proceeding with deployment');
}
// CLI usage for system administrators
// Run directly: node dist/shared/database/testConnection.js
// Or via npm script: npm run db:test
// Exit code 0 = success, 1 = failure
Tests database connection and verifies schema setup for WayrApp sovereign nodes.
This function performs a comprehensive health check of the database connection, ensuring that community administrators can verify their educational platform's database is properly configured and accessible. It's designed to be used both programmatically and as a CLI diagnostic tool during deployment and maintenance.
The function performs three levels of verification:
This utility is essential for sovereign node deployment workflows, allowing community administrators to validate their database setup without requiring deep database expertise. It provides clear, actionable feedback through structured logging with visual indicators (✅, ⚠️, ❌).
Usage Context:
Error Handling: The function gracefully handles various failure scenarios:
All errors are logged with appropriate severity levels and human-readable messages suitable for community administrators managing their own nodes.