using System.Text; namespace Connected.Data.Schema.Sql { internal class ColumnDrop : ColumnTransaction { public ColumnDrop(ISchemaColumn column, ExistingSchema existing) : base(column) { Existing = existing; } private ExistingSchema Existing { get; } protected override async Task OnExecute() { if (!string.IsNullOrWhiteSpace(Column.DefaultValue)) await new DefaultDrop(Column).Execute(Context); var indexes = Existing.ResolveIndexes(Column.Name); foreach (var index in indexes) await new IndexDrop(index).Execute(Context); await Context.Execute(CommandText); } private string CommandText { get { var text = new StringBuilder(); text.AppendLine($"ALTER TABLE {Escape(Context.Schema.SchemaName(), Context.Schema.Name)} DROP COLUMN {Column.Name};"); return text.ToString(); } } } }