Skip to content

Conversation

toshifumisuga
Copy link
Contributor

@toshifumisuga toshifumisuga commented Sep 24, 2025

Summary

This PR enhances the dbt export functionality to properly handle model-level primaryKey configurations in data contracts. The implementation differentiates between single-column and multi-column primary keys, applying
appropriate dbt constraints and tests.

Changes Made

  • Multi-column primaryKey: Generates dbt_utils.unique_combination_of_columns test at the model level
  • Single-column primaryKey: Adds unique constraint directly to the column level

Consultation Items

I also checked the export results after setting the PK at the column level, but nothing in particular was reflected.

Should this feature be removed?
Or should it be modified so that the NOT NULL and UNIQUE tests are set?

reviewee's checkpoint

  • Tests pass
pytest tests result
(datacontract-cli) datacontract-cli toshifumi.suga$ pytest tests/test_export_dbt_models.py -v 
=================================================================================================================== test session starts ====================================================================================================================
platform darwin -- Python 3.11.13, pytest-8.4.2, pluggy-1.6.0 -- /Users/toshifumi.suga/Documents/dev/datacontract-cli/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/toshifumi.suga/Documents/dev/datacontract-cli
configfile: pyproject.toml
plugins: xdist-3.8.0, anyio-4.10.0, typeguard-4.4.4
collected 6 items                                                                                                                                                                                                                                          

tests/test_export_dbt_models.py::test_cli PASSED                                                                                                                                                                                                     [ 16%]
tests/test_export_dbt_models.py::test_to_dbt_models PASSED                                                                                                                                                                                           [ 33%]
tests/test_export_dbt_models.py::test_to_dbt_models_with_server PASSED                                                                                                                                                                               [ 50%]
tests/test_export_dbt_models.py::test_to_dbt_models_with_no_model_type PASSED                                                                                                                                                                        [ 66%]
tests/test_export_dbt_models.py::test_to_dbt_models_with_model_level_composite_primary_key PASSED                                                                                                                                                    [ 83%]
tests/test_export_dbt_models.py::test_to_dbt_models_with_single_column_primary_key PASSED                                                                                                                                                            [100%]

==================================================================================================================== 6 passed in 0.61s =====================================================================================================================
  • ruff format
ruff check result
(datacontract-cli) datacontract-cli toshifumi.suga$ ruff check tests/test_export_dbt_models.py 
All checks passed!
(datacontract-cli) datacontract-cli toshifumi.suga$ ruff check datacontract/export/dbt_converter.py 
All checks passed!

I haven't made the changes yet because there are still matters to discuss.

  • README.md updated (if relevant)
  •  CHANGELOG.md entry added

@toshifumisuga toshifumisuga changed the title fix primaryKey support for dbt export feat: add model-level primaryKey support for dbt export Sep 24, 2025
@toshifumisuga toshifumisuga marked this pull request as ready for review September 24, 2025 06:30
Copy link
Contributor

@jochenchrist jochenchrist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jochenchrist
Copy link
Contributor

Please also update the Changelog

@jochenchrist jochenchrist merged commit e3a5915 into datacontract:main Sep 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants