Skip to content

Commit

Permalink
Merge pull request #83 from syou6162/add_progenitor_to_meta
Browse files Browse the repository at this point in the history
[feature] Add progenitor information to meta
  • Loading branch information
z3z1ma authored Aug 27, 2023
2 parents 071aa77 + 651bfd1 commit 5cae0b4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/dbt_osmosis/core/osmosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(
skip_add_columns: bool = False,
skip_add_tags: bool = False,
skip_merge_meta: bool = False,
add_progenitor_to_meta : bool = False,
):
"""Initializes the DbtYamlManager class."""
super().__init__(target, profiles_dir, project_dir, threads)
Expand All @@ -123,6 +124,7 @@ def __init__(
self.skip_add_columns = skip_add_columns
self.skip_add_tags = skip_add_tags
self.skip_merge_meta = skip_merge_meta
self.add_progenitor_to_meta = add_progenitor_to_meta

if len(list(self.filtered_models())) == 0:
logger().warning(
Expand Down Expand Up @@ -1019,6 +1021,9 @@ def update_undocumented_columns_with_prior_knowledge(
node.columns[column].replace(kwargs={"name": column, **prior_knowledge})
for model_column in yaml_file_model_section["columns"]:
if model_column["name"] == column:
if self.add_progenitor_to_meta:
prior_knowledge.setdefault("meta", {})
prior_knowledge["meta"]["osmosis_progenitor"] = progenitor
model_column.update(prior_knowledge)
changes_committed += 1
logger().info(
Expand Down
34 changes: 34 additions & 0 deletions src/dbt_osmosis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ def wrapper(*args, **kwargs):
is_flag=True,
help="If specified, we will skip merging meta to the models.",
)
@click.option(
"--add-progenitor-to-meta",
is_flag=True,
help=(
"If specified, progenitor information will be added to the meta information of a column."
" This is useful if you want to know which model is the progenitor of a specific model's column."
),
)
@click.argument("models", nargs=-1)
def refactor(
target: Optional[str] = None,
Expand All @@ -153,6 +161,7 @@ def refactor(
skip_add_columns: bool = False,
skip_add_tags: bool = False,
skip_merge_meta: bool = False,
add_progenitor_to_meta : bool = False,
models: Optional[List[str]] = None,
):
"""Executes organize which syncs yaml files with database schema and organizes the dbt models
Expand Down Expand Up @@ -180,6 +189,7 @@ def refactor(
skip_add_columns=skip_add_columns,
skip_add_tags=skip_add_tags,
skip_merge_meta=skip_merge_meta,
add_progenitor_to_meta=add_progenitor_to_meta,
)

# Conform project structure & bootstrap undocumented models injecting columns
Expand Down Expand Up @@ -231,6 +241,14 @@ def refactor(
is_flag=True,
help="If specified, we will skip merging meta to the models.",
)
@click.option(
"--add-progenitor-to-meta",
is_flag=True,
help=(
"If specified, progenitor information will be added to the meta information of a column."
" This is useful if you want to know which model is the progenitor of a specific model's column."
),
)
@click.argument("models", nargs=-1)
def organize(
target: Optional[str] = None,
Expand All @@ -241,6 +259,9 @@ def organize(
check: bool = False,
models: Optional[List[str]] = None,
skip_add_columns: bool = False,
skip_add_tags: bool = False,
skip_merge_meta: bool = False,
add_progenitor_to_meta : bool = False,
):
"""Organizes schema ymls based on config and injects undocumented models
Expand All @@ -263,6 +284,9 @@ def organize(
dry_run=dry_run,
models=models,
skip_add_columns=skip_add_columns,
skip_add_tags=skip_add_tags,
skip_merge_meta=skip_merge_meta,
add_progenitor_to_meta=add_progenitor_to_meta,
)

# Conform project structure & bootstrap undocumented models injecting columns
Expand Down Expand Up @@ -329,6 +353,14 @@ def organize(
is_flag=True,
help="If specified, we will skip merging meta to the models.",
)
@click.option(
"--add-progenitor-to-meta",
is_flag=True,
help=(
"If specified, progenitor information will be added to the meta information of a column."
" This is useful if you want to know which model is the progenitor of a specific model's column."
),
)
@click.argument("models", nargs=-1)
def document(
target: Optional[str] = None,
Expand All @@ -343,6 +375,7 @@ def document(
skip_add_columns: bool = False,
skip_add_tags: bool = False,
skip_merge_meta: bool = False,
add_progenitor_to_meta : bool = False,
):
"""Column level documentation inheritance for existing models
Expand All @@ -368,6 +401,7 @@ def document(
skip_add_columns=skip_add_columns,
skip_add_tags=skip_add_tags,
skip_merge_meta=skip_merge_meta,
add_progenitor_to_meta=add_progenitor_to_meta,
)

# Propagate documentation & inject/remove schema file columns to align with model in database
Expand Down

0 comments on commit 5cae0b4

Please sign in to comment.