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