public override string[] GenerateSql(EvolutionHistoryBuilder genesAffected, IGraphVisitor graph) { string createTable; string head = $"CREATE TABLE [{DatabaseName}].[{SchemaName}].[{TableName}]"; var optimizableGenes = _definitions .SelectMany(m => graph.PullPrerequisitesForward(m, this, CanOptimize)) .ToImmutableList(); if (optimizableGenes.Any()) { var definitions = optimizableGenes .OfType <TableDefinitionGene>() .Where(d => !d.Dropped) .Select(d => d.GenerateDefinitionSql()); createTable = $"{head}({string.Join(",", definitions)})"; optimizableGenes = optimizableGenes.AddRange(optimizableGenes .OfType <CreateColumnGene>() .SelectMany(d => d.Modifications)); } else { createTable = head; } string[] sql = { createTable }; genesAffected.AppendAll(optimizableGenes); return(sql); }
public override string[] GenerateRollbackSql(EvolutionHistoryBuilder genesAffected, IGraphVisitor graph) { string[] sql = { $"DROP TABLE [{DatabaseName}].[{SchemaName}].[{TableName}]" }; genesAffected.AppendAll(_definitions); return(sql); }
public override string[] GenerateSql(EvolutionHistoryBuilder genesAffected, IGraphVisitor graph) { var optimizableGenes = _modifications .SelectMany(m => graph.PullPrerequisitesForward(m, this, CanOptimize)) .ToImmutableList(); if (optimizableGenes.Any()) { genesAffected.AppendAll(optimizableGenes); if (optimizableGenes.OfType <DropColumnGene>().Any()) { return(new string[0]); } } return(CreateColumnSql()); }