Keep Snowflake SQL objects in Git and track every change with repeatable, idempotent scripts.
Version control prevents silent changes, enables code review, and lets teams roll back broken logic quickly. Treat SQL like application code for faster, safer releases.
Store CREATE OR REPLACE statements for tables, views, stages, procedures, and user-defined functions. Exclude transient data loads and one-off ad-hoc queries.
Organize scripts by object type (/tables
, /views
, /procedures
). Prefix files with incremental numbers so CI runs them in order (001_create_customers.sql
, 002_create_orders.sql
).
Use GitHub Actions, GitLab CI, or CircleCI. Configure a job that runs the SnowSQL CLI with your connection secrets to execute every changed script in pull requests and on merge to main
.
# .github/workflows/snowflake.yml
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install SnowSQL
run: sudo apt-get install -y snowflake-cli
- name: Run SQL scripts
env:
SNOWSQL_ACCOUNT: ${{ secrets.SF_ACCOUNT }}
SNOWSQL_USER: ${{ secrets.SF_USER }}
SNOWSQL_PWD: ${{ secrets.SF_PASSWORD }}
run: |
for file in $(git diff --name-only $GITHUB_SHA $GITHUB_BASE_SHA | grep .sql); do
snowsql -f $file
done
Add a comment header to each object. Example: CREATE OR REPLACE VIEW analytics.v_customer_orders /* v1.3 */ AS ...
. Query SHOW VIEWS
to audit versions.
Keep scripts idempotent (CREATE OR REPLACE
). Store sample data loads separately. Enforce reviews before merging to main
. Tag releases in Git to match production deploys.
Editing objects directly in the Snowflake UI (bypasses review) and committing compiled objects (like DESCRIBE
output) cause merge conflicts.
Yes. Both tools support Snowflake and manage migrations, checksums, and rollbacks automatically. Point them at your .sql
files and configure Snowflake drivers.
Create a new script that restores the previous DDL or reverts data fixes. Tag the rollback commit and redeploy via CI.
Less critical, but saving repeatable ad-hoc analysis in a "sandbox" folder promotes reuse and transparency.