public void AddGene(Gene gene) { var genesAffected = new EvolutionHistoryBuilder(); genesAffected.Append(gene); string[] rollbackSql = gene.GenerateRollbackSql(genesAffected, this); var mementos = genesAffected.EvolutionHistory.GetMementos().ToList(); string[] deleteStatements = GenerateDeleteStatements(_databaseName, mementos); _sql = _sql.InsertRange(0, deleteStatements); _sql = _sql.InsertRange(0, rollbackSql); _ahead = _ahead.Subtract(genesAffected.EvolutionHistory); }
public bool AddGene(Gene gene) { if (_working.Contains(gene)) { return(false); } foreach (var prerequisite in gene.AllPrerequisites .Where(p => _difference.Contains(p))) { if (!AddGene(prerequisite)) { return(false); } } _working = _working.Push(gene); var genesAffected = new EvolutionHistoryBuilder(); genesAffected.Append(gene); string[] result = gene.GenerateSql(genesAffected, this); _sql = _sql.AddRange(result); var mementos = genesAffected.EvolutionHistory.GetMementos().ToList(); _sql = _sql.Add(GenerateInsertStatement(_databaseName, mementos)); if (mementos.SelectMany(m => m.Prerequisites).SelectMany(p => p.Value).Any()) { _sql = _sql.Add(GeneratePrerequisiteInsertStatements(_databaseName, mementos)); } _difference = _difference.Subtract(genesAffected.EvolutionHistory); _working = _working.Pop(); return(true); }
public RollbackGenerator(string databaseName, EvolutionDelta ahead) { _databaseName = databaseName; _ahead = ahead; }
public ForwardGenerator(string databaseName, EvolutionDelta difference) { _databaseName = databaseName; _difference = difference; }