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

35 lines
816 B

2 years ago
using System.Text;
namespace Connected.Data.Schema.Sql
{
internal class DefaultAdd : ColumnTransaction
{
public DefaultAdd(ISchemaColumn column, string tableName) : base(column)
{
TableName = tableName;
}
private string TableName { get; }
protected override async Task OnExecute()
{
await Context.Execute(CommandText);
}
private string CommandText
{
get
{
var text = new StringBuilder();
var defValue = SchemaExtensions.ParseDefaultValue(Column.DefaultValue);
text.AppendLine($"ALTER TABLE {Escape(Context.Schema.SchemaName(), TableName)}");
text.AppendLine($"ADD CONSTRAINT {Context.GenerateConstraintName(Context.Schema.SchemaName(), TableName, ConstraintNameType.Default)} DEFAULT {defValue} FOR {Column.Name}");
return text.ToString();
}
}
}
}