|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Generate a demo HTML report to showcase the new check feature.""" |
| 3 | + |
| 4 | +from datetime import datetime |
| 5 | +from pum.checker import ComparisonReport, CheckResult, DifferenceItem, DifferenceType |
| 6 | +from pum.report_generator import ReportGenerator |
| 7 | + |
| 8 | +# Create check results |
| 9 | +check_results = [ |
| 10 | + CheckResult(name="Tables", key="tables", passed=True, differences=[]), |
| 11 | + CheckResult( |
| 12 | + name="Columns", |
| 13 | + key="columns", |
| 14 | + passed=False, |
| 15 | + differences=[ |
| 16 | + DifferenceItem( |
| 17 | + type=DifferenceType.REMOVED, |
| 18 | + content="('public', 'users', 'email', 'character varying', 100)", |
| 19 | + ), |
| 20 | + DifferenceItem( |
| 21 | + type=DifferenceType.ADDED, |
| 22 | + content="('public', 'users', 'email', 'character varying', 255)", |
| 23 | + ), |
| 24 | + DifferenceItem( |
| 25 | + type=DifferenceType.ADDED, |
| 26 | + content="('public', 'users', 'created_at', 'timestamp', None)", |
| 27 | + ), |
| 28 | + ], |
| 29 | + ), |
| 30 | + CheckResult(name="Constraints", key="constraints", passed=True, differences=[]), |
| 31 | + CheckResult( |
| 32 | + name="Views", |
| 33 | + key="views", |
| 34 | + passed=False, |
| 35 | + differences=[ |
| 36 | + DifferenceItem( |
| 37 | + type=DifferenceType.REMOVED, |
| 38 | + content="('user_stats', 'SELECT id, COUNT(*) FROM users GROUP BY id')", |
| 39 | + ), |
| 40 | + DifferenceItem( |
| 41 | + type=DifferenceType.ADDED, |
| 42 | + content="('user_stats', 'SELECT id, name, COUNT(*) FROM users GROUP BY id, name')", |
| 43 | + ), |
| 44 | + ], |
| 45 | + ), |
| 46 | + CheckResult( |
| 47 | + name="Indexes", |
| 48 | + key="indexes", |
| 49 | + passed=False, |
| 50 | + differences=[ |
| 51 | + DifferenceItem( |
| 52 | + type=DifferenceType.ADDED, content="('users', 'idx_users_email', 'email', 'public')" |
| 53 | + ), |
| 54 | + DifferenceItem( |
| 55 | + type=DifferenceType.ADDED, |
| 56 | + content="('orders', 'idx_orders_created_at', 'created_at', 'public')", |
| 57 | + ), |
| 58 | + ], |
| 59 | + ), |
| 60 | + CheckResult(name="Functions", key="functions", passed=True, differences=[]), |
| 61 | +] |
| 62 | + |
| 63 | +# Create comparison report |
| 64 | +report = ComparisonReport( |
| 65 | + pg_service1="database_production", |
| 66 | + pg_service2="database_staging", |
| 67 | + timestamp=datetime.now(), |
| 68 | + check_results=check_results, |
| 69 | +) |
| 70 | + |
| 71 | +# Generate HTML |
| 72 | +html = ReportGenerator.generate_html(report) |
| 73 | +output_file = "/tmp/pum_demo_report.html" |
| 74 | +with open(output_file, "w", encoding="utf-8") as f: |
| 75 | + f.write(html) |
| 76 | + |
| 77 | +print(f"Demo HTML report generated at {output_file}") |
| 78 | +print("Open it in your browser to see the new design!") |
| 79 | +print() |
| 80 | +print("Report summary:") |
| 81 | +print(f" Total checks: {report.total_checks}") |
| 82 | +print(f" Passed: {report.passed_checks}") |
| 83 | +print(f" Failed: {report.failed_checks}") |
| 84 | +print(f" Total differences: {report.total_differences}") |
| 85 | +print(f" Overall result: {'PASSED' if report.passed else 'FAILED'}") |
0 commit comments