diff --git a/dbterd/adapters/adapter.py b/dbterd/adapters/adapter.py index f2a7fde..6c65a09 100644 --- a/dbterd/adapters/adapter.py +++ b/dbterd/adapters/adapter.py @@ -18,4 +18,4 @@ def load_executor(name: str): except ModuleNotFoundError as exc: if exc.name == "dbterd.adapters.targets." + name: raise Exception(f"Could not find adapter target type {name}!") - raise + raise # pragma: no cover diff --git a/dbterd/adapters/algos/base.py b/dbterd/adapters/algos/base.py index fb6c564..ab24c88 100644 --- a/dbterd/adapters/algos/base.py +++ b/dbterd/adapters/algos/base.py @@ -117,6 +117,7 @@ def get_table(node_name, manifest_node, catalog_node=None, exposures=[], **kwarg exposures=[ x.get("exposure_name") for x in exposures if x.get("node_name") == node_name ], + description=manifest_node.description, ) if catalog_node: diff --git a/dbterd/adapters/meta.py b/dbterd/adapters/meta.py index 91131db..6f2a474 100644 --- a/dbterd/adapters/meta.py +++ b/dbterd/adapters/meta.py @@ -24,6 +24,7 @@ class Table: resource_type: str = "model" exposures: Optional[List[str]] = field(default_factory=lambda: []) node_name: str = None + description: str = "" @dataclass diff --git a/dbterd/adapters/targets/dbml/dbml_test_relationship.py b/dbterd/adapters/targets/dbml/dbml_test_relationship.py index c9e8c95..4c32f5b 100644 --- a/dbterd/adapters/targets/dbml/dbml_test_relationship.py +++ b/dbterd/adapters/targets/dbml/dbml_test_relationship.py @@ -34,7 +34,7 @@ def parse(manifest, catalog, **kwargs): dbml = "//Tables (based on the selection criteria)\n" for table in tables: dbml += f"//--configured at schema: {table.database}.{table.schema}\n" - dbml += 'Table "{table}" {{\n{columns}\n}}\n'.format( + dbml += 'Table "{table}" {{\n{columns}\n\n Note: {table_note}\n}}\n'.format( table=table.name, columns="\n".join( [ @@ -49,6 +49,7 @@ def parse(manifest, catalog, **kwargs): for x in table.columns ] ), + table_note=json.dumps(table.description), ) dbml += "//Refs (based on the DBT Relationship Tests)\n" diff --git a/pyproject.toml b/pyproject.toml index 48b376a..3f53ff4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,6 +65,9 @@ ignore-init-module-imports = true remove-unused-variables = true ignore-pass-statements = false +[tool.coverage.run] +omit = ["tests/*"] + [tool.poe.tasks] git-hooks = { shell = "pre-commit install --install-hooks && pre-commit install --hook-type commit-msg" } format = [ diff --git a/tests/unit/adapters/algos/test_test_relationship.py b/tests/unit/adapters/algos/test_test_relationship.py index f5770c3..936c655 100644 --- a/tests/unit/adapters/algos/test_test_relationship.py +++ b/tests/unit/adapters/algos/test_test_relationship.py @@ -50,6 +50,7 @@ class ManifestNode: database: str = "" schema_: str = "" depends_on: ManifestNodeDependsOn = field(default_factory=ManifestNodeDependsOn) + description: str = "" @dataclass @@ -243,6 +244,7 @@ class TestAlgoTestRelationship: schema="--schema--", columns=[Column(name="name1", data_type="--name1-type--")], raw_sql="--irrelevant--", + description="", ), Table( name="model.dbt_resto.table_dummy_columns", @@ -251,6 +253,7 @@ class TestAlgoTestRelationship: schema="--schema--", columns=[Column()], raw_sql="--irrelevant--", + description="", ), Table( name="model.dbt_resto.table2", @@ -262,6 +265,7 @@ class TestAlgoTestRelationship: Column(name="name2"), ], raw_sql="--irrelevant--", + description="", ), Table( name="source.dummy.source_table", @@ -274,6 +278,7 @@ class TestAlgoTestRelationship: ], raw_sql="--irrelevant--", resource_type="source", + description="", ), ], ), diff --git a/tests/unit/adapters/targets/dbml/test_dbml_test_relationship.py b/tests/unit/adapters/targets/dbml/test_dbml_test_relationship.py index e166204..f46885e 100644 --- a/tests/unit/adapters/targets/dbml/test_dbml_test_relationship.py +++ b/tests/unit/adapters/targets/dbml/test_dbml_test_relationship.py @@ -35,6 +35,7 @@ class TestDbmlTestRelationship: //--configured at schema: --database--.--schema-- Table "model.dbt_resto.table1" { "name1" "--name1-type--" [note: "column name 1"] + Note:"" } //Refs (based on the DBT Relationship Tests) """, @@ -86,15 +87,18 @@ class TestDbmlTestRelationship: Table "model.dbt_resto.table1" { "name1" "--name1-type--" "name-notexist1" "unknown" + Note:"" } //--configured at schema: --database2--.--schema2-- Table "model.dbt_resto.table2" { "name2" "--name2-type2--" "name-notexist2" "unknown" + Note:"" } //--configured at schema: --database3--.--schema3-- Table "source.dbt_resto.table3" { "name3" "--name3-type3--" + Note:"" } //Refs (based on the DBT Relationship Tests) Ref: "model.dbt_resto.table1"."name1" > "model.dbt_resto.table2"."name2" @@ -134,6 +138,7 @@ class TestDbmlTestRelationship: //--configured at schema: --database--.--schema-- Table "model.dbt_resto.table1" { "name1" "--name1-type--" + Note:"" } //Refs (based on the DBT Relationship Tests) """, @@ -184,6 +189,7 @@ class TestDbmlTestRelationship: //--configured at schema: --database--.--schema-- Table "model.dbt_resto.table1" { "name1" "name1-type" + Note:"" } //Refs (based on the DBT Relationship Tests) """, @@ -223,10 +229,12 @@ class TestDbmlTestRelationship: //--configured at schema: --database--.--schema-- Table "model.dbt_resto.table1" { "name1" "name1-type" + Note:"" } //--configured at schema: --database3--.--schema3-- Table "source.dbt_resto.table3" { "name3" "name3-type3" + Note:"" } //Refs (based on the DBT Relationship Tests) """, @@ -251,6 +259,7 @@ class TestDbmlTestRelationship: //--configured at schema: --database--.--schema-- Table "model.dbt_resto.table1" { "name1" "name1-type" + Note:"" } //Refs (based on the DBT Relationship Tests) """, @@ -284,6 +293,33 @@ class TestDbmlTestRelationship: //--configured at schema: --database--.--schema-- Table "model.dbt_resto.table23" { "name23" "name23-type" + Note:"" + } + //Refs (based on the DBT Relationship Tests) + """, + ), + ( + [ + Table( + name="model.dbt_resto.table23", + node_name="model.dbt_resto.table23", + database="--database--", + schema="--schema--", + columns=[Column(name="name23", data_type="name23-type")], + raw_sql="--irrelevant--", + exposures=["dummy2", "dummy3"], + description="model.dbt_resto.table23 description", + ), + ], + [], + ["exposure:dummy2"], + [], + ["model"], + """//Tables (based on the selection criteria) + //--configured at schema: --database--.--schema-- + Table "model.dbt_resto.table23" { + "name23" "name23-type" + Note:"model.dbt_resto.table23 description" } //Refs (based on the DBT Relationship Tests) """,