This repository contains GitHub Actions for working with Atlas.
To learn more about the recommended way to build workflows, read our guide on Modern CI/CD for Databases.
| Action | Description |
|---|---|
| ariga/setup-atlas | Setup the Atlas CLI and optionally login to Atlas Cloud |
| ariga/atlas-action/copilot | Talk to Atlas Copilot. |
| ariga/atlas-action/migrate/apply | Applies a migration directory on a target database |
| ariga/atlas-action/migrate/autorebase | Automatically resolves atlas.sum conflicts and rebases the migration directory onto the target branch. |
| ariga/atlas-action/migrate/hash | Automatically generate a hash of the schema migrations directory, and commit it to the migration directory. |
| ariga/atlas-action/migrate/diff | Automatically generate versioned migrations whenever the schema is changed, and commit them to the migration directory. |
| ariga/atlas-action/migrate/down | Reverts deployed migration files on a target database |
| ariga/atlas-action/migrate/lint | CI for database schema changes with Atlas |
| ariga/atlas-action/migrate/push | Push the current version of your migration directory to Atlas Cloud. |
| ariga/atlas-action/migrate/set | Edits the revision table to consider all migrations up to and including the given version to be applied. |
| ariga/atlas-action/migrate/test | CI for database schema changes with Atlas |
| ariga/atlas-action/monitor/schema | Sync the database schema to Atlas Cloud. |
| ariga/atlas-action/schema/apply | Applies schema changes to a target database |
| ariga/atlas-action/schema/lint | Lint database schema with Atlas |
| ariga/atlas-action/schema/plan | Plan a declarative migration to move from the current state to the desired state |
| ariga/atlas-action/schema/plan/approve | Approve a migration plan by its URL |
| ariga/atlas-action/schema/push | Push a schema version with an optional tag to Atlas |
| ariga/atlas-action/schema/test | Run schema tests against the desired schema |
The Atlas GitHub Actions can be composed into workflows to create CI/CD pipelines for your database schema.
Workflows will normally begin with the setup-atlas action, which will install the Atlas CLI and optionally
login to Atlas Cloud. Followed by whatever actions you need to run, such as migrate lint or migrate apply.
The following examples require you to have an Atlas Cloud account and push an initial version of your migration directory.
To create an account, first download the Atlas CLI (on Linux/macOS):
curl -sSL https://atlasgo.io/install | sh
For more installation options, see the documentation.
Then, create an account by running the following command and following the instructions:
atlas login
After logging in, push your migration directory to Atlas Cloud:
atlas migrate push --dev-url docker://mysql/8/dev --dir-name my-project
For a more detailed guide, see the documentation.
Finally, you will need an API token to use the Atlas GitHub Actions. To create a token, see the docs.
This example workflow shows how to configure a CI/CD pipeline for your database schema. The workflow will verify the safety of your schema changes when in a pull request and push migrations to Atlas Cloud when merged into the main branch.
gh CLIIf you have the gh CLI installed, you can use the following command to setup a workflow for your repository:
gh extension install ariga/gh-atlas
gh auth refresh -s write:packages,workflow
gh atlas init-action
This will create a pull request with a workflow that will run migrate lint on pull requests and
migrate push on the main branch. You can customize the workflow by editing the generated
.github/workflows/atlas-ci.yaml file.
Create a new file named .github/workflows/atlas.yaml with the following contents:
name: Atlas CI/CD
on:
push:
branches:
- master # Use your main branch here.
pull_request:
paths:
- 'migrations/*' # Use the path to your migration directory here.
# Permissions to write comments on the pull request.
permissions:
contents: read
pull-requests: write
jobs:
atlas:
services:
# Spin up a mysql:8 container to be used as the dev-database for analysis.
mysql:
image: mysql:8
env:
MYSQL_DATABASE: dev
MYSQL_ROOT_PASSWORD: pass
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping -ppass"
--health-interval 10s
--health-start-period 10s
--health-timeout 5s
--health-retries 10
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- uses: ariga/atlas-action/migrate/lint@v1
with:
dir: 'file://migrations'
dir-name: 'my-project' # The name of the project in Atlas Cloud
dev-url: "mysql://root:pass@localhost:3306/dev"
- uses: ariga/atlas-action/migrate/push@v1
if: github.ref == 'refs/heads/master'
with:
dir: 'file://migrations'
dir-name: 'my-project'
dev-url: 'mysql://root:pass@localhost:3306/dev' # Use the service name "mysql" as the hostname
This example uses a MySQL database, but you can use any database supported by Atlas.
For more examples, see the documentation.
This example workflow shows how to configure a continuous deployment pipeline for your database schema. The workflow will apply migrations on the target database whenever a new commit is pushed to the main branch.
name: Atlas Continuous Deployment
on:
push:
branches:
- master
jobs:
apply:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- uses: ariga/atlas-action/migrate/apply@v1
with:
url: 'mysql://user:${{ secrets.DB_PASSWORD }}@db.hostname.io:3306/db'
dir: 'atlas://my-project' # A directory stored in Atlas Cloud, use ?tag=<tag> to specify a tag
This example workflow shows how to configure a deployment pipeline for your database schema. This workflow will pull the most recent version of your migration directory from Atlas Cloud and apply it to the target database.
For more examples, see the documentation.
ariga/setup-atlasSetup the Atlas CLI and optionally login to Atlas Cloud.
cloud-token - (Optional) The Atlas Cloud token to use for authentication. To create
a cloud token see the docs.version - (Optional) The version of the Atlas CLI to install. Defaults to the latest
version.flavor - (Optional) The driver flavor to install. Some drivers require custom binaries like ("snowflake", "spanner").ariga/atlas-action/migrate/pushPush the current version of your migration directory to Atlas Cloud.
All inputs are optional as they may be specified in the Atlas configuration file.
dir - The URL of the migration directory to push. For example: file://migrations.
Read more about Atlas URLs.dir-name - The name (slug) of the project in Atlas Cloud.latest - If true, push also to the latest tag.revisions-schema - The name of the schema containing the revisions table.tag - The tag to apply to the pushed migration directory. By default the
current git commit hash is used.working-directory - Atlas working directory. Default is project rootconfig - The URL of the Atlas configuration file. By default, Atlas will look for a file
named atlas.hcl in the current directory. For example, file://config/atlas.hcl.
Learn more about Atlas configuration files.env - The environment to use from the Atlas configuration file. For example, dev.vars - A JSON object containing variables to be used in the Atlas configuration file.
For example, {"var1": "value1", "var2": "value2"}.dev-url - The URL of the dev-database to use for analysis. For example: mysql://root:pass@localhost:3306/dev.
Read more about dev-databases.ariga/atlas-action/migrate/lintLint migration changes with Atlas
All inputs are optional as they may be specified in the Atlas configuration file.
dir - The URL of the migration directory to lint. For example: file://migrations.
Read more about Atlas URLs.dir-name - (Required) The name (slug) of the project in Atlas Cloud.git-base - The base branch to detected changes from.git-dir - The URL of the git directory to push to. Defaults to the current working directory.revisions-schema - The name of the schema containing the revisions table.tag - The tag of migrations to used as base for linting. By default, the latest tag is used.working-directory - Atlas working directory. Default is project rootconfig - The URL of the Atlas configuration file. By default, Atlas will look for a file
named atlas.hcl in the current directory. For example, file://config/atlas.hcl.
Learn more about Atlas configuration files.env - The environment to use from the Atlas configuration file. For example, dev.vars - A JSON object containing variables to be used in the Atlas configuration file.
For example, {"var1": "value1", "var2": "value2"}.dev-url - The URL of the dev-database to use for analysis. For example: mysql://root:pass@localhost:3306/dev.
Read more about dev-databases.url - The URL of the CI report in Atlas Cloud, containing an ERD visualization
and analysis of the schema migrations.ariga/atlas-action/migrate/applyApply migrations to a database.
All inputs are optional as they may be specified in the Atlas configuration file.
allow-dirty - Allow working on a non-clean database.amount - The maximum number of migration files to apply. Default is all.dir - The URL of the migration directory to apply. For example: atlas://dir-name for cloud
based directories or file://migrations for local ones.dry-run - Print SQL without executing it. Either "true" or "false".exec-order - How Atlas computes and executes pending migration files to the database.
Either "linear", "linear-skip", or "non-linear". Learn more about execution order.revisions-schema - The name of the schema containing the revisions table.to-version - The target version to apply migrations to. Mutually exclusive with amount.tx-mode - Transaction mode to use. Either "file", "all", or "none".url - The URL of the target database. For example: mysql://root:pass@localhost:3306/dev.working-directory - Atlas working directory. Default is project rootconfig - The URL of the Atlas configuration file. By default, Atlas will look for a file
named atlas.hcl in the current directory. For example, file://config/atlas.hcl.
Learn more about Atlas configuration files.env - The environment to use from the Atlas configuration file. For example, dev.vars - A JSON object containing variables to be used in the Atlas configuration file.
For example, {"var1": "value1", "var2": "value2"}.applied_count $ claude mcp add atlas-action \
-- python -m otcore.mcp_server <graph>