-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/commands: support schema plan (#25)
- Loading branch information
Showing
6 changed files
with
407 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
description: > | ||
Apply a declarative migrations to a database. | ||
parameters: | ||
to: | ||
type: string | ||
default: '' | ||
description: | | ||
The URL(s) of the desired schema state. | ||
url: | ||
type: string | ||
default: '' | ||
description: | | ||
The URL of the target database. For example: `mysql://root:pass@localhost:3306/prod`. | ||
plan: | ||
type: string | ||
default: '' | ||
description: | | ||
Optional plan file to use for applying the migrations. For example: `atlas://<schema>/plans/<id>`. | ||
dry_run: | ||
type: boolean | ||
default: false | ||
description: | | ||
Print SQL (and optional analysis) without executing it. Either `true` or `false`. Defaults to `false`. | ||
auto_approve: | ||
type: boolean | ||
default: false | ||
description: | | ||
Automatically approve and apply changes. Either `true` or `false`. Defaults to `false`. | ||
dev_url: | ||
type: string | ||
default: '' | ||
description: | | ||
The URL of the dev-database to use for analysis. For example: mysql://root:pass@localhost:3306/dev. | ||
Read more about [dev-databases](https://atlasgo.io/concepts/dev-database). | ||
config: | ||
type: string | ||
default: '' | ||
description: | | ||
The path to 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](https://atlasgo.io/atlas-schema/projects). | ||
vars: | ||
type: string | ||
default: '' | ||
description: | | ||
Stringify JSON object containing variables to be used inside the Atlas configuration file. For example: '{"var1": "value1", "var2": "value2"}' | ||
working_directory: | ||
type: string | ||
default: "." | ||
description: | | ||
The working directory to run from. Defaults to project root. | ||
env: | ||
type: string | ||
default: '' | ||
description: | | ||
The environment to use from the Atlas configuration file. For example, `dev`. | ||
steps: | ||
- run: | ||
name: Apply a declarative migrations to a database | ||
working_directory: <<parameters.working_directory>> | ||
command: atlasaction --action schema/apply | ||
environment: | ||
INPUT_TO: <<parameters.to>> | ||
INPUT_URL: <<parameters.url>> | ||
INPUT_PLAN: <<parameters.plan>> | ||
INPUT_DRY_RUN: <<parameters.dry_run>> | ||
INPUT_AUTO_APPROVE: <<parameters.auto_approve>> | ||
INPUT_DEV_URL: <<parameters.dev_url>> | ||
INPUT_CONFIG: <<parameters.config>> | ||
INPUT_ENV: <<parameters.env>> | ||
INPUT_VARS: <<parameters.vars>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
description: > | ||
Plan a declarative migration for a schema transition. | ||
parameters: | ||
schema_name: | ||
type: string | ||
default: '' | ||
description: | | ||
The name (slug) of the schema repository in [Atlas Registry](https://atlasgo.io/registry). | ||
from: | ||
type: string | ||
default: '' | ||
description: | | ||
URL(s) of the current schema state to transition from. | ||
to: | ||
type: string | ||
default: '' | ||
description: | | ||
URL(s) of the desired schema state to transition to. | ||
plan_name: | ||
type: string | ||
default: '' | ||
description: | | ||
Optional name for the plan. If not provided, a default plan is generated by Atlas. | ||
dev_url: | ||
type: string | ||
default: '' | ||
description: | | ||
The URL of the dev-database to use for analysis. For example: mysql://root:pass@localhost:3306/dev. | ||
Read more about [dev-databases](https://atlasgo.io/concepts/dev-database). | ||
config: | ||
type: string | ||
default: '' | ||
description: | | ||
The path to 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](https://atlasgo.io/atlas-schema/projects). | ||
vars: | ||
type: string | ||
default: '' | ||
description: | | ||
Extra variables to pass to the Atlas configuration file. For example, `key=value`. | ||
working_directory: | ||
type: string | ||
default: "." | ||
description: | | ||
The working directory to run from. Defaults to project root. | ||
env: | ||
type: string | ||
default: '' | ||
description: | | ||
The environment to use from the Atlas configuration file. For example, `dev`. | ||
github_repo_env: | ||
type: env_var_name | ||
default: GITHUB_REPOSITORY | ||
description: | | ||
The repository name that linting results will be posted to. | ||
github_token_env: | ||
type: env_var_name | ||
default: GITHUB_TOKEN | ||
description: | | ||
Environment variable containing the GitHub token. | ||
If provided, the command will authenticate to GitHub. | ||
(e.g. `GITHUB_TOKEN`) | ||
steps: | ||
- run: | ||
name: Plan a declarative migration for a schema transition | ||
working_directory: <<parameters.working_directory>> | ||
command: | | ||
# replace GITHUB_REPOSITORY with the github_repo_env if provided | ||
if [ -n "${<<parameters.github_repo_env>>}" ]; then | ||
GITHUB_REPOSITORY=${<<parameters.github_repo_env>>} | ||
fi | ||
# replace GITHUB_TOKEN with the github_token_env if provided | ||
if [ -n "${<<parameters.github_token_env>>}" ]; then | ||
GITHUB_TOKEN=${<<parameters.github_token_env>>} | ||
fi | ||
atlasaction --action schema/plan | ||
environment: | ||
INPUT_SCHEMA_NAME: <<parameters.schema_name>> | ||
INPUT_FROM: <<parameters.from>> | ||
INPUT_TO: <<parameters.to>> | ||
INPUT_NAME: <<parameters.plan_name>> | ||
INPUT_DEV_URL: <<parameters.dev_url>> | ||
INPUT_CONFIG: <<parameters.config>> | ||
INPUT_ENV: <<parameters.env>> | ||
INPUT_VARS: <<parameters.vars>> |
Oops, something went wrong.