MCPcopy Index your code
hub / github.com/ariga/atlas-action

github.com/ariga/atlas-action @v1.15.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.15.5 ↗ · + Follow
665 symbols 2,174 edges 53 files 436 documented · 66% updated 19d agov1 · 2024-02-22★ 43
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

GitHub Actions for Atlas

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.

Actions

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

Examples

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.

Pre-requisites

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.

Continuous Integration and Delivery

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.

Quick Setup: Using the gh CLI

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.

Manual Setup: Create a workflow

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.

Continuous Deployment

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.

API

ariga/setup-atlas

Setup the Atlas CLI and optionally login to Atlas Cloud.

Inputs

  • 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/push

Push the current version of your migration directory to Atlas Cloud.

Inputs

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 root
  • config - 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/lint

Lint migration changes with Atlas

Inputs

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 root
  • config - 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.

Outputs

  • url - The URL of the CI report in Atlas Cloud, containing an ERD visualization and analysis of the schema migrations.

ariga/atlas-action/migrate/apply

Apply migrations to a database.

Inputs

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 root
  • config - 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"}.

Outputs

  • applied_count

Extension points exported contracts — how you extend this code

Action (Interface)
Action interface for Atlas. [6 implementers]
atlasaction/action.go
ClientOption (FuncType)
ClientOption is the option when creating a new client.
internal/azuredevops/azuredevops.go
ClientOption (FuncType)
ClientOption is the option when creating a new client.
internal/github/github.go
Option (FuncType)
Option is a function that modifies the MessageAttributes of a message.
internal/teamcity/message.go
ClientOption (FuncType)
ClientOption is the option when creating a new client.
internal/bitbucket/bitbucket.go
ClientOption (FuncType)
(no doc)
internal/gitlab/gitlab.go
Reporter (Interface)
Reporter is an interface for reporting the status of the actions. [5 implementers]
atlasaction/action.go
SCMClient (Interface)
SCMClient contains methods for interacting with SCM platforms (GitHub, Gitlab etc...). [5 implementers]
atlasaction/action.go

Core symbols most depended-on inside this repo

Errorf
called by 243
atlasaction/action.go
GetInput
called by 112
atlasaction/action.go
Run
called by 83
atlasaction/action.go
Error
called by 66
internal/bitbucket/bitbucket.go
Infof
called by 41
atlasaction/action.go
GetArrayInput
called by 40
atlasaction/action.go
SetOutput
called by 39
atlasaction/action.go
WriteServiceMessage
called by 38
internal/teamcity/service.go

Shape

Method 384
Function 175
Struct 87
FuncType 7
Interface 7
TypeAlias 5

Languages

Go100%

Modules by API surface

atlasaction/action.go141 symbols
atlasaction/action_test.go126 symbols
internal/teamcity/service.go68 symbols
internal/bitbucket/bitbucket.go32 symbols
atlasaction/azure.go28 symbols
atlasaction/github.go27 symbols
internal/github/github.go26 symbols
atlasaction/manifest.go25 symbols
atlasaction/bitbucket.go25 symbols
internal/azuredevops/azuredevops.go20 symbols
atlasaction/teamcity.go20 symbols
atlasaction/gitlab.go19 symbols

Datastores touched

(mysql)Database · 1 repos
appDatabase · 1 repos
devDatabase · 1 repos
pathDatabase · 1 repos

For agents

$ claude mcp add atlas-action \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact