public override string[] GenerateSql(MigrationHistoryBuilder migrationsAffected, IGraphVisitor graph) { string createTable; string head = $"CREATE TABLE [{DatabaseName}].[{SchemaName}].[{TableName}]"; var optimizableMigrations = _definitions .SelectMany(m => graph.PullPrerequisitesForward(m, this, CanOptimize)) .ToImmutableList(); if (optimizableMigrations.Any()) { var definitions = optimizableMigrations .OfType <TableDefinitionMigration>() .Select(d => d.GenerateDefinitionSql()); createTable = $"{head}({string.Join(",", definitions)})"; } else { createTable = head; } string[] sql = { createTable }; migrationsAffected.AppendAll(optimizableMigrations); return(sql); }
public override string[] GenerateRollbackSql(MigrationHistoryBuilder migrationsAffected, IGraphVisitor graph) { string[] sql = { $"DROP TABLE [{DatabaseName}].[{SchemaName}].[{TableName}]" }; migrationsAffected.AppendAll(_definitions); return(sql); }