Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More column settings #145

Merged
merged 4 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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