UNPKG

@vasoyaprince14/sql-analyzer

Version:

🚀 Enhanced SQL database analyzer with AI-powered insights, comprehensive security analysis, RLS policy auditing, and beautiful HTML reports

175 lines • 4.76 kB
import { Client } from 'pg'; export interface DatabaseHealthReport { databaseInfo: DatabaseInfo; schemaHealth: SchemaHealthScore; indexAnalysis: IndexAnalysis; performanceIssues: PerformanceIssue[]; securityIssues: SecurityIssue[]; optimizationRecommendations: OptimizationRecommendation[]; costAnalysis: DatabaseCostAnalysis; maintenanceRecommendations: MaintenanceRecommendation[]; } export interface DatabaseInfo { version: string; size: string; tableCount: number; indexCount: number; connectionInfo: { maxConnections: number; activeConnections: number; }; settings: DatabaseSettings; } export interface DatabaseSettings { sharedBuffers: string; effectiveCacheSize: string; workMem: string; maintenanceWorkMem: string; checkpointCompletionTarget: number; walBuffers: string; randomPageCost: number; } export interface SchemaHealthScore { overall: number; normalization: number; indexEfficiency: number; foreignKeyIntegrity: number; dataTypes: number; naming: number; issues: SchemaIssue[]; } export interface SchemaIssue { type: 'missing_pk' | 'missing_fk_index' | 'redundant_index' | 'poor_naming' | 'data_type_inefficiency'; table: string; column?: string; severity: 'low' | 'medium' | 'high' | 'critical'; description: string; suggestion: string; sqlFix?: string; } export interface IndexAnalysis { totalIndexes: number; unusedIndexes: UnusedIndex[]; missingIndexes: MissingIndex[]; duplicateIndexes: DuplicateIndex[]; oversizedIndexes: OversizedIndex[]; indexEfficiencyScore: number; } export interface UnusedIndex { name: string; table: string; size: string; lastUsed: string | null; impact: 'low' | 'medium' | 'high'; } export interface MissingIndex { table: string; columns: string[]; reason: string; estimatedImpact: 'low' | 'medium' | 'high'; suggestedSql: string; } export interface DuplicateIndex { indexes: string[]; table: string; columns: string[]; wastedSpace: string; } export interface OversizedIndex { name: string; table: string; size: string; suggestion: string; } export interface PerformanceIssue { type: 'slow_query' | 'table_bloat' | 'lock_contention' | 'poor_statistics'; severity: 'low' | 'medium' | 'high' | 'critical'; description: string; impact: string; solution: string; sqlFix?: string; } export interface SecurityIssue { type: 'weak_permissions' | 'unencrypted_data' | 'default_passwords' | 'excessive_privileges'; severity: 'low' | 'medium' | 'high' | 'critical'; description: string; recommendation: string; } export interface OptimizationRecommendation { category: 'performance' | 'storage' | 'maintenance' | 'security'; priority: 'low' | 'medium' | 'high' | 'critical'; title: string; description: string; estimatedImpact: string; implementation: string; sqlCommands?: string[]; } export interface DatabaseCostAnalysis { storageUsage: { totalSize: string; dataSize: string; indexSize: string; wastedSpace: string; }; estimatedCosts: { storage: number; compute: number; maintenance: number; }; optimizationSavings: { storage: number; performance: number; }; } export interface MaintenanceRecommendation { task: string; frequency: 'daily' | 'weekly' | 'monthly' | 'quarterly'; importance: 'low' | 'medium' | 'high' | 'critical'; description: string; command?: string; } export declare class DatabaseHealthAuditor { private client; constructor(client: Client); /** * Perform comprehensive database health audit */ performHealthAudit(): Promise<DatabaseHealthReport>; /** * Get comprehensive database information */ private getDatabaseInfo; /** * Analyze schema health and detect issues */ private analyzeSchemaHealth; /** * Analyze indexes for efficiency and issues */ private analyzeIndexes; /** * Detect performance issues */ private detectPerformanceIssues; /** * Detect security issues */ private detectSecurityIssues; /** * Analyze database costs and usage */ private analyzeCosts; /** * Generate optimization recommendations */ private generateOptimizationRecommendations; /** * Generate maintenance recommendations */ private generateMaintenanceRecommendations; /** * Format bytes to human readable string */ private formatBytes; } //# sourceMappingURL=database-health-auditor.d.ts.map