/// <summary> /// Apply the migration to given migrable datacontext /// </summary> /// <param name="root">The migrable context root</param> public bool ApplyMigrations(IMigrable root) { var hasDoneSomething = false; this.migrations.ForEach(x => { if (!root.MigrationHistory.HasMigration(x.Key)) { this.SolveDependency(root, x.Value); x.Value.Apply(root); root.MigrationHistory.AddMigration(x.Key); hasDoneSomething = true; } }); return hasDoneSomething; }
private void SolveDependency(IMigrable root, IMigration migration) { foreach (var migrationId in migration.MigrationsNeeded.Where(x => !root.MigrationHistory.HasMigration(x))) { // For each dependency that needs to be solved, we solve the subdependencies var dependency = this.migrations[migrationId]; this.SolveDependency(root, dependency); dependency.Apply(root); root.MigrationHistory.AddMigration(migrationId); } }