Skip to content

Commit

Permalink
feat: add support for skip add source columns
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma committed Jan 2, 2025
1 parent 9d8bc30 commit e0056b2
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 48 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "dbt-osmosis"
version = "1.0.1"
version = "1.0.2"
description = "A dbt utility for managing YAML to make developing with dbt more delightful."
readme = "README.md"
license = { text = "Apache-2.0" }
Expand Down Expand Up @@ -67,3 +67,4 @@ include_trailing_comma = true

[tool.ruff]
line-length = 100
preview = true
105 changes: 59 additions & 46 deletions src/dbt_osmosis/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
def yaml_opts(func: t.Callable[P, T]) -> t.Callable[P, T]:
"""Options common to YAML operations."""

@click.argument("models", nargs=-1)
@click.option(
"-f",
"--fqn",
Expand Down Expand Up @@ -139,65 +140,69 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
"-F",
"--force-inherit-descriptions",
is_flag=True,
help="If specified, forces descriptions to be inherited from an upstream source if possible.",
help="Force descriptions to be inherited from an upstream source if possible.",
)
@click.option(
"--skip-add-columns",
"--use-unrendered-descriptions",
is_flag=True,
help="If specified, we will skip adding columns to the models. This is useful if you want to document your models without adding columns present in the database.",
help="Use unrendered column descriptions in the documentation. This is the only way to propogate docs blocks",
)
@click.option(
"--skip-add-tags",
"--skip-add-columns",
is_flag=True,
help="If specified, we will skip adding upstream tags to the model columns.",
help="Skip adding missing columns to any yaml. Useful if you want to document your models without adding large volume of columns present in the database.",
)
@click.option(
"--skip-merge-meta",
"--skip-add-source-columns",
is_flag=True,
help="If specified, we will skip merging upstrean meta keys to the model columns.",
help="Skip adding missing columns to source yamls. Useful if you want to document your models without adding large volume of columns present in the database.",
)
@click.option(
"--skip-add-data-types",
"--skip-add-tags",
is_flag=True,
help="If specified, we will skip adding data types to the models.",
help="Skip adding upstream tags to the model columns.",
)
@click.option(
"--numeric-precision",
"--skip-merge-meta",
is_flag=True,
help="If specified, numeric types will have precision and scale, e.g. Number(38, 8).",
help="Skip merging upstrean meta keys to the model columns.",
)
@click.option(
"--char-length",
"--skip-add-data-types",
is_flag=True,
help="If specified, character types will have length, e.g. Varchar(128).",
help="Skip adding data types 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 (origin) of a specific model's column.",
)
@click.option(
"--use-unrendered-descriptions",
is_flag=True,
help="If specified, will use unrendered column descriptions in the documentation. This is the only way to propogate docs blocks",
help="Progenitor information will be added to the meta information of a column. Useful to understand which model is the progenitor (origin) of a specific model's column.",
)
@click.option(
"--add-inheritance-for-specified-keys",
multiple=True,
type=click.STRING,
help="If specified, will add inheritance for the specified keys. IE policy_tags",
help="Add inheritance for the specified keys. IE policy_tags",
)
@click.option(
"--numeric-precision",
is_flag=True,
help="Numeric types will have precision and scale, e.g. Number(38, 8).",
)
@click.option(
"--char-length",
is_flag=True,
help="Character types will have length, e.g. Varchar(128).",
)
@click.option(
"--output-to-lower",
is_flag=True,
help="If specified, output yaml file columns and data types in lowercase if possible.",
help="Output yaml file columns and data types in lowercase if possible.",
)
@click.option(
"--auto-apply",
is_flag=True,
help="If specified, will automatically apply the restructure plan without confirmation.",
help="Automatically apply the restructure plan without confirmation.",
)
@click.argument("models", nargs=-1)
def refactor(
target: str | None = None,
profile: str | None = None,
Expand Down Expand Up @@ -247,7 +252,6 @@ def refactor(
@yaml.command(context_settings=_CONTEXT)
@shared_opts
@yaml_opts
@click.argument("models", nargs=-1)
@click.option(
"--auto-apply",
is_flag=True,
Expand Down Expand Up @@ -299,60 +303,69 @@ def organize(
"-F",
"--force-inherit-descriptions",
is_flag=True,
help="If specified, forces descriptions to be inherited from an upstream source if possible.",
help="Force descriptions to be inherited from an upstream source if possible.",
)
@click.option(
"--skip-add-tags",
"--use-unrendered-descriptions",
is_flag=True,
help="If specified, we will skip adding upstream tags to the model columns.",
help="Use unrendered column descriptions in the documentation. This is the only way to propogate docs blocks",
)
@click.option(
"--skip-merge-meta",
"--skip-add-columns",
is_flag=True,
help="If specified, we will skip merging upstrean meta keys to the model columns.",
help="Skip adding missing columns to any yaml. Useful if you want to document your models without adding large volume of columns present in the database.",
)
@click.option(
"--skip-add-data-types",
"--skip-add-source-columns",
is_flag=True,
help="If specified, we will skip adding data types to the models.",
help="Skip adding missing columns to source yamls. Useful if you want to document your models without adding large volume of columns present in the database.",
)
@click.option(
"--skip-add-columns",
"--skip-add-tags",
is_flag=True,
help="If specified, we will skip adding columns to the models. This is useful if you want to document your models without adding columns present in the database.",
help="Skip adding upstream tags to the model columns.",
)
@click.option(
"--numeric-precision",
"--skip-merge-meta",
is_flag=True,
help="If specified, numeric types will have precision and scale, e.g. Number(38, 8).",
help="Skip merging upstrean meta keys to the model columns.",
)
@click.option(
"--char-length",
"--skip-add-data-types",
is_flag=True,
help="If specified, character types will have length, e.g. Varchar(128).",
help="Skip adding data types 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 (origin) of a specific model's column.",
)
@click.option(
"--use-unrendered-descriptions",
is_flag=True,
help="If specified, will use unrendered column descriptions in the documentation. This is the only way to propogate docs blocks",
help="Progenitor information will be added to the meta information of a column. Useful to understand which model is the progenitor (origin) of a specific model's column.",
)
@click.option(
"--add-inheritance-for-specified-keys",
multiple=True,
type=click.STRING,
help="If specified, will add inheritance for the specified keys. IE policy_tags",
help="Add inheritance for the specified keys. IE policy_tags",
)
@click.option(
"--numeric-precision",
is_flag=True,
help="Numeric types will have precision and scale, e.g. Number(38, 8).",
)
@click.option(
"--char-length",
is_flag=True,
help="Character types will have length, e.g. Varchar(128).",
)
@click.option(
"--output-to-lower",
is_flag=True,
help="If specified, output yaml file columns and data types in lowercase if possible.",
help="Output yaml file columns and data types in lowercase if possible.",
)
@click.option(
"--auto-apply",
is_flag=True,
help="Automatically apply the restructure plan without confirmation.",
)
@click.argument("models", nargs=-1)
def document(
target: str | None = None,
profile: str | None = None,
Expand Down
5 changes: 5 additions & 0 deletions src/dbt_osmosis/core/osmosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ class YamlRefactorSettings:
"""Skip appending upstream tags in the yaml files."""
skip_add_data_types: bool = False
"""Skip adding data types in the yaml files."""
skip_add_source_columns: bool = False
"""Skip adding source columns in the yaml files."""
numeric_precision: bool = False
"""Include numeric precision in the data type."""
char_length: bool = False
Expand Down Expand Up @@ -1578,6 +1580,9 @@ def inject_missing_columns(context: YamlRefactorContext, node: ResultNode | None
for _, node in filter_models(context):
inject_missing_columns(context, node)
return
if context.settings.skip_add_source_columns and node.resource_type == NodeType.Source:
logger.debug(":no_entry_sign: Skipping column injection (skip_add_source_columns=True).")
return
current_columns = {
normalize_column_name(c.name, context.project.config.credentials.type)
for c in node.columns.values()
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e0056b2

Please sign in to comment.