using System; using System.Collections.Generic; namespace Jellyfin.DbMigrator; /// /// Represents the migration result for a single table. /// /// The name of the table. /// The number of rows read from SQLite. /// The number of rows verified in PostgreSQL after migration. /// The error message if migration failed, or on success. public sealed record TableReport( string TableName, long SqliteRowCount, long PostgresRowCount, string? Error); /// /// Provides utilities for collecting and printing the migration report. /// public static class MigrationReport { /// /// Prints a formatted summary of per-table migration results to the console. /// /// The collection of per-table results. public static void Print(IReadOnlyList reports) { Console.WriteLine(); Console.WriteLine("=== Migration Report ==="); Console.WriteLine( $"{"Table",-40} {"SQLite",10} {"PostgreSQL",10} {"Status",-10}"); Console.WriteLine(new string('-', 74)); int failed = 0; foreach (var r in reports) { string status = r.Error is null ? "OK" : "FAILED"; if (r.Error is not null) { failed++; } Console.WriteLine( $"{r.TableName,-40} {r.SqliteRowCount,10} {r.PostgresRowCount,10} {status,-10}"); if (r.Error is not null) { Console.WriteLine($" Error: {r.Error}"); } } Console.WriteLine(new string('-', 74)); Console.WriteLine( $"Total: {reports.Count} tables, {failed} failed, {reports.Count - failed} succeeded."); } }