This repository contains GitHub Actions for working with Atlas.
If you are looking for the old TypeScript-based action, please see the old README.
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/migrate/push | Push migrations to Atlas Registry |
ariga/atlas-action/migrate/lint | Lint migrations (required atlas login ) |
ariga/atlas-action/migrate/apply | Apply migrations to a database |
ariga/atlas-action/migrate/down | Revert migrations to a database |
ariga/atlas-action/migrate/test | Test migrations on a database |
ariga/atlas-action/schema/test | Test schema on a database |
ariga/atlas-action/schema/push | Push a schema to Atlas Registry |
ariga/atlas-action/schema/plan | Plan a declarative migration for a schema transition |
ariga/atlas-action/schema/plan/approve | Approve a declarative migration plan |
ariga/atlas-action/schema/apply | Apply a declarative migrations to a database |
ariga/atlas-action/monitor/schema | Sync the database schema to Atlas Cloud Monitoring |
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 a 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.
If 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.
Setup 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.
Push 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.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.tag
- The tag to apply to the pushed migration directory. By default the current git commit hash is used.latest
- Whether to implicitly push the "latest" tag. True by default.config
- The path to the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.
url
- The URL of the migration directory in Atlas Cloud, containing an ERD visualization of the schema.
Lint 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
- The name (slug) of the project in Atlas Cloud.tag
- The tag of migrations to used as base for linting. By default, thelatest
tag is used.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.config
- The path to the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.
url
- The URL of the CI report in Atlas Cloud, containing an ERD visualization and analysis of the schema migrations.
Apply migrations to a database.
All inputs are optional as they may be specified in the Atlas configuration file.
url
- The URL of the target database. For example:mysql://root:pass@localhost:3306/prod
.dir
- The URL of the migration directory to apply. For example:atlas://dir-name
for cloud based directories orfile://migrations
for local ones.config
- The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
.dry-run
- Print SQL without executing it. Defaults tofalse
vars
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.allow-dirty
- Allow applying migration on a non-clean database. Defaults to false.
current
- The current version of the database. (before applying migrations)target
- The target version of the database.pending_count
- The number of migrations that will be applied.applied_count
- The number of migrations that were applied.
Revert migrations to a database.
All inputs are optional as they may be specified in the Atlas configuration file.
url
- The URL of the target database. For example:mysql://root:pass@localhost:3306/dev
.dir
- The URL of the migration directory to apply. For example:atlas://dir-name
for cloud based directories orfile://migrations
for local ones.config
- The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
.amount
- The amount of applied migrations to revert, defaults to 1.to-version
- To which version to revert.to-tag
- To which tag to revert.wait-timeout
- Time after which no other retry attempt is made and the action exits. If not set, only one attempt is made.wait-interval
- Time in seconds between different migrate down attempts, useful when waiting for plan approval, defaults to 1s.vars
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.
current
- The current version of the database. (before applying migrations)target
- The target version of the database.pending_count
- The number of migrations that will be applied.reverted_count
- The number of migrations that were reverted.url
- The URL of the plan to review and approve / reject.
Run schema migration tests. Read more in Atlas website.
All inputs are optional as they may be specified in the Atlas configuration file.
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.dir
- The URL of the migration directory to apply. For example:atlas://dir-name
for cloud based directories orfile://migrations
for local ones.run
- Filter tests to run by regexp. For example,^test_.*
will only run tests that start withtest_
. Default is to run all tests.config
- The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.
Run schema tests on the desired schema. Read more in Atlas website.
All inputs are optional as they may be specified in the Atlas configuration file.
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 desired schema URL(s) to test. For Example:file://schema.hcl
run
- Filter tests to run by regexp. For example,^test_.*
will only run tests that start withtest_
. Default is to run all tests.config
- The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.
Apply a declarative migrations to a database.
to
- The URL(s) of the desired schema state.url
- The URL of the target database. For example:mysql://root:pass@localhost:3306/prod
.plan
- Optional plan file to use for applying the migrations. For example:atlas://<schema>/plans/<id>
.dry-run
- Print SQL (and optional analysis) without executing it. Eithertrue
orfalse
. Defaults tofalse
.auto-approve
- Automatically approve and apply changes. Eithertrue
orfalse
. Defaults tofalse
.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.schema
- The database schema(s). For example:public
.config
- The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.
error
- The error message if the action fails.
Push a schema to Atlas Registry with an optional tag.
schema-name
- The name (slug) of the schema repository in Atlas Registry.url
- Desired schema URL(s) to push. For example:file://schema.hcl
.tag
- The tag to apply to the pushed schema. By default, the current git commit hash is used.latest
- Whether to implicitly push thelatest
tag. True by default.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.schema
- The database schema(s) to push. For example:public
.config
- The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.
slug
- The slug of the schema repository in Atlas Registry.link
- The URL of the schema in Atlas Registry.url
- The URL of the pushed schema version in Atlas format. For example,atlas://app
.
Plan a declarative migration for a schema transition.
schema-name
- The name (slug) of the schema repository in Atlas Registry.from
- URL(s) of the current schema state to transition from.to
- URL(s) of the desired schema state to transition to.name
- Optional name for the plan. If not provided, a default plan is generated by Atlas.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.schema
- The database schema(s). For example:public
.config
- The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.
plan
- The URL of the generated plan in Atlas format. For example,atlas://app/plans/123
.link
- The URL of the plan in Atlas Registry.status
- The status of the plan. For example,PENDING
orAPPROVED
.
Approve a declarative migration plan.
schema-name
- The name (slug) of the schema repository in Atlas Registry.from
- URL(s) of the current schema state to transition from.to
- URL(s) of the desired schema state to transition to.plan
- Optional URL of the plan to be approved. For example,atlas://<schema>/plans/<id>
. By default, Atlas searches in the registry for a plan corresponding to the given schema transition and approves it (typically, this plan is created during the PR stage). If multiple plans are found, an error will be thrown.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.config
- The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.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
- Stringify JSON object containing variables to be used inside the Atlas configuration file. For example:'{"var1": "value1", "var2": "value2"}'
.working-directory
- The working directory to run from. Defaults to project root.
plan
- The URL of the generated plan in Atlas format. For example,atlas://app/plans/123
.link
- The URL of the plan in Atlas Registry.status
- The status of the plan. For example,PENDING
orAPPROVED
.
Monitor changes of the database schema and track them in Atlas Cloud. Can be used periodically to monitor changes in the database schema.
cloud-token
- (required) The Atlas Cloud token to use for authentication. To create a cloud token see the docs.url
- (required) The URL of the database to monitor. For example:mysql://root:pass@localhost:3306/prod
.slug
- (optional) Unique identifier for the database server.schemas
- (optional) List of database schemas to include (by default includes all schemas). see: https://atlasgo.io/declarative/inspect#inspect-multiple-schemas.exclude
- (optional) List of exclude patterns from inspection. see: https://atlasgo.io/declarative/inspect#exclude-schemas.
url
- URL of the schema of the database inside Atlas Cloud.
The following action will monitor changes to the auth
and app
schemas inside the mysql://root:pass@localhost:3306
database and track them in Atlas Cloud.
In case the database URL is subject to change, the slug
parameter can use to identify the same database across runs.
uses: ariga/atlas-action/monitor/schema@v1
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
url: 'mysql://root:pass@localhost:3306'
schemas: |-
auth
app
The source code for this GitHub Action is released under the Apache 2.0 License, see LICENSE.
This action downloads a binary version of Atlas which is distributed under the Ariga EULA.