From e96e84d3f7fbadf2d0b0bffa7dab91846b279628 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Wed, 22 Nov 2023 10:32:13 +0200 Subject: [PATCH] cmd/atlas: allow extending config hcl parse options --- cmd/atlas/internal/cmdapi/cmdapi_oss.go | 4 ++++ cmd/atlas/internal/cmdapi/project.go | 2 +- doc/md/versioned/diff.mdx | 4 ++-- sql/postgres/diff.go | 7 +++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/atlas/internal/cmdapi/cmdapi_oss.go b/cmd/atlas/internal/cmdapi/cmdapi_oss.go index ced19e680e5..85db79f2175 100644 --- a/cmd/atlas/internal/cmdapi/cmdapi_oss.go +++ b/cmd/atlas/internal/cmdapi/cmdapi_oss.go @@ -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" @@ -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 diff --git a/cmd/atlas/internal/cmdapi/project.go b/cmd/atlas/internal/cmdapi/project.go index 889b5a900df..accb845b18b 100644 --- a/cmd/atlas/internal/cmdapi/project.go +++ b/cmd/atlas/internal/cmdapi/project.go @@ -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"), diff --git a/doc/md/versioned/diff.mdx b/doc/md/versioned/diff.mdx index 09d86d0b727..5381af8e746 100644 --- a/doc/md/versioned/diff.mdx +++ b/doc/md/versioned/diff.mdx @@ -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 } } } diff --git a/sql/postgres/diff.go b/sql/postgres/diff.go index 13693917b79..8d9a8f48f57 100644 --- a/sql/postgres/diff.go +++ b/sql/postgres/diff.go @@ -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"` } @@ -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: