Skip to content

Commit

Permalink
cmd/atlas/internal: skip reporting local directories (#2084)
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Sep 14, 2023
1 parent 4bc1570 commit d75f5a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 13 additions & 2 deletions cmd/atlas/internal/cmdapi/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,20 @@ If run with the "--dry-run" flag, atlas will not execute any SQL.`,
if err != nil {
return err
}
set := NewReportProvider(cmd.Context(), project, envs)
defer func() { set.Flush(cmd, cmdErr) }()
var (
hasRemote bool
set = NewReportProvider(cmd.Context(), project, envs)
)
defer func() {
if hasRemote {
set.Flush(cmd, cmdErr)
}
}()
return cmdEnvsRun(envs, setMigrateEnvFlags, cmd, func(env *Env) error {
// Report deployments only if one of the migration directories is a cloud directory.
if u, err := url.Parse(flags.dirURL); err == nil && u.Scheme != cmdmigrate.DirTypeFile {
hasRemote = true
}
return migrateApplyRun(cmd, args, flags, set.ReportFor(flags, env))
})
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/atlas/internal/cmdapi/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,8 @@ env {
require.Equal(t, "Error: openerror", *reports.Error)
})

t.Run("LocalFile", func(t *testing.T) {
t.Run("LocalDirectory", func(t *testing.T) {
report.DirName = "NotReported"
cmd := migrateCmd()
cmd.AddCommand(migrateApplyCmd())
_, err := runCmd(
Expand All @@ -985,7 +986,7 @@ env {
"--var", "cloud_url="+srv.URL,
)
require.NoError(t, err)
require.Equal(t, cloudapi.DefaultDirName, report.DirName)
require.Equal(t, "NotReported", report.DirName)
})
}

Expand Down

0 comments on commit d75f5a6

Please sign in to comment.