Skip to content

Commit 438315b

Browse files
Fix: Make dialect in dbt init noncompulsory again (#4087)
1 parent badba08 commit 438315b

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

docs/integrations/dbt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Learn more about [SQLMesh installation and extras here](../installation.md#insta
4141
Prepare an existing dbt project to be run by SQLMesh by executing the `sqlmesh init` command *within the dbt project root directory* and with the `dbt` template option:
4242

4343
```bash
44-
$ sqlmesh init -t dbt <dialect> # e.g. sqlmesh init -t dbt snowflake
44+
$ sqlmesh init -t dbt
4545
```
4646

4747
SQLMesh will use the data warehouse connection target in your dbt project `profiles.yml` file. The target can be changed at any time.

sqlmesh/cli/example_project.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ def _gen_config(
2828
start: t.Optional[str],
2929
template: ProjectTemplate,
3030
) -> str:
31-
if not settings:
31+
connection_settings = (
32+
settings
33+
or """ type: duckdb
34+
database: db.db"""
35+
)
36+
37+
if not settings and template != ProjectTemplate.DBT:
3238
doc_link = "https://sqlmesh.readthedocs.io/en/stable/integrations/engines{engine_link}"
3339
engine_link = ""
3440

@@ -69,8 +75,6 @@ def _gen_config(
6975
" # https://sqlmesh.readthedocs.io/en/stable/reference/configuration/#connections\n"
7076
f" # {doc_link.format(engine_link=engine_link)}\n{connection_settings}"
7177
)
72-
else:
73-
connection_settings = settings
7478

7579
default_configs = {
7680
ProjectTemplate.DEFAULT: f"""gateways:

tests/cli/test_cli.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,3 +1614,24 @@ def test_state_import_local(runner: CliRunner, tmp_path: Path) -> None:
16141614
assert result.exit_code == 1
16151615
assert "State file is marked as not importable" in result.output
16161616
assert "Aborting" in result.output
1617+
1618+
1619+
def test_dbt_init(tmp_path):
1620+
# The dbt init project doesn't require a dialect
1621+
init_example_project(tmp_path, dialect=None, template=ProjectTemplate.DBT)
1622+
1623+
config_path = tmp_path / "config.py"
1624+
assert config_path.exists()
1625+
1626+
with open(config_path) as file:
1627+
config = file.read()
1628+
1629+
assert (
1630+
config
1631+
== """from pathlib import Path
1632+
1633+
from sqlmesh.dbt.loader import sqlmesh_config
1634+
1635+
config = sqlmesh_config(Path(__file__).parent)
1636+
"""
1637+
)

0 commit comments

Comments
 (0)