You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Data/Schema/Sql/ColumnDrop.cs

40 lines
862 B

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();
}
}
}
}