Skip to content
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

update to github actions file to meet new demo structure #302

Merged
merged 37 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
72d22c8
update to github actions file to meet new demo structure
sfc-gh-tmathew Nov 19, 2024
7246545
Verifying Snowflake User
sfc-gh-tmathew Nov 20, 2024
c2bf720
testing for demo functionality
sfc-gh-tmathew Nov 21, 2024
c539c1b
Fixing demo by making the config reference correct
sfc-gh-tmathew Nov 22, 2024
5ab793c
testing basics demo
sfc-gh-tmathew Nov 22, 2024
bca27a1
setting up demo config
sfc-gh-tmathew Nov 22, 2024
2f6c220
testing demo scripts
sfc-gh-tmathew Nov 22, 2024
de1a3e2
reverting the password reference
sfc-gh-tmathew Nov 22, 2024
266a712
testing usage of snowflake password
sfc-gh-tmathew Nov 22, 2024
b9879b6
Setting right configs for demo
sfc-gh-tmathew Nov 22, 2024
5b37fa4
Updating change history table creation logic
sfc-gh-tmathew Nov 22, 2024
dae6316
testing dev setup
sfc-gh-tmathew Nov 22, 2024
fd13a23
testing github actions using shell script file
sfc-gh-tmathew Nov 22, 2024
b6e3e36
tweaking scripts
sfc-gh-tmathew Nov 22, 2024
db43352
fix script
sfc-gh-tmathew Nov 22, 2024
59d5288
testing script
sfc-gh-tmathew Nov 22, 2024
04d2ab4
testing scripts
sfc-gh-tmathew Nov 22, 2024
3b65924
testing scripts
sfc-gh-tmathew Nov 22, 2024
02e20d8
testing scripts
sfc-gh-tmathew Nov 22, 2024
4184af3
testing scripts
sfc-gh-tmathew Nov 22, 2024
b3e84b8
testing
sfc-gh-tmathew Nov 22, 2024
9218607
testing scripts
sfc-gh-tmathew Nov 22, 2024
adab2f5
setting working directory
sfc-gh-tmathew Nov 22, 2024
6aba923
setting working directory
sfc-gh-tmathew Nov 22, 2024
3fcdcba
push script update
sfc-gh-tmathew Nov 22, 2024
e482c36
testing bash scripting
sfc-gh-tmathew Nov 22, 2024
c7d0a66
testing shell script
sfc-gh-tmathew Nov 22, 2024
32b1c2c
it helps to use the right file name
sfc-gh-tmathew Nov 22, 2024
9ab568b
testing
sfc-gh-tmathew Nov 22, 2024
e9b6918
testing continues
sfc-gh-tmathew Nov 22, 2024
9c012f6
Testing scripting options
sfc-gh-tmathew Nov 22, 2024
c3b53fa
testing script to revert back to Zane's suggestion
sfc-gh-tmathew Nov 22, 2024
0f73900
update to schemachange config location
sfc-gh-tmathew Nov 22, 2024
62e9478
Pushing pre-final changes
sfc-gh-tmathew Nov 22, 2024
e3a02b3
adding test scenarios in Dev
sfc-gh-tmathew Nov 22, 2024
7e68ecf
testing Deployconfig changes
sfc-gh-tmathew Nov 22, 2024
c05fa56
Leaving code comment to review later
sfc-gh-tmathew Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions .github/workflows/dev-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,22 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Create and populate connections.toml
run: |
echo "Current Directory: ${PWD}"
echo "GITHUB WORKSPACE: ${GITHUB_WORKSPACE}"
chmod +x populateConnection.sh
bash populateConnection.sh
working-directory: .
- name: Test with pytest
id: pytest
run: |
pytest
# Testing Schemachange demo projects
- name: Test Schemachange on ${{ matrix.os }} targeting ${{ env.SNOWFLAKE_DATABASE }}.${{ env.MY_TARGET_SCHEMA }} schema
run: |
echo "::group::Setting up ${MY_TARGET_SCHEMA}"
schemachange deploy --config-folder ./demo/setup/${SCENARIO_NAME}
echo "::endgroup::"
echo "::group::Testing Rendering to ${MY_TARGET_SCHEMA}"
schemachange render --config-folder ./demo/${SCENARIO_NAME} ./demo/${SCENARIO_NAME}/A__render.sql
schemachange render --config-folder ./demo/${SCENARIO_NAME} ./demo/${SCENARIO_NAME}/R__render.sql
schemachange render --config-folder ./demo/${SCENARIO_NAME} ./demo/${SCENARIO_NAME}/V1.0.0__render.sql
echo "::endgroup::"
echo "::group::Testing Deployment using ${MY_TARGET_SCHEMA}"
set +e
schemachange deploy --config-folder ./demo/${SCENARIO_NAME}
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo "Deployment Completed!"
else
echo "Deployment Failed. Proceeding to Teardown."
fi
echo "::endgroup::"
set -e
echo "::group::Tearing down up ${MY_TARGET_SCHEMA}"
schemachange deploy --config-folder ./demo/teardown/${SCENARIO_NAME}
echo "::endgroup::"
if [ $RESULT -ne 0 ]; then
exit 1
fi
echo "Current Directory: ${PWD}"
echo "GITHUB WORKSPACE: ${GITHUB_WORKSPACE}"
chmod +x testSchemachange.sh
bash testSchemachange.sh
working-directory: .
73 changes: 10 additions & 63 deletions .github/workflows/master-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,73 +60,20 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Create and populate connections.toml
run: |
touch ./connections.toml
echo [default] >> ./connections.toml
echo account = \"${SNOWFLAKE_ACCOUNT}\" >> ./connections.toml
echo user = \"${SNOWFLAKE_USER}\" >> ./connections.toml
echo role = \"${SNOWFLAKE_ROLE}\" >> ./connections.toml
echo warehouse = \"${SNOWFLAKE_WAREHOUSE}\" >> ./connections.toml
echo database = \"${SNOWFLAKE_DATABASE}\" >> ./connections.toml
echo password = \"${SNOWFLAKE_PASSWORD}\" >> ./connections.toml
echo "cat connections.toml"
cat ./connections.toml
echo "Current Directory: ${PWD}"
echo "GITHUB WORKSPACE: ${GITHUB_WORKSPACE}"
chmod +x populateConnection.sh
bash populateConnection.sh
working-directory: .
- name: Test with pytest
id: pytest
run: |
pytest
# Testing Schemachange demo projects
- name: Test Schemachange on ${{ matrix.os }} targeting ${{ env.SNOWFLAKE_DATABASE }}.${{ env.MY_TARGET_SCHEMA }} schema
run: |
echo "::group::Setting up ${MY_TARGET_SCHEMA}"
schemachange deploy \
--config-folder ./demo \
--config-file-name schemachange-config-setup.yml \
--root-folder ./demo/${SCENARIO_NAME}/1_setup \
--connection-name default \
--connections-file-path ./connections.toml \
--verbose
echo "::endgroup::"

echo "::group::Testing Rendering to ${MY_TARGET_SCHEMA}"

schemachange render \
--config-folder ./demo/${SCENARIO_NAME} \
./demo/${SCENARIO_NAME}/2_test/A__render.sql
schemachange render \
--config-folder ./demo/${SCENARIO_NAME} \
./demo/${SCENARIO_NAME}/2_test/R__render.sql
schemachange render \
--config-folder ./demo/${SCENARIO_NAME} \
./demo/${SCENARIO_NAME}/2_test/V1.0.0__render.sql
echo "::endgroup::"

echo "::group::Testing Deployment using ${MY_TARGET_SCHEMA}"
set +e
schemachange deploy \
--config-folder ./demo/${SCENARIO_NAME} \
--connection-name default \
--connections-file-path ./connections.toml \
--root-folder ./demo/${SCENARIO_NAME}/2_test \
--verbose
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo "Deployment Completed!"
else
echo "Deployment Failed. Proceeding to Teardown."
fi
echo "::endgroup::"
set -e

echo "::group::Tearing down up ${MY_TARGET_SCHEMA}"
schemachange deploy \
--config-folder ./demo \
--config-file-name schemachange-config-teardown.yml \
--connection-name default \
--connections-file-path ./connections.toml \
--root-folder ./demo/${SCENARIO_NAME}/3_teardown \
--verbose
echo "::endgroup::"

if [ $RESULT -ne 0 ]; then
exit 1
fi
echo "Current Directory: ${PWD}"
echo "GITHUB WORKSPACE: ${GITHUB_WORKSPACE}"
chmod +x testSchemachange.sh
bash testSchemachange.sh
working-directory: .
2 changes: 1 addition & 1 deletion demo/basics_demo/schemachange-config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
config-version: 1

root-folder: "./demo/{{ env_var('SCENARIO_NAME')}}"
root-folder: "./demo/{{ env_var('SCENARIO_NAME')}}/2_test"

change-history-table: "{{ env_var('SNOWFLAKE_DATABASE')}}.{{ env_var('MY_TARGET_SCHEMA')}}.CHANGE_HISTORY"
create-change-history-table: true
Expand Down
2 changes: 0 additions & 2 deletions demo/citibike_demo/schemachange-config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
config-version: 1

root-folder: "./demo/{{ env_var('SCENARIO_NAME')}}"

change-history-table: "{{ env_var('SNOWFLAKE_DATABASE')}}.{{ env_var('MY_TARGET_SCHEMA')}}.CHANGE_HISTORY"
create-change-history-table: true

Expand Down
1 change: 0 additions & 1 deletion demo/citibike_demo_jinja/schemachange-config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
config-version: 1

root-folder: "./demo/{{ env_var('SCENARIO_NAME')}}"
modules-folder: "./demo/{{ env_var('SCENARIO_NAME')}}/modules"

change-history-table: "{{ env_var('SNOWFLAKE_DATABASE')}}.{{ env_var('MY_TARGET_SCHEMA')}}.CHANGE_HISTORY"
Expand Down
2 changes: 0 additions & 2 deletions demo/schemachange-config-setup.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
config-version: 1

root-folder: "./demo/setup/{{ env_var('SCENARIO_NAME')}}"

# tracking the setup step in a different change history table to use schemachange setup and teardown separate from deployment.
change-history-table: "{{ env_var('SNOWFLAKE_DATABASE')}}.SCHEMACHANGE.{{ env_var('SCENARIO_NAME')}}_CHANGE_HISTORY"
create-change-history-table: true
Expand Down
2 changes: 0 additions & 2 deletions demo/schemachange-config-teardown.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
config-version: 1

root-folder: "./demo/teardown/{{ env_var('SCENARIO_NAME')}}"

# tracking the setup step in a different change history table to use schemachange setup and teardown separate from deployment.
change-history-table: "{{ env_var('SNOWFLAKE_DATABASE')}}.SCHEMACHANGE.{{ env_var('SCENARIO_NAME')}}_CHANGE_HISTORY"
create-change-history-table: true
Expand Down
12 changes: 12 additions & 0 deletions populateConnection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Script used in github actions to run test the schemachange functionality against the demo scenarios included in the repository.
touch ./connections.toml
echo [default] >> ./connections.toml
echo account = \"${SNOWFLAKE_ACCOUNT}\" >> ./connections.toml
echo user = \"${SNOWFLAKE_USER}\" >> ./connections.toml
echo role = \"${SNOWFLAKE_ROLE}\" >> ./connections.toml
echo warehouse = \"${SNOWFLAKE_WAREHOUSE}\" >> ./connections.toml
echo database = \"${SNOWFLAKE_DATABASE}\" >> ./connections.toml
echo password = \"${SNOWFLAKE_PASSWORD}\" >> ./connections.toml
echo "cat connections.toml"
cat ./connections.toml
4 changes: 4 additions & 0 deletions schemachange/config/ChangeHistoryTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class ChangeHistoryTable:
@property
def fully_qualified(self) -> str:
return f"{self.database_name}.{self.schema_name}.{self.table_name}"

@property
def fully_qualified_schema_name(self) -> str:
return f"{self.database_name}.{self.schema_name}"

@classmethod
def from_str(cls, table_str: str):
Expand Down
14 changes: 11 additions & 3 deletions schemachange/config/DeployConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

from schemachange.config.BaseConfig import BaseConfig
from schemachange.config.ChangeHistoryTable import ChangeHistoryTable
from schemachange.config.utils import get_snowflake_identifier_string

from schemachange.config.utils import (
get_snowflake_identifier_string,
get_snowflake_password,
)

@dataclasses.dataclass(frozen=True)
class DeployConfig(BaseConfig):
Expand Down Expand Up @@ -82,6 +84,12 @@ def get_session_kwargs(self) -> dict:
"connection_name": self.connection_name,
"change_history_table": self.change_history_table,
"autocommit": self.autocommit,
"query_tag": self.query_tag,
"query_tag": self.query_tag
}

# TODO: Discuss the need for check for snowflake password before passing the session
# kwargs to open a snowflake session
# snowflake_password = get_snowflake_password()
# if snowflake_password is not None and snowflake_password:
# session_kwargs["password"] = snowflake_password
return {k: v for k, v in session_kwargs.items() if v is not None}
2 changes: 1 addition & 1 deletion schemachange/config/get_merged_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from schemachange.config.utils import (
load_yaml_config,
validate_directory,
validate_file_path,
validate_file_path
)


Expand Down
2 changes: 1 addition & 1 deletion schemachange/config/parse_cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def parse_cli_args(args) -> dict:
"-a",
"--snowflake-account",
type=str,
help="The name of the snowflake account (e.g. xy12345.east-us-2.azure)",
help="The name of the snowflake account (e.g. xy12345.east-us-2.azure, xy12345.east-us-2.azure.privatelink, org-accountname, org-accountname.privatelink)",
required=False,
action="deprecate",
)
Expand Down
2 changes: 1 addition & 1 deletion schemachange/session/SnowflakeSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def change_history_schema_exists(self) -> bool:
return row[0] > 0

def create_change_history_schema(self, dry_run: bool) -> None:
query = f"CREATE SCHEMA IF NOT EXISTS {self.change_history_table.schema_name}"
query = f"CREATE SCHEMA IF NOT EXISTS {self.change_history_table.fully_qualified_schema_name}"
if dry_run:
self.logger.debug(
"Running in dry-run mode. Skipping execution.",
Expand Down
57 changes: 57 additions & 0 deletions testSchemachange.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# Script used in github actions to run test the schemachange functionality against the demo scenarios included in the repository.
echo "::group::Setting up ${MY_TARGET_SCHEMA}"
schemachange deploy \
--config-folder ./demo \
--config-file-name schemachange-config-setup.yml \
--root-folder ./demo/${SCENARIO_NAME}/1_setup \
--connection-name default \
--connections-file-path ./connections.toml \
--verbose
echo "::endgroup::"

echo "::group::Testing Rendering to ${MY_TARGET_SCHEMA}"

schemachange render \
--config-folder ./demo/${SCENARIO_NAME} \
./demo/${SCENARIO_NAME}/2_test/A__render.sql
schemachange render \
--config-folder ./demo/${SCENARIO_NAME} \
./demo/${SCENARIO_NAME}/2_test/R__render.sql
schemachange render \
--config-folder ./demo/${SCENARIO_NAME} \
./demo/${SCENARIO_NAME}/2_test/V1.0.0__render.sql
echo "::endgroup::"

echo "::group::Testing Deployment using ${MY_TARGET_SCHEMA}"
set +e
schemachange deploy \
--config-folder ./demo/${SCENARIO_NAME} \
--connection-name default \
--connections-file-path ./connections.toml \
--root-folder ./demo/${SCENARIO_NAME}/2_test \
--verbose
RESULT=$?

if [ $RESULT -eq 0 ]; then
echo "Deployment Completed!"
else
echo "Deployment Failed. Proceeding to Teardown."
fi
echo "::endgroup::"

set -e

echo "::group::Tearing down up ${MY_TARGET_SCHEMA}"
schemachange deploy \
--config-folder ./demo \
--config-file-name schemachange-config-teardown.yml \
--connection-name default \
--connections-file-path ./connections.toml \
--root-folder ./demo/${SCENARIO_NAME}/3_teardown \
--verbose
echo "::endgroup::"

if [ $RESULT -ne 0 ]; then
exit 1
fi