< Summary - ZhEaIsNsAaBn.Libraries coverage (affected: 23 packages)

Information
Line coverage
95%
Covered lines: 23
Uncovered lines: 1
Coverable lines: 24
Total lines: 73
Line coverage: 95.8%
Branch coverage
76%
Covered branches: 20
Total branches: 26
Branch coverage: 76.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Plan(...)76.92%262695.65%
Keys(...)100%11100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder/Running/SeedStepPlanner.cs

#LineLine coverage
 1namespace ZhEaIsNsAaBn.DbSeeder;
 2
 3/// <summary>
 4/// Turns a bound migration into its ordered steps (§6.1 – §6.2): upserts principals first (self-referencing rows by lev
 5/// restores, then per table dependents first the <c>Delete</c> rows (entity delete mode: soft when <c>Auto</c> and soft
 6/// <c>SoftDelete</c> rows. The runner executes these steps; the SQL script is generated from the same ones.
 7/// </summary>
 8internal static class SeedStepPlanner
 9{
 10    /// <returns>The steps; otherwise <c>SystemUserRequired</c>, <c>CycleDetected</c> or <c>SoftDeleteNotSupported</c>.<
 11    public static LayerResponse<IReadOnlyList<SeedStep>> Plan( IReadOnlyList<SeedBoundTable> tables, SeedRowWriter write
 12    {
 34313        var steps = new List<SeedStep>();
 14
 15
 254016        foreach ( var table in tables.Where( t => t.UpsertRows.Count > 0 ) )
 17        {
 92718            var writes = writer.Upserts( table, migrationId );
 19
 92720            if ( writes.IsFailure ) { return LayerResponse<IReadOnlyList<SeedStep>>.Failure( writes ); }
 21
 92722            steps.AddRange( writes.Result!.Select( w => new SeedStep { Kind = SeedStepKind.Upsert, Table = table.Table, 
 23        }
 24
 25
 75626        foreach ( var table in tables.Where( t => t.RestoreKeys.Count > 0 ) )
 27        {
 3528            if ( table.Table.SoftDeleteFlag is null ) { return SeedErrors.SoftDeleteNotSupported( table.EntityType.Name 
 29
 30
 3531            var values = writer.RestoreValues( table );
 32
 3533            if ( values.IsFailure ) { return LayerResponse<IReadOnlyList<SeedStep>>.Failure( values ); }
 34
 3535            steps.Add( new SeedStep { Kind = SeedStepKind.Restore, Table = table.Table, Keys = Keys( table, table.Restor
 36        }
 37
 38
 273639        foreach ( var table in tables.Reverse() )
 40        {
 41            // Delete follows the entity's delete mode; SoftDelete is always soft.
 615042            foreach ( var (keys, mode) in new[] { ( table.DeleteKeys, table.Roles.DeleteMode ), ( table.SoftDeleteKeys, 
 43            {
 205044                if ( keys.Count == 0 ) { continue; }
 45
 46
 20747                var soft = mode == SeedDeleteMode.Soft || ( mode == SeedDeleteMode.Auto && table.Table.SoftDeleteFlag is
 48
 20749                if ( !soft )
 50                {
 7051                    steps.Add( new SeedStep { Kind = SeedStepKind.Delete, Table = table.Table, Keys = Keys( table, keys 
 52
 7053                    continue;
 54                }
 55
 13756                if ( table.Table.SoftDeleteFlag is null ) { return SeedErrors.SoftDeleteNotSupported( table.EntityType.N
 57
 58
 13759                var values = writer.SoftDeleteValues( table );
 60
 13761                if ( values.IsFailure ) { return LayerResponse<IReadOnlyList<SeedStep>>.Failure( values ); }
 62
 13763                steps.Add( new SeedStep { Kind = SeedStepKind.SoftDelete, Table = table.Table, Keys = Keys( table, keys 
 64            }
 65        }
 66
 67
 34368        return steps;
 069    }
 70
 71
 24272    private static SeedTableKeys Keys( SeedBoundTable table, IReadOnlyList<IReadOnlyList<object?>> keys ) => new() { Tab
 73}