atlas fmt check only
wyardley opened this issue · comments
For, e.g.,
atlas schema fmt
, currently, it seems to exit 0 whether files are modified or not:
% atlas schema fmt
maindb.hcl
% echo $?
0
% atlas schema fmt
% echo $?
0
Would it be possible to either exit non-0 when files are modified, or have a --check
flag, similar to Terraform's -check
flag, that just checks whether files would be modified and exits non-0 if they would be?
While it's certainly possible to see if there is output or not, it would be nice to be able to have a simple way to check if formatting is needed (for example, in CI checks)
Also, is there an easy way to check formatting (and validity) on the Atlas config (e.g., atlas.hcl
) itself?
One thing that does work is
% atlas schema apply --dry-run --to file://foo.hcl --url "docker://postgres/15/dev?search_path=public"
If that succeeds the config should be valid, and if not, it will fail with an error.
However, it would nice to be able to catch completely invalid HCL further left
schema "public" {
comment = "standard public schema"
}
table "foo" {
schema = schema.doesnotexist
column "bar" {
null = asdfasdf
type = character_varying(60)
}
It seems it should be possible for atlas
to tell us that asdfasdf
is not a valid value (vs. a bool) for null
without actually trying to run it. Happy to make a separate issue for this if it's valid and there isn't another way to do this already. Of course, in practice, the above approach is generally very fast and safe, but it would still be nice.
Side note, in case it's helpful to anyone; here's how I implemented this in GitHub actions for now, since there is no such command:
jobs:
atlas:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ariga/setup-atlas@v0
# Work around lack of a -check flag or similar for "atlas schema fmt"
# https://dev.to/mbjelac/github-action-output-to-if-expression-and-how-to-test-it-531i
- name: Check that schemas are formatted correctly via atlas schema fmt
run: echo "modified=$(atlas schema fmt)" >> $GITHUB_OUTPUT
id: fmt
- name: Fail if schema is not formatted via atlas schema fmt
if: steps.fmt.outputs.modified != null
run: |
echo "Unformatted files modified: ${{ steps.fmt.outputs.modified }}" >&2
echo "Use atlas schema fmt to fix this." >&2
exit 1