-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor post deploy hooks to use sql facade and clean up tests with factories #1804
Open
sfc-gh-mchok
wants to merge
2
commits into
main
Choose a base branch
from
mchok-migrate-post-deploy-scripts-to-sqlfacade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from contextlib import contextmanager | ||
from pathlib import Path | ||
from textwrap import dedent | ||
from typing import List, Literal, Optional, Union | ||
|
@@ -44,7 +43,6 @@ | |
from snowflake.cli._plugins.stage.diff import DiffResult | ||
from snowflake.cli._plugins.stage.manager import StageManager | ||
from snowflake.cli._plugins.workspace.context import ActionContext | ||
from snowflake.cli.api.cli_global_context import get_cli_context | ||
from snowflake.cli.api.entities.common import EntityBase, get_sql_executor | ||
from snowflake.cli.api.entities.utils import ( | ||
drop_generic_object, | ||
|
@@ -55,7 +53,6 @@ | |
) | ||
from snowflake.cli.api.errno import DOES_NOT_EXIST_OR_NOT_AUTHORIZED | ||
from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError | ||
from snowflake.cli.api.metrics import CLICounterField | ||
from snowflake.cli.api.project.schemas.entities.common import ( | ||
EntityModelBase, | ||
Identifier, | ||
|
@@ -596,8 +593,8 @@ def _deploy( | |
print_diff=print_diff, | ||
) | ||
|
||
if run_post_deploy_hooks: | ||
self.execute_post_deploy_hooks() | ||
if run_post_deploy_hooks: | ||
self.execute_post_deploy_hooks() | ||
Comment on lines
+596
to
+597
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this will be calling use_role through the sql facade, we don't need to nest it inside the above context manager |
||
|
||
if validate: | ||
self.validate_setup_script( | ||
|
@@ -859,27 +856,6 @@ def verify_project_distribution( | |
return False | ||
return True | ||
|
||
@contextmanager | ||
def use_package_warehouse(self): | ||
model = self._entity_model | ||
ctx = self._workspace_ctx | ||
package_warehouse = ( | ||
model.meta and model.meta.warehouse and to_identifier(model.meta.warehouse) | ||
) or to_identifier(ctx.default_warehouse) | ||
|
||
if package_warehouse: | ||
with get_sql_executor().use_warehouse(package_warehouse): | ||
yield | ||
else: | ||
raise ClickException( | ||
dedent( | ||
f"""\ | ||
Application package warehouse cannot be empty. | ||
Please provide a value for it in your connection information or your project definition file. | ||
""" | ||
) | ||
) | ||
|
||
def create_app_package(self) -> None: | ||
""" | ||
Creates the application package with our up-to-date stage if none exists. | ||
|
@@ -932,23 +908,23 @@ def execute_post_deploy_hooks(self): | |
workspace_ctx = self._workspace_ctx | ||
console = workspace_ctx.console | ||
project_root = workspace_ctx.project_root | ||
package_role = (model.meta and model.meta.role) or workspace_ctx.default_role | ||
package_warehouse = ( | ||
model.meta and model.meta.warehouse | ||
) or workspace_ctx.default_warehouse | ||
package_name = model.fqn.identifier | ||
post_deploy_hooks = model.meta and model.meta.post_deploy | ||
|
||
get_cli_context().metrics.set_counter_default( | ||
CLICounterField.POST_DEPLOY_SCRIPTS, 0 | ||
execute_post_deploy_hooks( | ||
console=console, | ||
project_root=project_root, | ||
post_deploy_hooks=post_deploy_hooks, | ||
deployed_object_type="application package", | ||
role_name=package_role, | ||
warehouse_name=package_warehouse, | ||
database_name=package_name, | ||
) | ||
|
||
if post_deploy_hooks: | ||
with self.use_package_warehouse(): | ||
execute_post_deploy_hooks( | ||
console=console, | ||
project_root=project_root, | ||
post_deploy_hooks=post_deploy_hooks, | ||
deployed_object_type="application package", | ||
database_name=package_name, | ||
) | ||
|
||
def validate_setup_script( | ||
self, use_scratch_stage: bool, interactive: bool, force: bool | ||
): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should rebase on top of Frank's latest work (expect conflicts though, but it will make your job easier overall)