diff --git a/dbt_meshify/cli.py b/dbt_meshify/cli.py index 7a62408..91e5dff 100644 --- a/dbt_meshify/cli.py +++ b/dbt_meshify/cli.py @@ -103,6 +103,13 @@ help="Skips the dbt docs generate step and reads the local catalog.json file.", ) +latest = click.option( + "--latest", + "-l", + is_flag=True, + help="Makes the newest version the latest version when incrementing model versions", +) + def owner(func): """Add click options and argument validation for creating Owner objects.""" diff --git a/dbt_meshify/main.py b/dbt_meshify/main.py index 9f16df7..1e5deb6 100644 --- a/dbt_meshify/main.py +++ b/dbt_meshify/main.py @@ -26,6 +26,7 @@ exclude, exclude_projects, group_yml_path, + latest, owner, owner_email, owner_name, @@ -357,14 +358,14 @@ def add_version( @read_catalog @select @selector -@click.option("--prerelease", "--pre", default=False, is_flag=True) +@latest @click.option("--defined-in", default=None) def bump_version( select, exclude, project_path, selector, - prerelease: bool, + latest: bool, defined_in: Optional[Path], read_catalog, ) -> List[ChangeSet]: @@ -397,7 +398,7 @@ def bump_version( continue changes: ChangeSet = versioner.bump_version( - model=model_node, prerelease=prerelease, defined_in=defined_in + model=model_node, prerelease=not (latest), defined_in=defined_in ) change_set.extend(changes) @@ -413,14 +414,14 @@ def bump_version( @read_catalog @select @selector -@click.option("--prerelease", "--pre", default=False, is_flag=True) +@latest @click.option("--defined-in", default=None) def version( select, exclude, project_path, selector, - prerelease: bool, + latest: bool, defined_in: Optional[Path], read_catalog, ) -> List[ChangeSet]: @@ -459,7 +460,7 @@ def version( versioner.bump_version( model=model_node, defined_in=defined_in, - prerelease=prerelease, + prerelease=not (latest), ) ) @@ -483,7 +484,7 @@ def version( bump_change: ChangeSet = versioner.bump_version( model=model_node, defined_in=defined_in, - prerelease=prerelease, + prerelease=not (latest), model_override=model_add_change.data, ) diff --git a/tests/integration/test_version_command.py b/tests/integration/test_version_command.py index 78408e2..864a606 100644 --- a/tests/integration/test_version_command.py +++ b/tests/integration/test_version_command.py @@ -12,11 +12,11 @@ from ..sql_and_yml_fixtures import ( expected_versioned_model_yml_increment_prerelease_version, expected_versioned_model_yml_increment_prerelease_version_with_second_prerelease, - expected_versioned_model_yml_increment_version_defined_in, expected_versioned_model_yml_increment_version_no_prerelease, expected_versioned_model_yml_increment_version_with_prerelease, expected_versioned_model_yml_no_version, expected_versioned_model_yml_no_yml, + expected_versioned_model_yml_prerelease_defined_in, model_yml_increment_version, model_yml_no_col_no_version, model_yml_string_version, @@ -109,7 +109,7 @@ def test_add_version_version_in_yml( ), ( model_yml_increment_version, - expected_versioned_model_yml_increment_version_defined_in, + expected_versioned_model_yml_prerelease_defined_in, ["shared_model.sql"], ["shared_model_v1.sql", "daves_model.sql"], ["--defined-in", "daves_model"], @@ -211,18 +211,18 @@ def test_bump_version_fails_when_no_versions_present( expected_versioned_model_yml_increment_version_no_prerelease, ["shared_model.sql"], ["shared_model_v1.sql", "shared_model_v2.sql"], - [], + ["--latest"], ), ( model_yml_increment_version, expected_versioned_model_yml_increment_version_with_prerelease, ["shared_model.sql"], ["shared_model_v1.sql", "shared_model_v2.sql"], - ["--prerelease"], + [], ), ( model_yml_increment_version, - expected_versioned_model_yml_increment_version_defined_in, + expected_versioned_model_yml_prerelease_defined_in, ["shared_model.sql"], ["shared_model_v1.sql", "daves_model.sql"], ["--defined-in", "daves_model"], @@ -232,14 +232,14 @@ def test_bump_version_fails_when_no_versions_present( expected_versioned_model_yml_increment_prerelease_version_with_second_prerelease, ["shared_model_v1.sql", "shared_model_v2.sql"], ["shared_model_v1.sql", "shared_model_v2.sql", "shared_model_v3.sql"], - ["--prerelease"], + [], ), ( expected_versioned_model_yml_increment_version_with_prerelease, expected_versioned_model_yml_increment_prerelease_version, ["shared_model_v1.sql", "shared_model_v2.sql"], ["shared_model_v1.sql", "shared_model_v2.sql", "shared_model_v3.sql"], - [], + ["--latest"], ), ], ids=["1", "2", "3", "4", "5"], @@ -289,7 +289,7 @@ def test_bump_version_in_yml( model_yml_increment_version, expected_versioned_model_yml_increment_version_with_prerelease, ["shared_model_v1.sql", "shared_model_v2.sql"], - ["--prerelease"], + [], ) ], ) diff --git a/tests/sql_and_yml_fixtures.py b/tests/sql_and_yml_fixtures.py index b0977ad..e6b920e 100644 --- a/tests/sql_and_yml_fixtures.py +++ b/tests/sql_and_yml_fixtures.py @@ -234,10 +234,10 @@ - v: 3 """ -expected_versioned_model_yml_increment_version_defined_in = """ +expected_versioned_model_yml_prerelease_defined_in = """ models: - name: shared_model - latest_version: 2 + latest_version: 1 description: "this is a test model" versions: - v: 1 diff --git a/tests/unit/test_add_version_to_yml.py b/tests/unit/test_add_version_to_yml.py index 9386f2b..2313e12 100644 --- a/tests/unit/test_add_version_to_yml.py +++ b/tests/unit/test_add_version_to_yml.py @@ -8,11 +8,11 @@ from ..dbt_project_fixtures import model, project # noqa: F401 from ..sql_and_yml_fixtures import ( - expected_versioned_model_yml_increment_version_defined_in, expected_versioned_model_yml_increment_version_no_prerelease, expected_versioned_model_yml_increment_version_with_prerelease, expected_versioned_model_yml_no_version, expected_versioned_model_yml_no_yml, + expected_versioned_model_yml_prerelease_defined_in, model_yml_increment_version, model_yml_no_col_no_version, ) @@ -81,9 +81,9 @@ def test_add_version_to_model_yml_increment_version_defined_in( self, model, project, file_manager # noqa: F811 ): versioner = ModelVersioner(project=project, file_manager=file_manager) - changes = list(versioner.bump_version(model, defined_in="daves_model")) + changes = list(versioner.bump_version(model, defined_in="daves_model", prerelease=True)) yml_dict = ResourceFileEditor.update_resource( properties=read_yml(model_yml_increment_version), change=changes[0] ) - assert yml_dict == read_yml(expected_versioned_model_yml_increment_version_defined_in) + assert yml_dict == read_yml(expected_versioned_model_yml_prerelease_defined_in)