Skip to content

Commit

Permalink
More column settings (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
willbryant authored Sep 13, 2022
1 parent c64ec8a commit 0df4084
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 19 additions & 1 deletion dbtmetabase/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ def export_column(
if api_field["fk_target_field_id"] and not fk_target_field_id:
fk_target_field_id = api_field["fk_target_field_id"]

body_field = {}
api_settings = api_field.get("settings") or {}
body_field = {
"settings": api_settings.copy(),
}
if api_field.get("display_name") != column_display_name:
body_field["display_name"] = column_display_name
if api_field.get("description") != column_description:
Expand All @@ -398,6 +401,21 @@ def export_column(
body_field["visibility_type"] = column_visibility
if api_field.get("fk_target_field_id") != fk_target_field_id:
body_field["fk_target_field_id"] = fk_target_field_id
if (
api_field.get("has_field_values") != column.has_field_values
and column.has_field_values
):
body_field["has_field_values"] = column.has_field_values
if (
api_field.get("coercion_strategy") != column.coercion_strategy
and column.coercion_strategy
):
body_field["coercion_strategy"] = column.coercion_strategy
if (
api_settings.get("number_style") != column.number_style
and column.number_style
):
body_field["settings"]["number_style"] = column.number_style

# Allow explicit null type to override detected one
if api_field.get(semantic_type_key) != column.semantic_type and (
Expand Down
6 changes: 6 additions & 0 deletions dbtmetabase/models/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# Must be covered by MetabaseColumn attributes
METABASE_COLUMN_META_FIELDS = METABASE_MODEL_META_FIELDS + [
"semantic_type",
"has_field_values",
"coercion_strategy",
"number_style",
]

# Default model schema (only schema in BigQuery)
Expand All @@ -34,6 +37,9 @@ class MetabaseColumn:

semantic_type: Optional[str] = None
visibility_type: Optional[str] = None
has_field_values: Optional[str] = None
coercion_strategy: Optional[str] = None
number_style: Optional[str] = None

fk_target_table: Optional[str] = None
fk_target_field: Optional[str] = None
Expand Down

0 comments on commit 0df4084

Please sign in to comment.