Skip to content

Commit 23fff39

Browse files
committed
Comment registration support for MSSQL engine
Signed-off-by: Ujfalusi Sándor <ujfalusi.sandor@gmail.com>
1 parent 3432233 commit 23fff39

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

sqlmesh/core/engine_adapter/mssql.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def delete_from(self, table_name: TableName, where: t.Union[str, exp.Expr]) -> N
460460
return super().delete_from(table_name, where)
461461

462462
def _build_create_comment_table_exp(
463-
self, table: exp.Table, table_comment: str, table_kind: str
463+
self, table: exp.Table, table_comment: str, table_kind: str = "TABLE"
464464
) -> exp.Comment | str:
465465
template = dedent("""
466466
DECLARE @comment sql_variant = {comment};
@@ -486,17 +486,18 @@ def _build_create_comment_table_exp(
486486
END
487487
""")
488488
tsql_text = template.format(
489-
comment = exp.Literal.string(table_comment).sql(dialect=self.dialect) if table_comment is not None else "NULL",
490-
schema_name = table.db if table.db else "dbo",
491-
object_name = table.name,
492-
object_kind = table_kind,
489+
comment=exp.Literal.string(table_comment).sql(dialect=self.dialect)
490+
if table_comment is not None
491+
else "NULL",
492+
schema_name=table.db if table.db else "dbo",
493+
object_name=table.name,
494+
object_kind=table_kind,
493495
)
494496
return tsql_text
495497

496498
def _build_create_comment_column_exp(
497-
self, table: exp.Table, column_name: str, column_comment: str, table_kind: str
499+
self, table: exp.Table, column_name: str, column_comment: str, table_kind: str = "TABLE"
498500
) -> exp.Comment | str:
499-
500501
template = dedent("""
501502
DECLARE @comment sql_variant = {comment};
502503
DECLARE @property_name VARCHAR(128) = 'MS_Description';
@@ -522,11 +523,13 @@ def _build_create_comment_column_exp(
522523
END
523524
""")
524525
tsql_text = template.format(
525-
comment = exp.Literal.string(column_comment).sql(dialect=self.dialect) if column_comment is not None else "NULL",
526-
schema_name = table.db if table.db else "dbo",
527-
object_name = table.name,
528-
object_kind = table_kind,
529-
column_name = column_name,
526+
comment=exp.Literal.string(column_comment).sql(dialect=self.dialect)
527+
if column_comment is not None
528+
else "NULL",
529+
schema_name=table.db if table.db else "dbo",
530+
object_name=table.name,
531+
object_kind=table_kind,
532+
column_name=column_name,
530533
)
531534

532-
return tsql_text
535+
return tsql_text

0 commit comments

Comments
 (0)