Bitbucket Pipes
Atlas provides seamless integration with Bitbucket Pipelines, allowing you to manage and apply database migrations directly from your Bitbucket repository. By leveraging Bitbucket Pipelines, you can automate the deployment of migration directories to your target databases, ensuring that your database schema is always up-to-date with your application code.
This guide will walk you through the steps to set up and use Atlas-Action with Bitbucket Pipelines, enabling you to deploy migration directories from your git repository effortlessly.
Offline Access
Bitbucket Pipelines does not automatically cache Atlas grants for Atlas Action runs. To ensure Atlas Cloud is not a single point of failure in your pipeline, configure an external cache for .atlas and sync it with ~/.atlas before and after each Atlas action step.
definitions:
caches:
atlas-grant: .atlas
pipelines:
default:
- step:
caches:
- atlas-grant
script:
- mkdir -p ~/.atlas
- cp -a .atlas/. ~/.atlas/ 2>/dev/null || true
- pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: migrate/lint
ATLAS_TOKEN: $ATLAS_TOKEN
- mkdir -p .atlas
- cp -a ~/.atlas/. .atlas/ 2>/dev/null || true
migrate/apply
Run migrations on a target database using migrate apply
Usage
Add bitbucket-pipelines.yml to your repo with the following contents:
Deploy a directory from the git repository
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "Applies a migration directory on a target database"
script:
- name: "Migrate Apply"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/apply" # Required
ATLAS_INPUT_URL: ${DATABASE_URL}
ATLAS_INPUT_DIR: "file://migrations"
- source .atlas-action/outputs.sh
Deploy a directory from the cloud
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "Applies a migration directory on a target database"
script:
- name: "Migrate Apply"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/apply" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
ATLAS_INPUT_URL: ${DATABASE_URL}
ATLAS_INPUT_DIR: "atlas://my-project"
- source .atlas-action/outputs.sh
Inputs
ATLAS_ACTION- (Required) Alwaysmigrate/apply.ATLAS_TOKEN- (Optional) to authenticate with Atlas Cloud.BITBUCKET_ACCESS_TOKEN- (Optional) Bitbucket access token to post comment on the PR.ATLAS_INPUT_ALLOW_DIRTY- (Optional) Allow working on a non-clean database.ATLAS_INPUT_AMOUNT- (Optional) The maximum number of migration files to apply, default is all.ATLAS_INPUT_DIR- (Optional) The URL of the migration directory to apply. For example:atlas://dir-namefor cloud based directories orfile://migrationsfor local ones.ATLAS_INPUT_DRY_RUN- (Optional) Print SQL without executing it. Either "true" or "false".ATLAS_INPUT_REVISIONS_SCHEMA- (Optional) The name of the schema containing the revisions table.ATLAS_INPUT_TX_MODE- (Optional) Transaction mode to use. Either "file", "all", or "none". Default is "file".ATLAS_INPUT_URL- (Optional) The URL of the target database. For example:mysql://root:pass@localhost:3306/dev.ATLAS_INPUT_WORKING_DIRECTORY- (Optional) Atlas working directory, default is project rootATLAS_INPUT_CONFIG- (Optional) The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.hclin the current directory. For example,file://config/atlas.hcl. Learn more about Atlas configuration files.ATLAS_INPUT_ENV- (Optional) The environment to use from the Atlas configuration file. For example,dev.ATLAS_INPUT_VARS- (Optional) A JSON object containing variables to be used in the Atlas configuration file. For example,{"var1": "value1", "var2": "value2"}.
Outputs
The outputs are written into the .atlas-action/outputs.sh, we can load it for the next step using the source command.
ATLAS_OUTPUT_MIGRATE_APPLY_APPLIED_COUNT- The number of migrations that were applied.ATLAS_OUTPUT_MIGRATE_APPLY_CURRENT- The current version of the database. (before applying migrations)ATLAS_OUTPUT_MIGRATE_APPLY_PENDING_COUNT- The number of migrations that will be applied.ATLAS_OUTPUT_MIGRATE_APPLY_TARGET- The target version of the database.
migrate/autorebase
Automatically resolves atlas.sum conflicts and rebases the migration directory onto the target branch.
Inputs
ATLAS_ACTION- (Required) Alwaysmigrate/autorebase.ATLAS_TOKEN- (Optional) to authenticate with Atlas Cloud.BITBUCKET_ACCESS_TOKEN- (Optional) Bitbucket access token to post comment on the PR.ATLAS_INPUT_BASE_BRANCH- (Optional) The base branch to rebase the migration directory onto. Default to the default branch of the repository.ATLAS_INPUT_DIR- (Optional) The URL of the migration directory to rebase on. By default:file://migrations.ATLAS_INPUT_REMOTE- (Optional) The remote to fetch from. Defaults toorigin.ATLAS_INPUT_WORKING_DIRECTORY- (Optional) Atlas working directory, default is project root
migrate/diff
Automatically generate versioned migrations whenever the schema is changed, and commit them to the migration directory.
Inputs
ATLAS_ACTION- (Required) Alwaysmigrate/diff.ATLAS_TOKEN- (Optional) to authenticate with Atlas Cloud.BITBUCKET_ACCESS_TOKEN- (Optional) Bitbucket access token to post comment on the PR.ATLAS_INPUT_DIR- (Optional) The URL of the migration directory. For example:file://migrations. Read more about Atlas URLs.ATLAS_INPUT_REMOTE- (Optional) The remote to push changes to. Defaults toorigin.ATLAS_INPUT_TO- (Optional) The URL of the desired state.ATLAS_INPUT_WORKING_DIRECTORY- (Optional) Atlas working directory, default is project rootATLAS_INPUT_CONFIG- (Optional) The path to the Atlas configuration file. By default, Atlas will look for a file namedatlas.hclin the current directory. For example,file://config/atlas.hcl. Learn more about Atlas configuration files.ATLAS_INPUT_ENV- (Optional) The environment to use from the Atlas configuration file. For example,dev.ATLAS_INPUT_VARS- (Optional) A JSON object containing variables to be used in the Atlas configuration file. For example,{"var1": "value1", "var2": "value2"}.ATLAS_INPUT_DEV_URL- (Optional) The URL of the dev-database to use for analysis. For example:mysql://root:pass@localhost:3306/dev. Read more about dev-databases.
Outputs
The outputs are written into the .atlas-action/outputs.sh, we can load it for the next step using the source command.
ATLAS_OUTPUT_MIGRATE_DIFF_URL- The URL of the CI report in Atlas Cloud, containing an ERD visualization and analysis of the schema migrations.
migrate/down
Reverts deployed migration files from a target database using migrate down
Inputs
ATLAS_ACTION- (Required) Alwaysmigrate/down.ATLAS_TOKEN- (Optional) to authenticate with Atlas Cloud.BITBUCKET_ACCESS_TOKEN- (Optional) Bitbucket access token to post comment on the PR.ATLAS_INPUT_AMOUNT- (Optional) The amount of applied migrations to revert. Mutually exclusive withto-tagandto-version.ATLAS_INPUT_DIR- (Optional) The URL of the migration directory to apply. For example:atlas://dir-namefor cloud based directories orfile://migrationsfor local ones.ATLAS_INPUT_REVISIONS_SCHEMA- (Optional) The name of the schema containing the revisions table.ATLAS_INPUT_TO_TAG- (Optional) The tag to revert to. Mutually exclusive withamountandto-version.ATLAS_INPUT_TO_VERSION- (Optional) The version to revert to. Mutually exclusive withamountandto-tag.ATLAS_INPUT_URL- (Optional) The URL of the target database. For example:mysql://root:pass@localhost:3306/dev.ATLAS_INPUT_WAIT_INTERVAL- (Optional) Time in seconds between different migrate down attempts.ATLAS_INPUT_WAIT_TIMEOUT- (Optional) Time after which no other retry attempt is made and the action exits.ATLAS_INPUT_WORKING_DIRECTORY- (Optional) Atlas working directory, default is project root.ATLAS_INPUT_CONFIG- (Optional) The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.hclin the current directory. For example,file://config/atlas.hcl. Learn more about Atlas configuration files.ATLAS_INPUT_ENV- (Optional) The environment to use from the Atlas configuration file. For example,dev.ATLAS_INPUT_VARS- (Optional) A JSON object containing variables to be used in the Atlas configuration file. For example,{"var1": "value1", "var2": "value2"}.ATLAS_INPUT_DEV_URL- (Optional) The URL of the dev-database to use for analysis. For example:mysql://root:pass@localhost:3306/dev. Read more about dev-databases.
Outputs
The outputs are written into the .atlas-action/outputs.sh, we can load it for the next step using the source command.
ATLAS_OUTPUT_MIGRATE_DOWN_CURRENT- The current version of the database. (before applying migrations)ATLAS_OUTPUT_MIGRATE_DOWN_PLANNED_COUNT- The number of migrations that will be applied.ATLAS_OUTPUT_MIGRATE_DOWN_REVERTED_COUNT- The number of migrations that were reverted.ATLAS_OUTPUT_MIGRATE_DOWN_TARGET- The target version of the database.ATLAS_OUTPUT_MIGRATE_DOWN_URL- If given, the URL for reviewing the revert plan.
migrate/lint
Verify migration safety using migration linting.
Usage
Add bitbucket-pipelines.yml to your repo with the following contents:
- MySQL
- Postgres
- MariaDB
- SQL Server
- ClickHouse
- SQLite
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "CI for database schema changes with Atlas"
script:
- name: "Migrate Lint"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/lint" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://mysql/8/dev"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "CI for database schema changes with Atlas"
script:
- name: "Migrate Lint"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/lint" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://postgres/15/dev?search_path=public"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "CI for database schema changes with Atlas"
script:
- name: "Migrate Lint"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/lint" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://maria/latest/schema"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "CI for database schema changes with Atlas"
script:
- name: "Migrate Lint"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/lint" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://sqlserver/2022-latest?mode=schema"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "CI for database schema changes with Atlas"
script:
- name: "Migrate Lint"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/lint" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://clickhouse/23.11/dev"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "CI for database schema changes with Atlas"
script:
- name: "Migrate Lint"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/lint" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "sqlite://db?mode=memory"
- source .atlas-action/outputs.sh
Inputs
ATLAS_ACTION- (Required) Alwaysmigrate/lint.ATLAS_TOKEN- (Optional) to authenticate with Atlas Cloud.BITBUCKET_ACCESS_TOKEN- (Optional) Bitbucket access token to post comment on the PR.ATLAS_INPUT_DIR- (Optional) The URL of the migration directory to lint. For example:file://migrations. Read more about Atlas URLs.ATLAS_INPUT_DIR_NAME- The name (slug) of the project in Atlas Cloud.ATLAS_INPUT_TAG- (Optional) The tag of migrations to used as base for linting. By default, thelatesttag is used.ATLAS_INPUT_WORKING_DIRECTORY- (Optional) Atlas working directory, default is project rootATLAS_INPUT_CONFIG- (Optional) The path to the Atlas configuration file. By default, Atlas will look for a file namedatlas.hclin the current directory. For example,file://config/atlas.hcl. Learn more about Atlas configuration files.ATLAS_INPUT_ENV- (Optional) The environment to use from the Atlas configuration file. For example,dev.ATLAS_INPUT_VARS- (Optional) A JSON object containing variables to be used in the Atlas configuration file. For example,{"var1": "value1", "var2": "value2"}.ATLAS_INPUT_DEV_URL- (Optional) The URL of the dev-database to use for analysis. For example:mysql://root:pass@localhost:3306/dev. Read more about dev-databases.
Outputs
The outputs are written into the .atlas-action/outputs.sh, we can load it for the next step using the source command.
ATLAS_OUTPUT_MIGRATE_LINT_URL- The URL of the CI report in Atlas Cloud, containing an ERD visualization and analysis of the schema migrations.
migrate/push
Push the current version of your migration directory to the schema registry
Usage
Add bitbucket-pipelines.yml to your repo with the following contents:
- MySQL
- Postgres
- MariaDB
- SQL Server
- ClickHouse
- SQLite
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "Push the current version of your migration directory to Atlas Cloud."
script:
- name: "Migrate Push"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/push" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://mysql/8/dev"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "Push the current version of your migration directory to Atlas Cloud."
script:
- name: "Migrate Push"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/push" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://postgres/15/dev?search_path=public"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "Push the current version of your migration directory to Atlas Cloud."
script:
- name: "Migrate Push"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/push" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://maria/latest/schema"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "Push the current version of your migration directory to Atlas Cloud."
script:
- name: "Migrate Push"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/push" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://sqlserver/2022-latest?mode=schema"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "Push the current version of your migration directory to Atlas Cloud."
script:
- name: "Migrate Push"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/push" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "docker://clickhouse/23.11/dev"
- source .atlas-action/outputs.sh
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: "Push the current version of your migration directory to Atlas Cloud."
script:
- name: "Migrate Push"
pipe: docker://arigaio/atlas-action:v1
variables:
ATLAS_ACTION: "migrate/push" # Required
ATLAS_TOKEN: ${ATLAS_TOKEN}
BITBUCKET_ACCESS_TOKEN: ${BITBUCKET_ACCESS_TOKEN}
ATLAS_INPUT_DIR_NAME: "my-project"
ATLAS_INPUT_DEV_URL: "sqlite://db?mode=memory"
- source .atlas-action/outputs.sh
Inputs
ATLAS_ACTION- (Required) Alwaysmigrate/push.ATLAS_TOKEN- (Optional) to authenticate with Atlas Cloud.BITBUCKET_ACCESS_TOKEN- (Optional) Bitbucket access token to post comment on the PR.ATLAS_INPUT_DIR- (Optional) The URL of the migration directory to push. For example:file://migrations. Read more about Atlas URLs.ATLAS_INPUT_DIR_NAME- (Optional) The name (slug) of the project in Atlas Cloud.ATLAS_INPUT_LATEST- (Optional) If true, push also to the "latest" tag.ATLAS_INPUT_TAG- (Optional) The tag to apply to the pushed migration directory. By default the current git commit hash is used.ATLAS_INPUT_WORKING_DIRECTORY- (Optional) Atlas working directory, default is project rootATLAS_INPUT_CONFIG- (Optional) The path to the Atlas configuration file. By default, Atlas will look for a file namedatlas.hclin the current directory. For example,file://config/atlas.hcl. Learn more about Atlas configuration files.ATLAS_INPUT_ENV- (Optional) The environment to use from the Atlas configuration file. For example,dev.ATLAS_INPUT_VARS- (Optional) A JSON object containing variables to be used in the Atlas configuration file. For example,{"var1": "value1", "var2": "value2"}.ATLAS_INPUT_DEV_URL- (Optional) The URL of the dev-database to use for analysis. For example:mysql://root:pass@localhost:3306/dev. Read more about dev-databases.
migrate/test
Run migration testing in CI.
Inputs
ATLAS_ACTION- (Required) Alwaysmigrate/test.ATLAS_TOKEN- (Optional) to authenticate with Atlas Cloud.BITBUCKET_ACCESS_TOKEN- (Optional) Bitbucket access token to post comment on the PR.ATLAS_INPUT_DIR- (Optional) The URL of the migration directory to apply. For example:atlas://dir-namefor cloud based directories orfile://migrationsfor local ones.ATLAS_INPUT_PATHS- (Optional) the list of directories containing test files.ATLAS_INPUT_REVISIONS_SCHEMA- (Optional) The name of the schema containing the revisions table.ATLAS_INPUT_RUN- (Optional) Filter tests to run by regexp. For example,^test_.*will only run tests that start withtest_. Default is to run all tests.ATLAS_INPUT_WORKING_DIRECTORY- (Optional) Atlas working directory, default is project rootATLAS_INPUT_CONFIG- (Optional) The URL of the Atlas configuration file. By default, Atlas will look for a file namedatlas.hclin the current directory. For example,file://config/atlas.hcl. Learn more about Atlas configuration files.ATLAS_INPUT_ENV- (Optional) The environment to use from the Atlas configuration file. For example,dev.ATLAS_INPUT_VARS- (Optional) A JSON object containing variables to be used in the Atlas configuration file. For example,{"var1": "value1", "var2": "value2"}.ATLAS_INPUT_DEV_URL- (Optional) The URL of the dev-database to use for analysis. For example:mysql://root:pass@localhost:3306/dev. Read more about dev-databases.
monitor/schema
Run schema monitoring for a target database, pushes the schema to the schema registry.