-
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 migrate lint (#8)
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 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,53 @@ | ||
description: > | ||
This command lints the migration directory before pushing to Atlas Cloud. | ||
parameters: | ||
dir: | ||
type: string | ||
default: "" | ||
description: | | ||
The URL of the migration directory to lint. For example: file://migrations. | ||
Read more about [Atlas URLs](https://atlasgo.io/concepts/url) | ||
dir_name: | ||
type: string | ||
description: | | ||
The name (slug) of the project in Atlas Cloud. | ||
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`. | ||
steps: | ||
- run: | ||
name: Lint migrations to Atlas Cloud | ||
command: <<include(scripts/migrate-lint.sh)>> | ||
working_directory: <<parameters.working_directory>> | ||
environment: | ||
PARAM_DIR_NAME: <<parameters.dir_name>> | ||
PARAM_DIR: <<parameters.dir>> | ||
PARAM_CONFIG: <<parameters.config>> | ||
PARAM_ENV: <<parameters.env>> | ||
PARAM_VARS: <<parameters.vars>> | ||
PARAM_DEV_URL: <<parameters.dev_url>> |
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,31 @@ | ||
#!/bin/bash | ||
|
||
DIR_NAME=$(circleci env subst "${PARAM_DIR_NAME}") | ||
DIR=$(circleci env subst "${PARAM_DIR}") | ||
CONFIG=$(circleci env subst "${PARAM_CONFIG}") | ||
ENV=$(circleci env subst "${PARAM_ENV}") | ||
VARS=$(circleci env subst "${PARAM_VARS}") | ||
DEV_URL=$(circleci env subst "${PARAM_DEV_URL}") | ||
|
||
ARGS="$ARGS --dev-url $DEV_URL" | ||
if [ -n "$DIR" ]; then | ||
ARGS="$ARGS --dir $DIR" | ||
fi | ||
if [ -n "$DIR_NAME" ]; then | ||
ARGS="$ARGS --base atlas://$DIR_NAME" | ||
fi | ||
if [ -n "$CONFIG" ]; then | ||
ARGS="$ARGS --config $CONFIG" | ||
fi | ||
if [ -n "$ENV" ]; then | ||
ARGS="$ARGS --env $ENV" | ||
fi | ||
if [ -n "$VARS" ]; then | ||
for _var in $VARS | ||
do | ||
ARGS="$ARGS --var $_var" | ||
done | ||
fi | ||
|
||
# shellcheck disable=SC2086 | ||
atlas migrate lint $ARGS |