public TableSpecification CreateTable(string tableName) { var gene = new CreateTableGene(_gene, tableName, Prerequisites); EvolutionHistoryBuilder.Append(gene); gene.AddToParent(); return(new TableSpecification(gene, EvolutionHistoryBuilder)); }
public CustomSqlSpecification Execute(string up, string down = null) { var gene = new CustomSqlGene(_databaseName, up, down, Prerequisites); EvolutionHistoryBuilder.Append(gene); gene.AddToParent(); return(new CustomSqlSpecification(gene, EvolutionHistoryBuilder)); }
public SchemaSpecification UseSchema(string schemaName) { var gene = new UseSchemaGene(_databaseName, schemaName, Prerequisites); EvolutionHistoryBuilder.Append(gene); gene.AddToParent(); return(new SchemaSpecification(gene, EvolutionHistoryBuilder)); }
public void DropColumn() { var childGene = new DropColumnGene( _gene, Prerequisites); EvolutionHistoryBuilder.Append(childGene); childGene.AddToParent(); }
public IndexSpecification CreateIndex(params ColumnSpecification[] columns) { var childGene = new CreateIndexGene( _gene, columns.Select(c => c.Gene), Prerequisites); EvolutionHistoryBuilder.Append(childGene); childGene.AddToParent(); return(new IndexSpecification(childGene, EvolutionHistoryBuilder)); }
private ColumnSpecification CreateColumn(string columnName, string typeDescriptor, bool nullable) { var childGene = new CreateColumnGene( _gene, columnName, typeDescriptor, nullable, Prerequisites); EvolutionHistoryBuilder.Append(childGene); childGene.AddToParent(); return(new ColumnSpecification(childGene, EvolutionHistoryBuilder)); }
public ForeignKeySpecification CreateForeignKey(PrimaryKeySpecification referencing, bool cascadeDelete = false, bool cascadeUpdate = false) { var childGene = new CreateForeignKeyGene( _gene, referencing.Gene, cascadeDelete, cascadeUpdate, Prerequisites); EvolutionHistoryBuilder.Append(childGene); childGene.AddToParent(); return(new ForeignKeySpecification(EvolutionHistoryBuilder)); }
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); }