Skip to content

Commit

Permalink
Generate column comments
Browse files Browse the repository at this point in the history
Related issue: dotnet#16820
  • Loading branch information
skalpin committed Aug 16, 2019
1 parent bad2bf5 commit 9528827
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,12 @@ protected virtual void ColumnDefinition(
}

var columnType = operation.ColumnType ?? GetColumnType(schema, table, name, operation, model);

if(!string.IsNullOrEmpty(operation.Comment))
{
builder.AppendLine($"-- {operation.Comment}");
}

builder
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(name))
.Append(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public override void CreateTableOperation()
AssertSql(
@"CREATE TABLE ""dbo"".""People"" (
""Id"" default_int_mapping NOT NULL,
-- Employer ID comment
""EmployerId"" default_int_mapping NULL,
""SSN"" char(11) NULL,
PRIMARY KEY (""Id""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,34 @@ public virtual void CreateTableOperation_old_autoincrement_annotation()
");
}

[ConditionalFact]
public virtual void CreateTableOperation_has_comment()
{
Generate(
new CreateTableOperation
{
Name = "People",
Columns =
{
new AddColumnOperation
{
Name = "Id",
Table = "People",
ClrType = typeof(int),
IsNullable = false,
Comment = "My Comment"
}
}
});
var sql = Sql;
AssertSql(
@"CREATE TABLE ""People"" (
-- My Comment
""Id"" INTEGER NOT NULL
);
");
}

public SqliteMigrationSqlGeneratorTest()
: base(SqliteTestHelpers.Instance)
{
Expand Down

0 comments on commit 9528827

Please sign in to comment.