dbml icon indicating copy to clipboard operation
dbml copied to clipboard

sql2dbml fail to generate note if dbo specified

Open benjdv opened this issue 1 year ago • 1 comments

Hi,

When you explicitly specify the dbo schema in front of the table, if comments are added to a column with EXEC sp_addextendedproperty (by specifying the dbo schema), these will not appear in the "note" of the columns concerned in the generated dbml via sql2dbml

Let's take the DDL noschema_specified_is_OK.sql

>>> cat ok.sql
CREATE TABLE mytable(
 a int
)
GO

EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'This is the description of my column',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'mytable',
@level2type = N'Column', @level2name = 'a'
GO

>>> sql2dbml --mssql noschema_specified_is_OK.sql
Table "mytable" {
  "a" int [note: 'This is the description of my column']
}

All is fine here.

Now try with specified_schema_is_OK.sql

>>> cat specified_schema_is_OK.sql
CREATE TABLE myschema.mytable(
 a int
)
GO

EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'This is the description of my column',
@level0type = N'Schema', @level0name = 'myschema',
@level1type = N'Table', @level1name = 'mytable',
@level2type = N'Column', @level2name = 'a'
GO

>>> sql2dbml --mssql specified_schema_is_OK.sql
Table "myschema"."mytable" {
  "a" int [note: 'This is the description of my column']
}

All is fine here.

Now try with replacing myschema by dbo in file specified_dbo_is_NOK.sql

>>> cat specified_dbo_is_NOK.sql
CREATE TABLE dbo.mytable(
 a int
)
GO

EXEC sp_addextendedproperty
@name = N'Column_Description',
@value = 'This is the description of my column',
@level0type = N'Schema', @level0name = 'dbo',
@level1type = N'Table', @level1name = 'mytable',
@level2type = N'Column', @level2name = 'a'
GO

>>> sql2dbml --mssql specified_dbo_is_NOK.sql
Table "dbo"."mytable" {
  "a" int
}

In this case, there is a problem, the note corresponding to column's a comment doesn't appears

>>>sql2dbml --version
3.0.0

benjdv avatar Jan 09 '24 11:01 benjdv

Hi @benjdv,

Thank you for reporting the issue. It's a bug that handles dbo schema inconsistently in our MSSQL parser. We will look into it soon.

Regards.

nguyenalter avatar Jan 10 '24 08:01 nguyenalter