Snowflake CI/CD: Lint, Test, and Deploy Schema Migrations
This guide sets up a CI/CD pipeline for Snowflake schema migrations on GitHub Actions, using the versioned workflow. The pipeline:
- Lints new migration files on every pull request.
- Pushes the migration directory to the Schema Registry when a change is merged to the default branch.
- Applies pending migrations to staging, then to production after an approval.
The pipeline follows the GitHub Actions guide, with changes for how Snowflake works:
- Snowflake does not run in Docker, so there is no
docker://dev database.lintandpushuse dev databases on your Snowflake account, owned by a role that can reach nothing else. - Atlas takes no lock on Snowflake, so two deployments to one database are not serialized. Each target
database gets its own GitHub
concurrencygroup. - Snowflake commits every DDL statement on its own, so a file that fails halfway stays half applied. Therefore, running jobs are never cancelled, and migration files stay small.
- Every
lintandpushrun executes DDL on the dev database, and Snowflake DDL is slow, so jobs get generous timeouts.
For connection URLs, inspection, and the workflows themselves, start with Getting Started with Snowflake.
For GitLab, Azure DevOps, Jenkins, CircleCI, or Bitbucket, see Other CI/CD Platforms.
Prerequisites
The Snowflake driver is available to Pro users. Run atlas login to log in, or to start a free trial.
- A Snowflake account, and a user that can use the
SYSADMINandSECURITYADMINroles to create the databases, roles, and users. - A GitHub repository with the
migrations/migration directory, and environments with environment secrets and deployment branches. On a private repository, these need GitHub Pro, GitHub Team, or GitHub Enterprise, and required reviewers need GitHub Enterprise.
Installing Atlas
The Snowflake driver ships in the extended build of Atlas:
- macOS + Linux
- Docker
- Windows
To download and install the custom release of the Atlas CLI, simply run the following in your terminal:
curl -sSf https://atlasgo.sh | ATLAS_FLAVOR="snowflake" sh
To pull the Atlas image and run it as a Docker container:
docker pull arigaio/atlas:latest-extended
docker run --rm arigaio/atlas:latest-extended --help
If the container needs access to the host network or a local directory, use the --net=host flag and mount the desired
directory:
docker run --rm --net=host \
-v $(pwd)/migrations:/migrations \
arigaio/atlas:latest-extended migrate apply \
--url "oracle://PDBADMIN:Pssw0rd0995@localhost:1521/FREEPDB1"
Download the custom release and move the atlas binary to a file location on your system PATH.
Then log in to your Atlas Cloud organization:
atlas login
Installing the agent skills
To set up the pipeline with a coding agent, install the Atlas agent skills. One command installs them:
- Claude Code
- OpenAI Codex
- Cursor
- GitHub Copilot
Install the skills from a terminal. It installs the Atlas plugin, with all its skills, for every project on this machine.
claude plugin marketplace add ariga/atlas
claude plugin install atlas@ariga
Then start the onboarding skill in Claude Code. See Claude Code with Atlas for the other ways to use the skills.
/atlas:atlas-onboard
Install the skills from a terminal. Run it from the repository root. It installs every Atlas skill in .agents/skills/.
npx skills add ariga/atlas -a codex -y
Then start the onboarding skill in OpenAI Codex. See OpenAI Codex with Atlas for the other ways to use the skills.
$atlas-onboard
Install the skills from a terminal. Run it from the repository root. It installs every Atlas skill in .agents/skills/.
npx skills add ariga/atlas -a cursor -y
Then start the onboarding skill in Cursor. See Cursor with Atlas for the other ways to use the skills.
/atlas-onboard
Install the skills from a terminal. Run it from the repository root. It installs every Atlas skill in .agents/skills/.
npx skills add ariga/atlas -a github-copilot -y
Then start the onboarding skill in GitHub Copilot. See GitHub Copilot with Atlas for the other ways to use the skills.
/atlas-onboard
Three of them cover this pipeline, and the agent loads each one on its own when the task needs it:
atlas-actionwrites and fixes the workflow file for GitHub Actions and the other CI/CD platforms.atlas-snowflakeadds the Snowflake rules this guide follows: the dev database on your account, matching URL scopes, one deployment at a time, and time budgets for slow planning.atlas-onboardtakes a project without Atlas from the first export to production. Its CI, staging, and production stages build the same pipeline as this guide.
The agent never asks for tokens or database URLs. You create the Snowflake roles and users, store the
secrets, and run the first production deployment. Before it reports a change done, the agent lints it
and runs atlas migrate test on the dev database.
Creating a bot token
CI authenticates to Atlas Cloud with a bot token. In your GitHub repository, go to
Settings -> Secrets and variables -> Actions and store it as a repository secret named
ATLAS_CLOUD_TOKEN.
If your organization turns on protected flows for new repositories, give the bot the Writer role in the repository's settings after the first push.
Setting Up Snowflake
The pipeline uses a separate Snowflake identity for each kind of job. The steps below create them:
- The
ATLAS_CIrole and itsATLAS_CI_USERservice user run lint on pull requests and push on the default branch. The role owns the dev databasesAPP_DEVandAPP_DEV_MAIN. - A role and service user per target database, such as
ATLAS_DEPLOY_STAGINGandATLAS_DEPLOY_STAGING_USERforAPP_STAGING.
Choose the sign-in method before you run the SQL. With workload identity federation, each job signs in
as its own user, so skip the CREATE USER statements in Dev databases and
Deploy roles, create the roles, and create the users in
Authentication.
A job that runs on a pull request runs the pull request's workflow file and atlas.hcl, so anyone who
can push a branch can read the secrets that job gets. Pull request jobs therefore get only the dev
database credentials, and the role behind them owns the dev databases and nothing else.
Storing the URLs as Secrets keeps the target URLs in GitHub environments
that pull request jobs cannot read.
Dev databases
The dev database is an empty database that
Atlas uses to replay and check migrations. It must be dedicated to Atlas, and two jobs must not use it
at the same time. The pipeline uses two: APP_DEV for pull requests and APP_DEV_MAIN for the
default branch, so a queue of pull request runs never delays a deployment
(Running one job at a time explains why).
Run the following as a user that can use SYSADMIN and SECURITYADMIN:
-- A warehouse for Atlas.
USE ROLE SYSADMIN;
CREATE WAREHOUSE ATLAS_WH
WAREHOUSE_SIZE = XSMALL
AUTO_SUSPEND = 60
AUTO_RESUME = TRUE
INITIALLY_SUSPENDED = TRUE;
-- The dev databases.
CREATE DATABASE APP_DEV;
CREATE DATABASE APP_DEV_MAIN;
-- The CI role owns the dev databases and their PUBLIC schemas.
USE ROLE SECURITYADMIN;
CREATE ROLE ATLAS_CI;
GRANT ROLE ATLAS_CI TO ROLE SYSADMIN;
GRANT USAGE ON WAREHOUSE ATLAS_WH TO ROLE ATLAS_CI;
GRANT OWNERSHIP ON DATABASE APP_DEV TO ROLE ATLAS_CI;
GRANT OWNERSHIP ON SCHEMA APP_DEV.PUBLIC TO ROLE ATLAS_CI;
GRANT OWNERSHIP ON DATABASE APP_DEV_MAIN TO ROLE ATLAS_CI;
GRANT OWNERSHIP ON SCHEMA APP_DEV_MAIN.PUBLIC TO ROLE ATLAS_CI;
-- A service user for CI. Remove if using workload identity federation.
CREATE USER ATLAS_CI_USER
TYPE = SERVICE
DEFAULT_ROLE = ATLAS_CI
DEFAULT_WAREHOUSE = ATLAS_WH;
GRANT ROLE ATLAS_CI TO USER ATLAS_CI_USER;
ATLAS_CI needs to create every kind of object your migrations create. If a migration references an
object outside the dev database, such as the warehouse of a dynamic table, grant ATLAS_CI access to
it too.
Deploy roles
Each target database gets its own role and service user. For a new staging database:
USE ROLE SYSADMIN;
CREATE DATABASE APP_STAGING;
USE ROLE SECURITYADMIN;
CREATE ROLE ATLAS_DEPLOY_STAGING;
GRANT ROLE ATLAS_DEPLOY_STAGING TO ROLE SYSADMIN;
GRANT USAGE ON WAREHOUSE ATLAS_WH TO ROLE ATLAS_DEPLOY_STAGING;
GRANT OWNERSHIP ON DATABASE APP_STAGING TO ROLE ATLAS_DEPLOY_STAGING;
GRANT OWNERSHIP ON SCHEMA APP_STAGING.PUBLIC TO ROLE ATLAS_DEPLOY_STAGING;
-- Remove if using workload identity federation.
CREATE USER ATLAS_DEPLOY_STAGING_USER
TYPE = SERVICE
DEFAULT_ROLE = ATLAS_DEPLOY_STAGING
DEFAULT_WAREHOUSE = ATLAS_WH;
GRANT ROLE ATLAS_DEPLOY_STAGING TO USER ATLAS_DEPLOY_STAGING_USER;
Repeat this for production with APP_PROD, ATLAS_DEPLOY_PROD, and ATLAS_DEPLOY_PROD_USER.
For an existing database, the deploy role needs to own the objects the migrations alter: transfer them
with GRANT OWNERSHIP ... COPY CURRENT GRANTS. An existing database also needs a
baseline migration before its first deployment.
Authentication
Service users sign in with workload identity federation, a key pair, or a programmatic access token. Atlas takes each one in the connection URL. Snowflake recommends workload identity federation for service users: GitHub issues each job a short-lived token, and no Snowflake credential is stored in GitHub.
- Workload identity federation
- Key pair
- Programmatic access token
With workload identity federation, Snowflake matches the subject of the job's GitHub OIDC token to
one service user. GitHub sets a different subject for pull requests, for pushes to a branch, and for
jobs that run in an environment, so each job gets its own user. Create these users in place of the
CREATE USER statements above, replacing <owner>/<repo> with your repository:
USE ROLE SECURITYADMIN;
-- lint, on pull requests.
CREATE USER ATLAS_CI_PR_USER
WORKLOAD_IDENTITY = (
TYPE = OIDC
ISSUER = 'https://token.actions.githubusercontent.com'
SUBJECT = 'repo:<owner>/<repo>:pull_request'
)
TYPE = SERVICE;
GRANT ROLE ATLAS_CI TO USER ATLAS_CI_PR_USER;
-- push, on the default branch.
CREATE USER ATLAS_CI_MAIN_USER
WORKLOAD_IDENTITY = (
TYPE = OIDC
ISSUER = 'https://token.actions.githubusercontent.com'
SUBJECT = 'repo:<owner>/<repo>:ref:refs/heads/master'
)
TYPE = SERVICE;
GRANT ROLE ATLAS_CI TO USER ATLAS_CI_MAIN_USER;
-- deploy-staging, in the staging environment.
CREATE USER ATLAS_DEPLOY_STAGING_USER
WORKLOAD_IDENTITY = (
TYPE = OIDC
ISSUER = 'https://token.actions.githubusercontent.com'
SUBJECT = 'repo:<owner>/<repo>:environment:staging'
)
TYPE = SERVICE;
GRANT ROLE ATLAS_DEPLOY_STAGING TO USER ATLAS_DEPLOY_STAGING_USER;
-- deploy-production, in the production environment.
CREATE USER ATLAS_DEPLOY_PROD_USER
WORKLOAD_IDENTITY = (
TYPE = OIDC
ISSUER = 'https://token.actions.githubusercontent.com'
SUBJECT = 'repo:<owner>/<repo>:environment:production'
)
TYPE = SERVICE;
GRANT ROLE ATLAS_DEPLOY_PROD TO USER ATLAS_DEPLOY_PROD_USER;
The production user accepts only tokens from jobs that run in the production environment, so the
environment's branch rules and required reviewers also guard the Snowflake sign-in.
The subject must match the one GitHub sends exactly. Some organizations and repositories send a
different format, such as one with owner and repository IDs
(repo:<owner>@<owner_id>/<repo>@<repo_id>:pull_request) or a custom subject template. If a job fails
with error 394729 (Either the subject or issuer claims were not recognized), the error message
shows the subject GitHub sent. Set it on the job's user, and use the same format for the other users:
ALTER USER ATLAS_CI_PR_USER SET WORKLOAD_IDENTITY = (
TYPE = OIDC
ISSUER = 'https://token.actions.githubusercontent.com'
SUBJECT = '<subject from the error>'
);
The URLs you store as secrets hold no credential. Each job requests a token from GitHub at run time and appends it to the URL. The workload identity federation tab of the workflow does this in every job. Pull requests from forks cannot request a token, as they cannot read secrets.
Generate a key pair for each service user, register the public key with the user, and encode the private key, as described in the Snowflake tab of the URL documentation. The encoded private key goes in the user's URL when you store it as a secret.
Generate a programmatic access token for each service user. The token goes in the user's URL when you store it as a secret.
By default, Snowflake accepts a service user's programmatic access token only from the IP addresses of a network policy, and GitHub-hosted runners have no fixed addresses. See Snowflake's documentation on programmatic access tokens for the network policy requirements.
Storing the URLs as Secrets
The pipeline reads one URL per database. The dev URLs are repository secrets, and the target URLs are
environment secrets. Both environments name their secret SNOWFLAKE_URL, so each deploy job reads the
URL of the environment it runs in.
Each URL names a database and no schema (database scope), so Atlas covers every
schema in it, and migration files use qualified names such as "PUBLIC"."USERS". To manage a single
schema instead, add the schema to every URL, for example APP_DEV/PUBLIC and APP_STAGING/PUBLIC. The
dev URLs and the target URLs must always have the same scope.
Creating the environments
In your GitHub repository, go to Settings -> Environments -> New environment and create:
staging: under Deployment branches and tags, select Selected branches and tags and add your default branch.production: limit the deployment branches the same way, and add required reviewers, so every production deployment waits for an approval.
A job gets an environment's secrets only when it names the environment and runs on a branch the environment allows. Pull requests never see the target URLs.
Without required reviewers on production, deploy-production runs right after deploy-staging, and
every merge reaches production without an approval. On a private repository, required reviewers need
GitHub Enterprise. Without them, run production deployments from a
manual workflow instead.
Adding the secrets
Add each secret below with the value for your sign-in method:
- Repository secrets: Settings -> Secrets and variables -> Actions -> New repository secret.
- Environment secrets: Settings -> Environments -> the environment -> Add environment secret.
| Secret | Where | Database | Role |
|---|---|---|---|
SNOWFLAKE_DEV_URL | Repository | APP_DEV | ATLAS_CI |
SNOWFLAKE_DEV_URL_MAIN | Repository | APP_DEV_MAIN | ATLAS_CI |
SNOWFLAKE_URL | staging environment | APP_STAGING | ATLAS_DEPLOY_STAGING |
SNOWFLAKE_URL | production environment | APP_PROD | ATLAS_DEPLOY_PROD |
In every value, replace <account_identifier> with your Snowflake account identifier. In Snowsight, it
is under your avatar -> Connect a tool to Snowflake -> Account Identifier.
- Workload identity federation
- Key pair
- Programmatic access token
The values hold no credential: each job appends its token at run time, as described in Authentication.
Repository secret SNOWFLAKE_DEV_URL, for pull requests:
snowflake://ATLAS_CI_PR_USER@<account_identifier>/APP_DEV?warehouse=ATLAS_WH&role=ATLAS_CI&authenticator=WORKLOAD_IDENTITY&workloadIdentityProvider=OIDC
Repository secret SNOWFLAKE_DEV_URL_MAIN, for the default branch:
snowflake://ATLAS_CI_MAIN_USER@<account_identifier>/APP_DEV_MAIN?warehouse=ATLAS_WH&role=ATLAS_CI&authenticator=WORKLOAD_IDENTITY&workloadIdentityProvider=OIDC
SNOWFLAKE_URL in the staging environment:
snowflake://ATLAS_DEPLOY_STAGING_USER@<account_identifier>/APP_STAGING?warehouse=ATLAS_WH&role=ATLAS_DEPLOY_STAGING&authenticator=WORKLOAD_IDENTITY&workloadIdentityProvider=OIDC
SNOWFLAKE_URL in the production environment:
snowflake://ATLAS_DEPLOY_PROD_USER@<account_identifier>/APP_PROD?warehouse=ATLAS_WH&role=ATLAS_DEPLOY_PROD&authenticator=WORKLOAD_IDENTITY&workloadIdentityProvider=OIDC
Each value holds the encoded private key of its user.
Repository secret SNOWFLAKE_DEV_URL, for pull requests:
snowflake://ATLAS_CI_USER@<account_identifier>/APP_DEV?warehouse=ATLAS_WH&role=ATLAS_CI&authenticator=SNOWFLAKE_JWT&privateKey=<ci_private_key>
Repository secret SNOWFLAKE_DEV_URL_MAIN, for the default branch:
snowflake://ATLAS_CI_USER@<account_identifier>/APP_DEV_MAIN?warehouse=ATLAS_WH&role=ATLAS_CI&authenticator=SNOWFLAKE_JWT&privateKey=<ci_private_key>
SNOWFLAKE_URL in the staging environment:
snowflake://ATLAS_DEPLOY_STAGING_USER@<account_identifier>/APP_STAGING?warehouse=ATLAS_WH&role=ATLAS_DEPLOY_STAGING&authenticator=SNOWFLAKE_JWT&privateKey=<staging_private_key>
SNOWFLAKE_URL in the production environment:
snowflake://ATLAS_DEPLOY_PROD_USER@<account_identifier>/APP_PROD?warehouse=ATLAS_WH&role=ATLAS_DEPLOY_PROD&authenticator=SNOWFLAKE_JWT&privateKey=<prod_private_key>
Each value holds the programmatic access token of its user, in the password position.
Repository secret SNOWFLAKE_DEV_URL, for pull requests:
snowflake://ATLAS_CI_USER:<ci_access_token>@<account_identifier>/APP_DEV?warehouse=ATLAS_WH&role=ATLAS_CI
Repository secret SNOWFLAKE_DEV_URL_MAIN, for the default branch:
snowflake://ATLAS_CI_USER:<ci_access_token>@<account_identifier>/APP_DEV_MAIN?warehouse=ATLAS_WH&role=ATLAS_CI
SNOWFLAKE_URL in the staging environment:
snowflake://ATLAS_DEPLOY_STAGING_USER:<staging_access_token>@<account_identifier>/APP_STAGING?warehouse=ATLAS_WH&role=ATLAS_DEPLOY_STAGING
SNOWFLAKE_URL in the production environment:
snowflake://ATLAS_DEPLOY_PROD_USER:<prod_access_token>@<account_identifier>/APP_PROD?warehouse=ATLAS_WH&role=ATLAS_DEPLOY_PROD
Percent-encode any reserved character in a key or token (see non-alphanumeric characters).
Configuring the Project
Create an atlas.hcl file next to the migration directory, with one env for each kind of job:
// Pull request and push jobs: the dev database only.
env "ci" {
dev = getenv("SNOWFLAKE_DEV_URL")
migration {
dir = "file://migrations"
}
lint {
destructive {
error = true
}
}
}
// Deploy jobs: the target database of the job's GitHub environment, and the
// directory from the Schema Registry.
env "deploy" {
url = getenv("SNOWFLAKE_URL")
migration {
dir = "atlas://snowflake-app"
}
// Stop the deploy if the database drifted from its last applied version.
check "migrate_apply" {
drift {
on_error = FAIL
}
}
}
ci sets no url, so lint and push jobs never connect to a target database. deploy reads the URL of
whichever GitHub environment the job runs in, so staging and production share it.
deploy applies the directory from the Schema Registry: the version the
push job uploaded, which holds exactly the files that were reviewed and merged. Atlas Cloud records
every deployment from the registry. A deployment from file://migrations is recorded only when the
env's migration block also sets report = true and a repo block
(see Deployment reporting). Replace snowflake-app with your repository name.
The pre-apply drift check runs at the start of every
deploy. It compares the target database with the state the registry holds for its last applied
version, and aborts the deploy before any file runs if they differ, such as after a change made
outside Atlas. On a new database with no applied version, the check is skipped. On an existing database,
start with on_error = CONTINUE to report drift without blocking, fix or
exclude what it finds, and then switch to FAIL.
destructive { error = true } fails the lint on any dropped schema, table, or column. Snowflake makes
some changes by dropping and recreating an object, and lint reports those drops too.
Keep account roles, grants, and warehouses out of the migration directory. They live on the account,
not in the dev database, so lint and push run a CREATE ROLE in a migration file against the account,
and fail once the role exists. Manage them in a declarative env of their own, as shown in
Security as Code for Snowflake.
Keeping migration files small
Snowflake commits each DDL statement on its own, so lint reports
TX101 on a file with several DDL statements: if the file fails halfway, it
stays half applied. Write one change per file, as in this example:
-- Create "USERS" table
CREATE TABLE "PUBLIC"."USERS" (
"ID" NUMBER NOT NULL,
"EMAIL" VARCHAR(255) NULL
);
When a file needs several statements, start it with -- atlas:txmode none followed by an empty line.
The directive tells Atlas not to wrap the file in a transaction and clears the TX101 report. It does
not make the file atomic.
Pushing the directory for the first time
Lint compares new files with the latest version of the directory in the Schema Registry, so push the
directory once before the pipeline runs. From the directory that holds atlas.hcl, point
SNOWFLAKE_DEV_URL at a dev database of your own, not one the pipeline uses, and push:
export SNOWFLAKE_DEV_URL="snowflake://<user>:<access_token>@<account_identifier>/<your_dev_database>?warehouse=ATLAS_WH&role=SYSADMIN"
atlas migrate push snowflake-app --env ci
Replace <your_dev_database> with an empty database that only Atlas uses, such as one you create with
CREATE DATABASE APP_DEV_LOCAL; as SYSADMIN. Atlas replays the migration directory on it, so it
must hold no other objects.
Replace snowflake-app with the name of the repository to create in your Atlas Cloud organization.
Atlas prints a URL to the pushed directory.
Setting Up GitHub Actions
Create .github/workflows/atlas.yaml for your sign-in method, replacing snowflake-app with your
repository name and master with your default branch:
- Workload identity federation
- Key pair or access token
Every job gets id-token: write, and a step before the Atlas step requests a token from GitHub and
appends it to the job's URL. The Atlas step must not set the URL in its own env: a step's env
overrides the URL that holds the token, and Atlas fails with no OIDC token was specified.
name: Atlas
on:
push:
branches:
- master
paths:
- .github/workflows/atlas.yaml
- atlas.hcl
- 'migrations/*'
pull_request:
paths:
- .github/workflows/atlas.yaml
- atlas.hcl
- migrate.test.hcl
- 'migrations/*'
permissions:
contents: read
jobs:
lint:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 30
# One job at a time on APP_DEV. Never cancel a running job, and queue
# pending ones instead of cancelling them.
concurrency:
group: atlas-snowflake-dev
cancel-in-progress: false
queue: max
permissions:
contents: read
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
flavor: snowflake
- name: Request a Snowflake token
env:
SNOWFLAKE_DEV_URL: ${{ secrets.SNOWFLAKE_DEV_URL }}
run: |
TOKEN=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=snowflakecomputing.com" | jq -r .value)
echo "::add-mask::$TOKEN"
echo "SNOWFLAKE_DEV_URL=$SNOWFLAKE_DEV_URL&token=$TOKEN" >> "$GITHUB_ENV"
- uses: ariga/atlas-action/migrate/lint@v1
with:
env: ci
dir-name: snowflake-app
env:
GITHUB_TOKEN: ${{ github.token }}
push:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
timeout-minutes: 30
# One job at a time on APP_DEV_MAIN.
concurrency:
group: atlas-snowflake-dev-main
cancel-in-progress: false
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
flavor: snowflake
- name: Request a Snowflake token
env:
SNOWFLAKE_DEV_URL: ${{ secrets.SNOWFLAKE_DEV_URL_MAIN }}
run: |
TOKEN=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=snowflakecomputing.com" | jq -r .value)
echo "::add-mask::$TOKEN"
echo "SNOWFLAKE_DEV_URL=$SNOWFLAKE_DEV_URL&token=$TOKEN" >> "$GITHUB_ENV"
- uses: ariga/atlas-action/migrate/push@v1
with:
env: ci
dir-name: snowflake-app
deploy-staging:
needs: push
runs-on: ubuntu-latest
timeout-minutes: 30
environment: staging
# Atlas takes no lock on Snowflake: one deployment at a time per database.
concurrency:
group: atlas-deploy-staging
cancel-in-progress: false
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
flavor: snowflake
- name: Request a Snowflake token
env:
SNOWFLAKE_URL: ${{ secrets.SNOWFLAKE_URL }}
run: |
TOKEN=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=snowflakecomputing.com" | jq -r .value)
echo "::add-mask::$TOKEN"
echo "SNOWFLAKE_URL=$SNOWFLAKE_URL&token=$TOKEN" >> "$GITHUB_ENV"
- uses: ariga/atlas-action/migrate/apply@v1
with:
env: deploy
# The version the push job uploaded for this commit.
dir: atlas://snowflake-app?tag=${{ github.sha }}
deploy-production:
needs: deploy-staging
runs-on: ubuntu-latest
timeout-minutes: 30
environment: production
concurrency:
group: atlas-deploy-production
cancel-in-progress: false
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
flavor: snowflake
- name: Request a Snowflake token
env:
SNOWFLAKE_URL: ${{ secrets.SNOWFLAKE_URL }}
run: |
TOKEN=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=snowflakecomputing.com" | jq -r .value)
echo "::add-mask::$TOKEN"
echo "SNOWFLAKE_URL=$SNOWFLAKE_URL&token=$TOKEN" >> "$GITHUB_ENV"
- uses: ariga/atlas-action/migrate/apply@v1
with:
env: deploy
# The version the push job uploaded for this commit.
dir: atlas://snowflake-app?tag=${{ github.sha }}
The key or token is part of each URL secret, so the Atlas steps read the secrets directly.
name: Atlas
on:
push:
branches:
- master
paths:
- .github/workflows/atlas.yaml
- atlas.hcl
- 'migrations/*'
pull_request:
paths:
- .github/workflows/atlas.yaml
- atlas.hcl
- migrate.test.hcl
- 'migrations/*'
permissions:
contents: read
jobs:
lint:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 30
# One job at a time on APP_DEV. Never cancel a running job, and queue
# pending ones instead of cancelling them.
concurrency:
group: atlas-snowflake-dev
cancel-in-progress: false
queue: max
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
flavor: snowflake
- uses: ariga/atlas-action/migrate/lint@v1
with:
env: ci
dir-name: snowflake-app
env:
SNOWFLAKE_DEV_URL: ${{ secrets.SNOWFLAKE_DEV_URL }}
GITHUB_TOKEN: ${{ github.token }}
push:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
timeout-minutes: 30
# One job at a time on APP_DEV_MAIN.
concurrency:
group: atlas-snowflake-dev-main
cancel-in-progress: false
steps:
- uses: actions/checkout@v7
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
flavor: snowflake
- uses: ariga/atlas-action/migrate/push@v1
with:
env: ci
dir-name: snowflake-app
env:
SNOWFLAKE_DEV_URL: ${{ secrets.SNOWFLAKE_DEV_URL_MAIN }}
deploy-staging:
needs: push
runs-on: ubuntu-latest
timeout-minutes: 30
environment: staging
# Atlas takes no lock on Snowflake: one deployment at a time per database.
concurrency:
group: atlas-deploy-staging
cancel-in-progress: false
steps:
- uses: actions/checkout@v7
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
flavor: snowflake
- uses: ariga/atlas-action/migrate/apply@v1
with:
env: deploy
# The version the push job uploaded for this commit.
dir: atlas://snowflake-app?tag=${{ github.sha }}
env:
SNOWFLAKE_URL: ${{ secrets.SNOWFLAKE_URL }}
deploy-production:
needs: deploy-staging
runs-on: ubuntu-latest
timeout-minutes: 30
environment: production
concurrency:
group: atlas-deploy-production
cancel-in-progress: false
steps:
- uses: actions/checkout@v7
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
flavor: snowflake
- uses: ariga/atlas-action/migrate/apply@v1
with:
env: deploy
# The version the push job uploaded for this commit.
dir: atlas://snowflake-app?tag=${{ github.sha }}
env:
SNOWFLAKE_URL: ${{ secrets.SNOWFLAKE_URL }}
What each job does:
| Job | Runs on | Snowflake access |
|---|---|---|
lint | Pull requests | Replays the directory on APP_DEV, lints the new files, and comments the report on the pull request |
push | Merges to the default branch | Replays the directory on APP_DEV_MAIN and pushes it to the Schema Registry |
deploy-staging | After push | Applies the version push uploaded, tagged with the commit, to APP_STAGING |
deploy-production | After deploy-staging, once a reviewer approves | Applies the same version to APP_PROD |
Each step that opens a snowflake:// URL needs the extended build and an Atlas Pro login, so every job
runs ariga/setup-atlas with flavor: snowflake and the bot token. Without flavor, the steps fail
with sql/sqlclient: unknown driver "snowflake". Without the login, they fail with
login is required to use the 'snowflake' driver.
Running one job at a time
Each job that touches a Snowflake database runs in a concurrency group named after that database:
- Lint and push replay the migration directory on a dev database. Two jobs on one dev database at once see each other's objects and fail.
- Atlas takes no lock on Snowflake, so two
migrate applyruns against one database can both apply the same pending files. The deploy groups serialize them. Any other job that applies to the same database, such as a manual deployment workflow, needs the same group name.
cancel-in-progress: false keeps a running job alive when a new one is queued. A job cancelled
mid-run can leave a half-applied migration on a target database, or leftover objects on a dev database.
By default, a group keeps one pending job and cancels it when a newer one queues. The groups use that default where it is safe, and a queue where it is not:
- The
lintgroup setsqueue: max, so up to 100 pending lint jobs wait their turn instead of cancelling each other, and every pull request gets its check.queue: maxcannot be combined withcancel-in-progress: true. - The
pushand deploy groups keep the default. A newer merge replaces an older pending one, and its version includes the older one's files. GitHub orders a queue by when each job started waiting, and does not guarantee that order, so a queue could push or deploy an older version after a newer one.
The default branch has its own dev database and group, so merges never wait behind a queue of pull
request lint jobs. See GitHub's documentation on concurrency for the queue setting.
Timeouts
Every lint and push run executes the migration directory as DDL on the dev database, and Snowflake DDL
is slow: a lint of a few statements can take about a minute. The time grows with the length of the
directory. Set timeout-minutes well above your longest run, since a job that times out mid-run leaves
the same leftovers as a cancelled one. To keep runs short on a long directory, use
atlas migrate checkpoint.
Testing Migrations in CI
Migration tests run migrations on the dev database with seeded rows and assert on
the result. Add the test files to the ci env:
env "ci" {
dev = getenv("SNOWFLAKE_DEV_URL")
migration {
dir = "file://migrations"
}
lint {
destructive {
error = true
}
}
test {
migrate {
src = ["migrate.test.hcl"]
}
}
}
Then add a step after migrate/lint in the lint job:
- Workload identity federation
- Key pair or access token
The step reads the URL with the token that the job's token step wrote, so it sets no URL of its own:
- uses: ariga/atlas-action/migrate/test@v1
with:
env: ci
- uses: ariga/atlas-action/migrate/test@v1
with:
env: ci
env:
SNOWFLAKE_DEV_URL: ${{ secrets.SNOWFLAKE_DEV_URL }}
The tests run on APP_DEV inside the same job, so they share its concurrency group. The workflow's
pull_request paths already include migrate.test.hcl: add any other test files you list in src.
Run them locally with atlas migrate test --env ci before you open the pull request, against a dev
database of your own. The step fails if migrate.test.hcl is missing:
Verifying the Pipeline has an example file.
Verifying the Pipeline
Send one migration through every job to check the roles, secrets, and environments together. The migration reaches production, and lint blocks removing it later as a destructive change, so use a table you want to keep, or your first real migration.
Checking the setup
In Snowflake, confirm each role reaches only its own databases:
SHOW GRANTS TO ROLE ATLAS_CI; -- ATLAS_WH, APP_DEV, APP_DEV_MAIN
SHOW GRANTS TO ROLE ATLAS_DEPLOY_STAGING; -- ATLAS_WH, APP_STAGING
SHOW GRANTS TO ROLE ATLAS_DEPLOY_PROD; -- ATLAS_WH, APP_PROD
SHOW USERS LIKE 'ATLAS%';
With workload identity federation, also run DESC USER on each user and check that its subject names
your repository, and your default branch or environment.
In GitHub, Settings -> Secrets and variables -> Actions lists only ATLAS_CLOUD_TOKEN,
SNOWFLAKE_DEV_URL, and SNOWFLAKE_DEV_URL_MAIN as repository secrets. SNOWFLAKE_URL belongs only
to the staging and production environments.
Opening a pull request
On a new branch, add a migration file:
-- Create "PIPELINE_CHECK" table
CREATE TABLE "PUBLIC"."PIPELINE_CHECK" ("ID" NUMBER NOT NULL);
If you added the migrate/test step from Testing Migrations in CI, add a
test case for the migration:
test "migrate" "pipeline_check" {
migrate {
to = "<the number at the start of your file name>"
}
exec {
sql = "INSERT INTO \"PUBLIC\".\"PIPELINE_CHECK\" (\"ID\") VALUES (1)"
}
exec {
sql = "SELECT COUNT(*) FROM \"PUBLIC\".\"PIPELINE_CHECK\""
output = "1"
}
}
Update atlas.sum, then commit the files and open a pull request:
atlas migrate hash --env ci
The lint job passes and comments the lint report on the pull request, and the migrate/test step
passes.

To check that lint blocks destructive changes, push a commit that drops a table to the same branch. The
lint job fails. Revert the commit before you merge.
Merging
Merge the pull request:
pushuploads the directory: thesnowflake-apprepository in Atlas Cloud shows a new version, tagged with the merge commit.deploy-stagingapplies it.SHOW TABLES IN DATABASE APP_STAGING;listsPIPELINE_CHECK.deploy-productionwaits for a reviewer. Approve it, then checkAPP_PRODthe same way. If it runs without waiting, see Troubleshooting.

Atlas Cloud shows both deployments in the repository.

After the runs, both dev databases are empty:
SHOW TABLES IN DATABASE APP_DEV;
SHOW TABLES IN DATABASE APP_DEV_MAIN;
A leftover object means a job was cancelled or timed out mid-run. See Troubleshooting for that and for sign-in errors.
Testing the drift check
Change staging outside Atlas, then send another migration through the pipeline. Make the change as a role that the deploy role is granted to:
USE ROLE SYSADMIN;
ALTER TABLE APP_STAGING.PUBLIC.PIPELINE_CHECK ADD COLUMN "HOTFIX" VARCHAR(100);
On a new branch, add a migration that does not touch PIPELINE_CHECK, run
atlas migrate hash --env ci, and open a pull request:
-- Create "DRIFT_TEST" table
CREATE TABLE "PUBLIC"."DRIFT_TEST" ("ID" NUMBER NOT NULL);
The lint job passes: the drift check runs on deploys, not on the dev database. When the pull request
merges, push uploads the version, and deploy-staging fails before it runs any file, with a report
of the HOTFIX column. DRIFT_TEST is not created, and deploy-production is skipped.


Remove the change and rerun the failed jobs:
USE ROLE SYSADMIN;
ALTER TABLE APP_STAGING.PUBLIC.PIPELINE_CHECK DROP COLUMN "HOTFIX";
deploy-staging passes the drift check and creates DRIFT_TEST, and deploy-production waits for a
reviewer.
Other CI/CD Platforms
These parts of the guide carry over to any CI platform:
Setting Up Snowflake, the URLs, and the atlas.hcl from
Configuring the Project. Two things change per platform:
-
Every job that opens a
snowflake://URL needs the extended build of Atlas, which carries the Snowflake driver. Outside GitHub Actions, install it with the install script:curl -sSf https://atlasgo.sh | ATLAS_FLAVOR="snowflake" sh -
Atlas takes no lock on Snowflake, so serialize the jobs that use each database, dev databases included, across every branch and pull request, and never cancel a running job. A control that serializes the builds of one branch leaves pull requests running against
APP_DEVat the same time.
| Platform | Installing the Snowflake build | Serializing jobs | Guide |
|---|---|---|---|
| GitHub Actions | flavor: snowflake on ariga/setup-atlas | concurrency groups | This guide, and GitHub Actions |
| Azure DevOps | The AtlasAction task runs the Atlas CLI that a script step installs: add ATLAS_FLAVOR="snowflake" to that step | An Exclusive Lock check on each environment, and on the variable group that holds each dev URL, since lint jobs use no environment | Azure DevOps with GitHub, Azure DevOps Repos |
| Jenkins | Install the extended build on the agent | disableConcurrentBuilds() on the deploy job, which builds only master. The Multibranch Pipeline runs a job per branch, so lint needs a lock shared across them, such as lock('APP_DEV') from the Lockable Resources plugin, or a dev database per branch | Jenkins |
| GitLab CI | The Atlas components have no input for the extended build: run the Atlas CLI in your own jobs, installed with the script above | A resource_group per database | GitLab |
| CircleCI | atlas-orb/setup has no input for the extended build: install it in a run step and run the Atlas CLI | The platform's own controls | CircleCI |
| Bitbucket Pipelines | The Atlas pipe carries its own CLI: install the extended build in a step and run the Atlas CLI | The platform's own controls | Bitbucket |
When you run the CLI directly, each pipeline step maps to one command with --env:
| Step | Command |
|---|---|
| Lint, on pull requests | atlas migrate lint --env ci --base atlas://snowflake-app |
| Push, on the default branch | atlas migrate push snowflake-app --env ci |
| Deploy | atlas migrate apply --env deploy |
The push updates the registry's latest version, and the deploy env applies it from
atlas://snowflake-app. Run the push and the deploy in one job that runs one build at a time, as the
Jenkins guide does, so each deployment applies the version its own build pushed.
Log in first with atlas login --token "$ATLAS_TOKEN", from a bot token stored in the platform's
secret store. Keep the same trust boundary as on GitHub: lint gets only the dev database URL, and only
deploy jobs on the default branch get the target URL, from protected variables or a protected
environment.
Troubleshooting
sql/sqlclient: unknown driver "snowflake"
ariga/setup-atlas installed the default build of Atlas, which has no Snowflake driver. Add
flavor: snowflake to the ariga/setup-atlas step in every job.
login is required to use the 'snowflake' driver
The job is not logged in to Atlas Cloud. Pass cloud-token to ariga/setup-atlas in every job that
opens a snowflake:// URL.
<bot> does not have write access to snowflake-app directory
The repository has protected flows turned on, and the bot is not one of its writers. In Atlas Cloud, open the repository's Settings tab, add the bot under Protected Flows with the Writer role, and rerun the failed jobs. To cover new repositories, add the bot to the defaults in ☰ -> Settings -> Repository Settings.
390422 (08004): Incoming request with IP/Token ... is not allowed to access Snowflake
A Snowflake network policy allows only listed IP addresses, and GitHub-hosted runners connect from
addresses that change. This applies to every sign-in method. To see which policy applies, run as
SECURITYADMIN:
SHOW PARAMETERS LIKE 'NETWORK_POLICY' IN ACCOUNT;
SHOW PARAMETERS LIKE 'NETWORK_POLICY' IN USER ATLAS_CI_PR_USER;
The Snowflake account administrator chooses the fix:
- Run the jobs on runners with fixed addresses, and add those addresses to the policy: a self-hosted
runner, or GitHub larger runners with static IP addresses, which need GitHub Team or GitHub
Enterprise. Set
runs-onin every job to the runner's label. - Attach a network policy to the Atlas service users. A user's network policy replaces the account policy for that user. With workload identity federation, a policy that allows any address leaves the token as the only check: a short-lived token that only jobs matching the user's subject can get.
USE ROLE SECURITYADMIN;
CREATE NETWORK POLICY ATLAS_GITHUB_ACTIONS ALLOWED_IP_LIST = ('0.0.0.0/0');
ALTER USER ATLAS_CI_PR_USER SET NETWORK_POLICY = ATLAS_GITHUB_ACTIONS;
ALTER USER ATLAS_CI_MAIN_USER SET NETWORK_POLICY = ATLAS_GITHUB_ACTIONS;
ALTER USER ATLAS_DEPLOY_STAGING_USER SET NETWORK_POLICY = ATLAS_GITHUB_ACTIONS;
ALTER USER ATLAS_DEPLOY_PROD_USER SET NETWORK_POLICY = ATLAS_GITHUB_ACTIONS;
With a key pair or a programmatic access token, keep the IP check: use runners with fixed addresses instead of a policy that allows any address.
connected database is not clean: found schema "..."
A cancelled or timed-out run left a schema behind in the dev database. Drop the schema as ATLAS_CI,
or recreate the dev database with the statements in Dev databases.
connected database is not clean: found table "..." in schema "PUBLIC"
A run left objects behind in the dev database's PUBLIC schema. Drop the objects as ATLAS_CI.
deploy-production ran without waiting for approval
The production environment has no required reviewers. In Settings -> Environments ->
production, check Required reviewers, add the people who approve deployments, and click
Save protection rules.
If Required reviewers is missing, the plan does not offer it for the repository: on a private
repository, it needs GitHub Enterprise. Without it, take production out of the merge flow. Move the
deploy-production job from atlas.yaml into a workflow that runs only when started by hand, remove
its needs, and apply the latest version in the registry:
name: Atlas Deploy Production
on:
workflow_dispatch:
permissions:
contents: read
jobs:
deploy-production:
runs-on: ubuntu-latest
timeout-minutes: 30
environment: production
concurrency:
group: atlas-deploy-production
cancel-in-progress: false
# ...the permissions and steps of the deploy-production job, with this change
# in the migrate/apply step:
# dir: atlas://snowflake-app
Start it from the Actions tab after deploy-staging has applied the same version. The environment's
branch rule still limits it to the default branch, and anyone with write access to the repository can
start it, so it is a weaker control than a reviewer.
A deployment failed halfway through a file
Snowflake committed the statements that ran before the failure, so the file is partially applied.
Atlas records each statement as it runs: atlas migrate status --env deploy shows the file as
partially applied, and the next migrate apply continues from the statement that failed. How you
recover depends on whether another environment already completed the file.
If no other environment completed the file, such as a failure on staging, fix the file:
- Fix the statement that failed and the statements after it. Leave the statements that already ran
unchanged: editing one fails the next apply with
history changed. - Run
atlas migrate hashto updateatlas.sum. - Open a pull request with the fix. When it merges, the pipeline continues the file from the failed statement.
If another environment completed the file, such as a failure on production after staging applied it,
leave the file unchanged. Staging does not reapply a file it completed, so an edited file leaves the
two environments with different schemas. Instead, repair the failing database so the original
statement can run, for example by fixing the rows a new constraint rejects, or by reverting a change
made outside Atlas. Review the repair like any other production change, run it, and then rerun the failed
deploy-production job: Atlas continues the file from the failed statement. See
Fixing Migration Failures for each kind of
failure.
Two deployments applied the same files
Two jobs applied to one database at the same time, and Atlas takes no lock on Snowflake. Put every job
that applies to the database in the same concurrency group, as in
Running one job at a time.
Next Steps
Getting Started with Snowflake
Connect to Snowflake, inspect a schema, and run both workflows
Security as Code (Declarative)
Define Snowflake account roles, database roles, and object grants as code
Snowflake and dbt
Manage the schema layer under a dbt project on Snowflake
GitHub Actions Reference
Inputs and outputs of every Atlas action
Testing Migrations
Write migration tests with seeded data and assertions
Declarative CI/CD on GitHub Actions
Plan and apply the declarative env that holds roles, grants, and warehouses