Skip to content

Commit

Permalink
Feature/caveats and points of interest (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
Patricia Figueira Goldberg authored Nov 27, 2021
1 parent e7c7832 commit b52fbb5
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,24 @@ Here are the visibility types supported by Metabase:

If you notice new ones, please submit a PR to update this readme.

Model extra fields
----------------

In addition to the model description, Metabase accepts two extra information fields. Those optional
fields are called ``caveats`` and ``points_of_interest`` and can be defined under the ``meta`` tag
of the model.

This is how you can specify them in the ``stg_users`` example:

.. code-block:: yaml
- name: stg_users
description: User records.
meta:
metabase.points_of_interest: Relevant records.
metabase.caveats: Sensitive information about users.
Database Sync
-------------

Expand Down
20 changes: 18 additions & 2 deletions dbtmetabase/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,30 @@ def export_model(
model_description = None
else:
model_description = model.description
if not model.points_of_interest:
model_points_of_interest = None
else:
model_points_of_interest = model.points_of_interest
if not model.caveats:
model_caveats = None
else:
model_caveats = model.caveats

body_table = {}
if api_table["description"] != model_description:
body_table["description"] = model_description
if api_table.get("points_of_interest") != model_points_of_interest:
body_table["points_of_interest"] = model_points_of_interest
if api_table.get("caveats") != model_caveats:
body_table["caveats"] = model_caveats

table_id = api_table["id"]
if api_table["description"] != model_description and model_description:
if bool(body_table):
# Update with new values
self.api(
"put",
f"/api/table/{table_id}",
json={"description": model_description},
json=body_table,
)
logger().info("\n:raising_hands: Updated table %s successfully", lookup_key)
elif not model_description:
Expand Down
2 changes: 2 additions & 0 deletions dbtmetabase/models/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class MetabaseModel:
name: str
schema: str
description: str = ""
points_of_interest: Optional[str] = None
caveats: Optional[str] = None

model_type: ModelType = ModelType.nodes
dbt_name: Optional[str] = None
Expand Down
5 changes: 5 additions & 0 deletions dbtmetabase/parsers/dbt_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def _read_model(
metabase_columns.append(self._read_column(column, schema))

description = model.get("description", "")
meta = model.get("meta", {})
points_of_interest = meta.get("metabase.points_of_interest")
caveats = meta.get("metabase.caveats")

if include_tags:
tags = model.get("tags", [])
Expand All @@ -165,6 +168,8 @@ def _read_model(
name=resolved_name,
schema=schema,
description=description,
points_of_interest=points_of_interest,
caveats=caveats,
columns=metabase_columns,
model_type=model_type,
source=source,
Expand Down
5 changes: 5 additions & 0 deletions dbtmetabase/parsers/dbt_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def _read_model(
)

description = model.get("description", "")
meta = model.get("meta", {})
points_of_interest = meta.get("metabase.points_of_interest")
caveats = meta.get("metabase.caveats")

if include_tags:
tags = model.get("tags", [])
Expand Down Expand Up @@ -273,6 +276,8 @@ def _read_model(
name=resolved_name,
schema=model["schema"].upper(),
description=description,
points_of_interest=points_of_interest,
caveats=caveats,
columns=metabase_column,
model_type=model_type,
unique_id=unique_id,
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/sample_project/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ models:

- name: orders
description: This table has basic information about orders, as well as some derived facts based on payments
meta:
metabase.points_of_interest: Basic information only
metabase.caveats: Some facts are derived from payments

columns:
- name: order_id
Expand Down
2 changes: 2 additions & 0 deletions tests/test_dbt_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def test_read_models(self):
name="orders",
schema="PUBLIC",
description="This table has basic information about orders, as well as some derived facts based on payments",
points_of_interest="Basic information only",
caveats="Some facts are derived from payments",
model_type=ModelType.nodes,
dbt_name=None,
source=None,
Expand Down

0 comments on commit b52fbb5

Please sign in to comment.