diff --git a/CHANGELOG.md b/CHANGELOG.md index 733ac439..2131d99b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Type conversion when importing contracts into dbt and exporting contracts from dbt (#534) +- Ensure 'name' is the first column when exporting in dbt format, considering column attributes (#541) ### Fixed - Modify the arguments to narrow down the import target with `--dbt-model` (#532) diff --git a/datacontract/export/dbt_converter.py b/datacontract/export/dbt_converter.py index 7b5254d3..48f8e0af 100644 --- a/datacontract/export/dbt_converter.py +++ b/datacontract/export/dbt_converter.py @@ -135,14 +135,13 @@ def _supports_constraints(model_type): def _to_columns(fields: Dict[str, Field], supports_constraints: bool, adapter_type: Optional[str]) -> list: columns = [] for field_name, field in fields.items(): - column = _to_column(field, supports_constraints, adapter_type) - column["name"] = field_name + column = _to_column(field_name, field, supports_constraints, adapter_type) columns.append(column) return columns -def _to_column(field: Field, supports_constraints: bool, adapter_type: Optional[str]) -> dict: - column = {} +def _to_column(field_name: str, field: Field, supports_constraints: bool, adapter_type: Optional[str]) -> dict: + column = {"name": field_name} adapter_type = adapter_type or "snowflake" dbt_type = convert_to_sql_type(field, adapter_type) if dbt_type is not None: