Skip to content

Commit f5ad96e

Browse files
feat: [SNOW-1890085] dbt deploy: provide main file param
1 parent 5e0a2f8 commit f5ad96e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/snowflake/cli/_plugins/dbt/manager.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ def deploy(
5353
force: bool,
5454
) -> SnowflakeCursor:
5555
# TODO: what to do with force?
56-
if not path.joinpath("dbt_project.yml").exists():
56+
dbt_project_path = path.joinpath("dbt_project.yml")
57+
if not dbt_project_path.exists():
5758
raise ClickException(f"dbt_project.yml does not exist in provided path.")
5859

5960
if dbt_version is None:
60-
with path.joinpath("dbt_project.yml").open() as fd:
61+
with dbt_project_path.open() as fd:
6162
dbt_project_config = yaml.safe_load(fd)
6263
try:
6364
dbt_version = dbt_project_config["version"]
@@ -77,11 +78,18 @@ def deploy(
7778
cli_console.step(f"Copied {len(results)} files")
7879

7980
with cli_console.phase("Creating DBT project"):
80-
query = f"CREATE OR REPLACE DBT PROJECT {name} FROM {stage_name} DBT_VERSION='{dbt_version}' DBT_ADAPTER_VERSION='{dbt_adapter_version}'"
81+
staged_dbt_project_path = self._get_dbt_project_stage_path(stage_name)
82+
query = f"""CREATE OR REPLACE DBT PROJECT {name}
83+
FROM {stage_name} MAIN_FILE='{staged_dbt_project_path}'
84+
DBT_VERSION='{dbt_version}' DBT_ADAPTER_VERSION='{dbt_adapter_version}'"""
8185
return self.execute_query(query)
8286

8387
def execute(self, dbt_command: str, name: str, *dbt_cli_args):
8488
query = f"EXECUTE DBT PROJECT {name} {dbt_command}"
8589
if dbt_cli_args:
8690
query += " " + " ".join([arg for arg in dbt_cli_args])
8791
return self.execute_query(query)
92+
93+
@staticmethod
94+
def _get_dbt_project_stage_path(stage_name):
95+
return "/".join([stage_name, "dbt_project.yml"])

tests/dbt/test_dbt_commands.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ def test_deploys_project_from_source(
7373
assert result.exit_code == 0, result.output
7474
assert (
7575
mock_connect.mocked_ctx.get_query()
76-
== "CREATE OR REPLACE DBT PROJECT TEST_PIPELINE FROM @MockDatabase.MockSchema.dbt_TEST_PIPELINE_stage DBT_VERSION='1.2.3' DBT_ADAPTER_VERSION='3.4.5'"
76+
== """CREATE OR REPLACE DBT PROJECT TEST_PIPELINE
77+
FROM @MockDatabase.MockSchema.dbt_TEST_PIPELINE_stage MAIN_FILE='@MockDatabase.MockSchema.dbt_TEST_PIPELINE_stage/dbt_project.yml'
78+
DBT_VERSION='1.2.3' DBT_ADAPTER_VERSION='3.4.5'"""
7779
)
7880
stage_fqn = FQN.from_string(f"dbt_TEST_PIPELINE_stage").using_context()
7981
mock_create.assert_called_once_with(stage_fqn, temporary=True)
@@ -100,7 +102,9 @@ def test_dbt_version_from_option_has_precedence_over_file(
100102
assert result.exit_code == 0, result.output
101103
assert (
102104
mock_connect.mocked_ctx.get_query()
103-
== "CREATE OR REPLACE DBT PROJECT TEST_PIPELINE FROM @MockDatabase.MockSchema.dbt_TEST_PIPELINE_stage DBT_VERSION='2.3.4' DBT_ADAPTER_VERSION='3.4.5'"
105+
== """CREATE OR REPLACE DBT PROJECT TEST_PIPELINE
106+
FROM @MockDatabase.MockSchema.dbt_TEST_PIPELINE_stage MAIN_FILE='@MockDatabase.MockSchema.dbt_TEST_PIPELINE_stage/dbt_project.yml'
107+
DBT_VERSION='2.3.4' DBT_ADAPTER_VERSION='3.4.5'"""
104108
)
105109

106110
def test_raises_when_dbt_project_is_not_available(

0 commit comments

Comments
 (0)