Skip to content

Commit

Permalink
cmd/atlas: allow extending config hcl parse options
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Nov 22, 2023
1 parent 3144d0d commit e96e84d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/atlas/internal/cmdapi/cmdapi_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"ariga.io/atlas/cmd/atlas/internal/cloudapi"
cmdmigrate "ariga.io/atlas/cmd/atlas/internal/migrate"
"ariga.io/atlas/cmd/atlas/internal/migratelint"
"ariga.io/atlas/schemahcl"
"ariga.io/atlas/sql/migrate"
"ariga.io/atlas/sql/sqlcheck"
"ariga.io/atlas/sql/sqlclient"
Expand Down Expand Up @@ -129,3 +130,6 @@ func withTokenContext(ctx context.Context, _ string, _ *cloudapi.Client) (contex
func checkDirRebased(context.Context, *cobra.Command, migrate.Dir) error {
return nil // unimplemented.
}

// specOptions are the options for the schema spec.
var specOptions []schemahcl.Option
2 changes: 1 addition & 1 deletion cmd/atlas/internal/cmdapi/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func parseConfig(path, env string, vars map[string]cty.Value) (*Project, error)
}
state := schemahcl.New(
append(
cmdext.DataSources,
append(cmdext.DataSources, specOptions...),
cfg.InitBlock(),
schemahcl.WithScopedEnums("env.migration.format", cmdmigrate.Formats...),
schemahcl.WithScopedEnums("env.migration.exec_order", "LINEAR", "LINEAR_SKIP", "NON_LINEAR"),
Expand Down
4 changes: 2 additions & 2 deletions doc/md/versioned/diff.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,8 @@ env "local" {
diff {
// By default, indexes are not created or dropped concurrently.
concurrent_index {
create = true
drop = true
add = true
drop = true
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions sql/postgres/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@ func (*diff) ReferenceChanged(from, to schema.ReferenceOption) bool {
// DiffOptions defines PostgreSQL specific schema diffing process.
type DiffOptions struct {
ConcurrentIndex struct {
Add bool `spec:"add"`
Drop bool `spec:"drop"`
// Allow config "CREATE" both with "add" and "create"
// as the documentation used both terms (accidentally).
Add bool `spec:"add"`
Create bool `spec:"create"`
} `spec:"concurrent_index"`
}

Expand All @@ -270,7 +273,7 @@ func (*diff) AnnotateChanges(changes []schema.Change, opts *schema.DiffOptions)
for i := range m.Changes {
switch c := m.Changes[i].(type) {
case *schema.AddIndex:
if extra.ConcurrentIndex.Add {
if extra.ConcurrentIndex.Add || extra.ConcurrentIndex.Create {
c.Extra = append(c.Extra, &Concurrently{})
}
case *schema.DropIndex:
Expand Down

0 comments on commit e96e84d

Please sign in to comment.