DBMigrator/VersionDiff.cs
/// <summary>
/// Creates a diff of migrations found in source, but not in target
/// </summary>
/// <param name="source"></param>
/// <param name="target"></param>
/// <returns></returns>
Creates a diff of migrations found in source, but not in target
Creates a diff of migrations found in source but not in target
public IOrderedEnumerable<DBVersion> Diff(List<DBVersion> source, List<DBVersion> target)
        {
            var diff = new List<DBVersion>();
            foreach (var sourceVersion in source)
            {
                var targetVersion = target.SingleOrDefault(t => t.Name == sourceVersion.Name);
                if (targetVersion == null) {
                    diff.Add(sourceVersion);
                    continue;
                } 
                foreach (var sourceFeature in sourceVersion.Features)
                {
                    var targetFeature = targetVersion.Features.SingleOrDefault(s => s.Name == sourceFeature.Name);
                    if (targetFeature == null)
                    {
                        var diffVersion = diff.SingleOrDefault(t => t.Name == targetVersion.Name);
                        if(diffVersion == null)
                        {
                            diffVersion = new DBVersion(targetVersion.Name);
                            diff.Add(diffVersion);
                        }
                        CopyFeatureToVersion(sourceFeature, diffVersion);
                        continue;
                    }
                    foreach (var sourceUpgradeScript in sourceFeature.UpgradeScripts)
                    {
                        var targetScript = targetFeature.UpgradeScripts.SingleOrDefault(s => s.FileName == sourceUpgradeScript.FileName);
                        if (targetScript == null)
                        {
                            var diffVersion = diff.SingleOrDefault(t => t.Name == targetVersion.Name);
                            if (diffVersion == null)
                            {
                                diffVersion = new DBVersion(targetVersion.Name);
                                diff.Add(diffVersion);
                            }
                            var diffFeature = diffVersion.Features.SingleOrDefault(t => t.Name == targetFeature.Name);
                            if (diffFeature == null)
                            {
                                diffFeature = diffVersion.AddAndOrGetFeature(targetFeature.Name, targetFeature.Order);
                            }
                            CopyUpgradeScriptToFeature(sourceUpgradeScript, diffFeature);
                        }
                    }
                }
            }
            return diff.OrderBy(a => a.Version);
        }
public IOrderedEnumerable < DBVersion > Diff ( List < DBVersion > source , List < DBVersion > target ) { var diff = new List < DBVersion > ( ) ; foreach ( var sourceVersion in source ) { var targetVersion = target . SingleOrDefault ( t => t . Name == sourceVersion . Name ) ; if ( targetVersion == null ) { diff . Add ( sourceVersion ) ; continue ; } foreach ( var sourceFeature in sourceVersion . Features ) { var targetFeature = targetVersion . Features . SingleOrDefault ( s => s . Name == sourceFeature . Name ) ; if ( targetFeature == null ) { var diffVersion = diff . SingleOrDefault ( t => t . Name == targetVersion . Name ) ; if ( diffVersion == null ) { diffVersion = new DBVersion ( targetVersion . Name ) ; diff . Add ( diffVersion ) ; } CopyFeatureToVersion ( sourceFeature , diffVersion ) ; continue ; } foreach ( var sourceUpgradeScript in sourceFeature . UpgradeScripts ) { var targetScript = targetFeature . UpgradeScripts . SingleOrDefault ( s => s . FileName == sourceUpgradeScript . FileName ) ; if ( targetScript == null ) { var diffVersion = diff . SingleOrDefault ( t => t . Name == targetVersion . Name ) ; if ( diffVersion == null ) { diffVersion = new DBVersion ( targetVersion . Name ) ; diff . Add ( diffVersion ) ; } var diffFeature = diffVersion . Features . SingleOrDefault ( t => t . Name == targetFeature . Name ) ; if ( diffFeature == null ) { diffFeature = diffVersion . AddAndOrGetFeature ( targetFeature . Name , targetFeature . Order ) ; } CopyUpgradeScriptToFeature ( sourceUpgradeScript , diffFeature ) ; } } } } return diff . OrderBy ( a => a . Version ) ; }
Creates a diff of migrations found in source, but not in target
Creates a diff of migrations found in source but not in target
None
source
List<DBVersion>
None
target
List<DBVersion>
None