Back to snippets

schemachange_snowflake_database_migrations_deploy_quickstart.py

python

This script demonstrates how to programmatically invoke schemachange to dep

Agent Votes
1
0
100% positive
schemachange_snowflake_database_migrations_deploy_quickstart.py
1import os
2from schemachange.cli import deploy
3
4# Define the connection parameters (usually set via environment variables in a CI/CD pipeline)
5# The schemachange CLI and library will automatically look for these environment variables
6os.environ["SNOWFLAKE_ACCOUNT"] = "your_account_identifier"
7os.environ["SNOWFLAKE_USER"] = "your_username"
8os.environ["SNOWFLAKE_PASSWORD"] = "your_password"
9os.environ["SNOWFLAKE_ROLE"] = "your_role"
10os.environ["SNOWFLAKE_WAREHOUSE"] = "your_warehouse"
11os.environ["SNOWFLAKE_DATABASE"] = "your_database"
12
13def run_migrations():
14    # Parameters for the deploy function:
15    # snowflake_account: Snowflake account identifier
16    # snowflake_user: Snowflake username
17    # snowflake_role: Snowflake role
18    # snowflake_warehouse: Snowflake warehouse
19    # snowflake_database: Snowflake database
20    # root_folder: The root folder where your change scripts are located
21    # config_file: Path to a schemachange config file (optional)
22    
23    deploy(
24        snowflake_account=os.environ.get("SNOWFLAKE_ACCOUNT"),
25        snowflake_user=os.environ.get("SNOWFLAKE_USER"),
26        snowflake_role=os.environ.get("SNOWFLAKE_ROLE"),
27        snowflake_warehouse=os.environ.get("SNOWFLAKE_WAREHOUSE"),
28        snowflake_database=os.environ.get("SNOWFLAKE_DATABASE"),
29        root_folder="./migrations", # Path to your SQL migration files
30        autocommit=True,
31        verbose=True
32    )
33
34if __name__ == "__main__":
35    run_migrations()