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/ColumnAdd.cs

36 lines
770 B

using System.Text;
namespace Connected.Data.Schema.Sql
{
internal class ColumnAdd : ColumnTransaction
{
public ColumnAdd(ISchemaColumn column) : base(column)
{
}
protected override async Task OnExecute()
{
await Context.Execute(CommandText);
if (Column.IsPrimaryKey)
await new PrimaryKeyAdd(Column).Execute(Context);
if (!string.IsNullOrWhiteSpace(Column.DefaultValue))
await new DefaultAdd(Column, Context.Schema.Name).Execute(Context);
}
private string CommandText
{
get
{
var text = new StringBuilder();
text.AppendLine($"ALTER TABLE {Escape(Context.Schema.SchemaName(), Context.Schema.Name)}");
text.AppendLine($"ADD COLUMN {CreateColumnCommandText(Column)}");
return text.ToString();
}
}
}
}