Skip to content

Commit 5e0a2f8

Browse files
feat: [SNOW-1890085] dbt deploy: add support for dbt-adapter-version flag
1 parent be94439 commit 5e0a2f8

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def deploy_dbt(
7070
None,
7171
help="Version of dbt tool to be used. Taken from dbt_project.yml if not provided.",
7272
),
73+
dbt_adapter_version: str = typer.Option(
74+
help="dbt-snowflake adapter version to be used",
75+
),
7376
**options,
7477
) -> CommandResult:
7578
"""
@@ -81,7 +84,9 @@ def deploy_dbt(
8184
else:
8285
path = Path(source)
8386
return QueryResult(
84-
DBTManager().deploy(path.resolve(), name, dbt_version, force=force)
87+
DBTManager().deploy(
88+
path.resolve(), name, dbt_version, dbt_adapter_version, force=force
89+
)
8590
)
8691

8792

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ def list(self) -> SnowflakeCursor: # noqa: A003
4545
return self.execute_query(query)
4646

4747
def deploy(
48-
self, path: Path, name: FQN, dbt_version: Optional[str], force: bool
48+
self,
49+
path: Path,
50+
name: FQN,
51+
dbt_version: Optional[str],
52+
dbt_adapter_version: str,
53+
force: bool,
4954
) -> SnowflakeCursor:
5055
# TODO: what to do with force?
5156
if not path.joinpath("dbt_project.yml").exists():
@@ -72,7 +77,7 @@ def deploy(
7277
cli_console.step(f"Copied {len(results)} files")
7378

7479
with cli_console.phase("Creating DBT project"):
75-
query = f"CREATE OR REPLACE DBT PROJECT {name} FROM {stage_name} DBT_VERSION='{dbt_version}'"
80+
query = f"CREATE OR REPLACE DBT PROJECT {name} FROM {stage_name} DBT_VERSION='{dbt_version}' DBT_ADAPTER_VERSION='{dbt_adapter_version}'"
7681
return self.execute_query(query)
7782

7883
def execute(self, dbt_command: str, name: str, *dbt_cli_args):

tests/dbt/test_dbt_commands.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,19 @@ def test_deploys_project_from_source(
6161
):
6262

6363
result = runner.invoke(
64-
["dbt", "deploy", "TEST_PIPELINE", f"--source={dbt_project_path}"]
64+
[
65+
"dbt",
66+
"deploy",
67+
"TEST_PIPELINE",
68+
f"--source={dbt_project_path}",
69+
"--dbt-adapter-version=3.4.5",
70+
]
6571
)
6672

6773
assert result.exit_code == 0, result.output
6874
assert (
6975
mock_connect.mocked_ctx.get_query()
70-
== "CREATE OR REPLACE DBT PROJECT TEST_PIPELINE FROM @MockDatabase.MockSchema.dbt_TEST_PIPELINE_stage DBT_VERSION='1.2.3'"
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'"
7177
)
7278
stage_fqn = FQN.from_string(f"dbt_TEST_PIPELINE_stage").using_context()
7379
mock_create.assert_called_once_with(stage_fqn, temporary=True)
@@ -87,13 +93,14 @@ def test_dbt_version_from_option_has_precedence_over_file(
8793
"TEST_PIPELINE",
8894
f"--source={dbt_project_path}",
8995
"--dbt-version=2.3.4",
96+
"--dbt-adapter-version=3.4.5",
9097
]
9198
)
9299

93100
assert result.exit_code == 0, result.output
94101
assert (
95102
mock_connect.mocked_ctx.get_query()
96-
== "CREATE OR REPLACE DBT PROJECT TEST_PIPELINE FROM @MockDatabase.MockSchema.dbt_TEST_PIPELINE_stage DBT_VERSION='2.3.4'"
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'"
97104
)
98105

99106
def test_raises_when_dbt_project_is_not_available(
@@ -103,7 +110,13 @@ def test_raises_when_dbt_project_is_not_available(
103110
dbt_file.unlink()
104111

105112
result = runner.invoke(
106-
["dbt", "deploy", "TEST_PIPELINE", f"--source={dbt_project_path}"]
113+
[
114+
"dbt",
115+
"deploy",
116+
"TEST_PIPELINE",
117+
f"--source={dbt_project_path}",
118+
"--dbt-adapter-version=3.4.5",
119+
],
107120
)
108121

109122
assert result.exit_code == 1, result.output
@@ -118,7 +131,13 @@ def test_raises_when_dbt_project_version_is_not_specified(
118131
yaml.dump({}, fd)
119132

120133
result = runner.invoke(
121-
["dbt", "deploy", "TEST_PIPELINE", f"--source={dbt_project_path}"]
134+
[
135+
"dbt",
136+
"deploy",
137+
"TEST_PIPELINE",
138+
f"--source={dbt_project_path}",
139+
"--dbt-adapter-version=3.4.5",
140+
]
122141
)
123142

124143
assert result.exit_code == 1, result.output

0 commit comments

Comments
 (0)