Skip to content

Comments

Feat: yaml config for dbt projects#5156

Merged
erindru merged 1 commit intomainfrom
erin/load-config-dbt
Aug 14, 2025
Merged

Feat: yaml config for dbt projects#5156
erindru merged 1 commit intomainfrom
erin/load-config-dbt

Conversation

@erindru
Copy link
Collaborator

@erindru erindru commented Aug 14, 2025

Second attempt at #5132

This PR enables SQLMesh to load DBT projects using just yaml config, rather than forcing users to create a config.py and use python config.

The following changes have been made:

  • sqlmesh.yaml is now a valid config file name. This is because it gets written next to the existing dbt_project.yml file so I wanted it to be clear that this config is relevant to SQLMesh only, which the existing config.yaml name is not clear about
  • sqlmesh init -t dbt now produces a small yaml file instead of a python config file
  • A check has been added to load_configs to return a Config configured with the DbtLoader if a dbt_project.yml file is detected. This essentially transparently automates what the users had to do manually before
  • The sqlmesh_dbt CLI automatically runs sqlmesh init -t dbt if it doesn't detect an existing sqlmesh config file, and then proceeds normally. This enables a user to get started with dbt on the SQLMesh engine with zero manual steps

The existing config mechanism is preserved - that is, the python base config is overlayed with all the yaml configs to produce a final config

Note: if this approach is considered acceptable, i'll update the docs in a followup PR

sqlmesh_path / "config.yml",
sqlmesh_path / "config.yaml",
]
personal_paths = [sqlmesh_path / name for name in YAML_CONFIG_FILENAMES]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I noticed that python config wasnt previously allowed in personal paths, so that's why there is both YAML_CONFIG_FILENAMES and ALL_CONFIG_FILENAMES

Copy link
Member

Choose a reason for hiding this comment

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

There is a reason for this. We can't correctly merge configs if the one in the home folder is a python config.

table = exp.to_table(table_name)
if len(table.parts) == 3 and "." in table.name:
self.execute(exp.select("*").from_(table).limit(0))
if not self._query_job:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is potentially covered by #5153 but I wanted to unblock the build on this PR

@erindru erindru marked this pull request as ready for review August 14, 2025 04:15
# todo: this may format the file differently, is that acceptable?
with project_yaml_path.open("w") as f:
dump(loaded_project_file, f)
from sqlmesh.cli.project_init import init_example_project, ProjectTemplate
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't all these imports be under the check of the file existence? Otherwise doesn't this defeat the purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How do you mean? The sqlmesh module has already been imported by the time init_project_if_required() is called, so these imports are "free"

@erindru erindru force-pushed the erin/load-config-dbt branch from 18ce1a9 to 9db95a1 Compare August 14, 2025 20:08
@erindru erindru merged commit 5bb40a1 into main Aug 14, 2025
26 of 28 checks passed
@erindru erindru deleted the erin/load-config-dbt branch August 14, 2025 20:24
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