Skip to content

Commit

Permalink
src/commands: support schema push (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao authored Oct 3, 2024
1 parent 52d5b24 commit cfa1ea9
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,45 @@ jobs:
grep -qe "INPUT_CONFIG=file://atlas.hcl" /tmp/env.out
# check vars should be set in the environment
grep -qe "INPUT_VARS={\"foo\": \"bar\", \"baz\": \"qux\", \"quux\": \"corge\"}" /tmp/env.out
command-test-schema-push:
executor: atlas-orb/default
steps:
- checkout
- run:
name: Mock atlas with echo.sh
command: |
sudo cp ./src/scripts/echo.sh /bin/atlas
sudo cp ./src/scripts/echo.sh /bin/atlasaction
- atlas-orb/schema_push:
working_directory: testdata
schema_name: "my-cool-project"
tag: "tag"
latest: true
url: "postgres://postgres:pass@localhost:5432/test?sslmode=disable"
dev_url: "postgres://postgres:pass@localhost:5432/dev?sslmode=disable"
env: "circleci-test"
config: "file://atlas.hcl"
vars: '{"foo": "bar", "baz": "qux", "quux": "corge"}'
- run:
name: Check echo.out for expected output
command: |
grep -qe "--action schema/push" /tmp/echo.out
# check schema_name should be set in the environment
grep -qe "INPUT_SCHEMA_NAME=my-cool-project" /tmp/env.out
# check tag should be set in the environment
grep -qe "INPUT_TAG=tag" /tmp/env.out
# check latest should be set in the environment
grep -qe "INPUT_LATEST=1" /tmp/env.out
# check url should be set in the environment
grep -qe "INPUT_URL=postgres://postgres:pass@localhost:5432/test?sslmode=disable" /tmp/env.out
# check dev_url should be set in the environment
grep -qe "INPUT_DEV_URL=postgres://postgres:pass@localhost:5432/dev?sslmode=disable" /tmp/env.out
# check env should be set in the environment
grep -qe "INPUT_ENV=circleci-test" /tmp/env.out
# check config should be set in the environment
grep -qe "INPUT_CONFIG=file://atlas.hcl" /tmp/env.out
# check vars should be set in the environment
grep -qe "INPUT_VARS={\"foo\": \"bar\", \"baz\": \"qux\", \"quux\": \"corge\"}" /tmp/env.out
integration-test-versioned:
docker:
- image: cimg/base:current
Expand Down Expand Up @@ -424,6 +463,34 @@ jobs:
run: "expected_failure"
dir: atlas://my-cool-project
dev_url: postgres://postgres:pass@localhost:5432/test?sslmode=disable
integration-test-declarative-gh:
docker:
- image: cimg/base:current
- image: cimg/postgres:16.2
environment:
POSTGRES_USER: postgres
POSTGRES_DB: test
POSTGRES_PASSWORD: pass
environment:
GITHUB_REPOSITORY: "ariga/atlas-orb"
steps:
- checkout
- run:
name: Wait for Postgres
command: dockerize -wait tcp://localhost:5432 -timeout 60s
- run:
name: Create "dev" database
command: |
psql postgres://postgres:pass@localhost:5432 -c "CREATE DATABASE dev;"
- atlas-orb/setup:
version: "latest"
cloud_token_env: "ATLAS_TOKEN"
- atlas-orb/schema_push:
working_directory: testdata/schema-push
schema_name: "circleci-schema-test"
tag: "latest"
url: "postgres://postgres:pass@localhost:5432/test?sslmode=disable"
dev_url: postgres://postgres:pass@localhost:5432/dev?sslmode=disable
integration-test-declarative-gh-test:
docker:
- image: cimg/base:current
Expand Down Expand Up @@ -474,6 +541,8 @@ workflows:
filters: *filters
- command-test-schema-test:
filters: *filters
- command-test-schema-push:
filters: *filters
- integration-test-versioned:
context: ariga-atlas
filters: *filters
Expand Down Expand Up @@ -512,6 +581,14 @@ workflows:
requires:
- command-test-setup
- command-test-schema-test
- command-test-schema-push
- integration-test-declarative-gh:
context: ariga-atlas-gh
filters: *filters
requires:
- command-test-setup
- command-test-schema-test
- command-test-schema-push
- integration-test-declarative-gh-test:
context: ariga-atlas-gh
filters: *filters
Expand Down
65 changes: 65 additions & 0 deletions src/commands/schema_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
description: >
Push a schema to [Atlas Registry](https://atlasgo.io/registry) with an optional tag.
parameters:
schema_name:
type: string
default: ''
description: |
The name (slug) of the schema repository in [Atlas Registry](https://atlasgo.io/registry).
tag:
type: string
default: ''
description: |
The tag to apply to the pushed schema. By default, the current git commit hash is used.
latest:
type: boolean
default: false
description: |
If true, the pushed schema will be tagged as `latest`.
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).
url:
type: string
default: ''
description: |
The desired schema URL(s) to test. For Example: `file://schema.hcl`
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: Test schema on a database
working_directory: <<parameters.working_directory>>
command: atlasaction --action schema/push
environment:
INPUT_SCHEMA_NAME: <<parameters.schema_name>>
INPUT_TAG: <<parameters.tag>>
INPUT_LATEST: <<parameters.latest>>
INPUT_DEV_URL: <<parameters.dev_url>>
INPUT_URL: <<parameters.url>>
INPUT_CONFIG: <<parameters.config>>
INPUT_ENV: <<parameters.env>>
INPUT_VARS: <<parameters.vars>>

0 comments on commit cfa1ea9

Please sign in to comment.