Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/postgres-launch-stage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `postgres_*` bundle resources are no longer labelled `[Beta]` in the JSON schema and are now available in PyDABs. ([#7705](https://github.com/databricks/cli/pull/7705))
12 changes: 1 addition & 11 deletions bundle/internal/annotation/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,7 @@ func PreviewTag(stage clijson.LaunchStage) string {
// change cannot silently alter the resource's label. Keys are the
// fully-qualified Go type paths (PkgPath + "." + Name), matching getPath in
// bundle/internal/schema.
var launchStageOverrides = map[string]clijson.LaunchStage{
"github.com/databricks/cli/bundle/config/resources.PostgresBranch": clijson.LaunchStagePublicBeta,
"github.com/databricks/cli/bundle/config/resources.PostgresCatalog": clijson.LaunchStagePublicBeta,
"github.com/databricks/cli/bundle/config/resources.PostgresDataApi": clijson.LaunchStagePrivatePreview, // The Data API is at Private Preview, below its siblings' Beta.
"github.com/databricks/cli/bundle/config/resources.PostgresDatabase": clijson.LaunchStagePublicBeta,
"github.com/databricks/cli/bundle/config/resources.PostgresEndpoint": clijson.LaunchStagePublicBeta,
"github.com/databricks/cli/bundle/config/resources.PostgresProject": clijson.LaunchStagePublicBeta,
"github.com/databricks/cli/bundle/config/resources.PostgresRole": clijson.LaunchStagePublicBeta,
"github.com/databricks/cli/bundle/config/resources.PostgresSnapshotSchedule": clijson.LaunchStagePublicBeta,
"github.com/databricks/cli/bundle/config/resources.PostgresSyncedTable": clijson.LaunchStagePublicBeta,
}
var launchStageOverrides = map[string]clijson.LaunchStage{}

// OverrideLaunchStage raises a field's launch stage to the type's configured
// override, unless the field's own stage is already more restrictive (see
Expand Down
35 changes: 35 additions & 0 deletions bundle/internal/annotation/preview_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package annotation

import (
"testing"

"github.com/databricks/cli/internal/clijson"
"github.com/stretchr/testify/assert"
)

// No resource is overridden at the moment, so the test installs its own
// override to keep the raising and more-restrictive paths covered.
func TestOverrideLaunchStage(t *testing.T) {
const overridden = "github.com/databricks/cli/bundle/config/resources.Job"
saved := launchStageOverrides
launchStageOverrides = map[string]clijson.LaunchStage{overridden: clijson.LaunchStagePublicBeta}
t.Cleanup(func() { launchStageOverrides = saved })

tests := []struct {
name string
typePath string
stage clijson.LaunchStage
want clijson.LaunchStage
}{
{"GA field is raised to the override", overridden, "", clijson.LaunchStagePublicBeta},
{"less-restrictive public-preview field is raised", overridden, clijson.LaunchStagePublicPreview, clijson.LaunchStagePublicBeta},
{"Beta field is unchanged", overridden, clijson.LaunchStagePublicBeta, clijson.LaunchStagePublicBeta},
{"more-restrictive private-preview field is kept", overridden, clijson.LaunchStagePrivatePreview, clijson.LaunchStagePrivatePreview},
{"field of a type with no override is unchanged", "github.com/databricks/cli/bundle/config/resources.Pipeline", "", ""},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, OverrideLaunchStage(tc.typePath, tc.stage))
})
}
}
21 changes: 0 additions & 21 deletions bundle/internal/annotation/preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,3 @@ func TestPreviewTagCoversAllStages(t *testing.T) {
assert.NotEmpty(t, annotation.PreviewTag(stage), "stage %q has no preview tag", stage)
}
}

func TestOverrideLaunchStage(t *testing.T) {
const overridden = "github.com/databricks/cli/bundle/config/resources.PostgresProject"
tests := []struct {
name string
typePath string
stage clijson.LaunchStage
want clijson.LaunchStage
}{
{"GA field is raised to the override", overridden, "", clijson.LaunchStagePublicBeta},
{"less-restrictive public-preview field is raised", overridden, clijson.LaunchStagePublicPreview, clijson.LaunchStagePublicBeta},
{"Beta field is unchanged", overridden, clijson.LaunchStagePublicBeta, clijson.LaunchStagePublicBeta},
{"more-restrictive private-preview field is kept", overridden, clijson.LaunchStagePrivatePreview, clijson.LaunchStagePrivatePreview},
{"field of a type with no override is unchanged", "github.com/databricks/cli/bundle/config/resources.Job", "", ""},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, annotation.OverrideLaunchStage(tc.typePath, tc.stage))
})
}
}
98 changes: 0 additions & 98 deletions bundle/internal/schema/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package main

import (
"reflect"
"strings"
"testing"

"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/bundle/internal/annotation"
"github.com/databricks/cli/internal/clijson"
"github.com/databricks/databricks-sdk-go/service/postgres"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -71,100 +67,6 @@ func TestExtractAnnotationsNestedEmbeddedSDKType(t *testing.T) {
assert.Equal(t, clijson.LaunchStagePublicBeta, got.LaunchStage)
}

// TestPostgresResourcesHaveLaunchStageOverride asserts every Postgres resource
// type is pinned to its expected stage (Beta, or Private Preview for the Data
// API) via a launch-stage override, so an upstream stage change cannot silently
// alter its label (see annotation.OverrideLaunchStage).
//
// postgresResources is spelled out explicitly so the expected set is visible on
// the page, but it is also cross-checked against the Postgres resources actually
// declared on config.Resources: a new resource missing from this list fails the
// completeness check, which is the reminder to add it here AND to
// launchStageOverrides in bundle/internal/annotation/preview.go.
func TestPostgresResourcesHaveLaunchStageOverride(t *testing.T) {
postgresResources := map[reflect.Type]clijson.LaunchStage{
reflect.TypeFor[resources.PostgresBranch](): clijson.LaunchStagePublicBeta,
reflect.TypeFor[resources.PostgresCatalog](): clijson.LaunchStagePublicBeta,
reflect.TypeFor[resources.PostgresDataApi](): clijson.LaunchStagePrivatePreview,
reflect.TypeFor[resources.PostgresDatabase](): clijson.LaunchStagePublicBeta,
reflect.TypeFor[resources.PostgresEndpoint](): clijson.LaunchStagePublicBeta,
reflect.TypeFor[resources.PostgresProject](): clijson.LaunchStagePublicBeta,
reflect.TypeFor[resources.PostgresRole](): clijson.LaunchStagePublicBeta,
reflect.TypeFor[resources.PostgresSnapshotSchedule](): clijson.LaunchStagePublicBeta,
reflect.TypeFor[resources.PostgresSyncedTable](): clijson.LaunchStagePublicBeta,
}

// The list must cover every Postgres resource on config.Resources, so a
// newly added one can't slip through unpinned.
listed := make(map[reflect.Type]bool, len(postgresResources))
for typ := range postgresResources {
listed[typ] = true
}
for _, f := range reflect.VisibleFields(reflect.TypeFor[config.Resources]()) {
if !strings.HasPrefix(f.Name, "Postgres") {
continue
}
// Each resource is a map[string]*resources.PostgresX; unwrap to the
// element struct the schema generator keys annotations by.
elem := f.Type.Elem()
for elem.Kind() == reflect.Pointer {
elem = elem.Elem()
}
assert.Truef(t, listed[elem],
"resource %s (%s) is not covered by this test; add it to postgresResources", f.Name, getPath(elem))
}

for typ, want := range postgresResources {
typePath := getPath(typ)
// A configured type returns its override for any input; an unconfigured
// one returns the input unchanged, so a GA input that survives as GA
// (rather than becoming Beta) means the override is missing.
stage := annotation.OverrideLaunchStage(typePath, clijson.LaunchStageGA)
assert.Equalf(t, want, stage,
"resource %s has no launch-stage override; add it to launchStageOverrides in bundle/internal/annotation/preview.go", typePath)
}
}

// TestExtractAnnotationsOverridesLaunchStage feeds a GA launch stage for a real
// field of an overridden resource and asserts extractAnnotations rewrites it to
// the override, so an upstream stage change does not alter the label.
// auth_method is a field of postgres.RoleRoleSpec, embedded by
// resources.PostgresRole.
func TestExtractAnnotationsOverridesLaunchStage(t *testing.T) {
p := newParser(map[string]*clijson.SchemaJSON{
"postgres.RoleRoleSpec": {
Fields: map[string]*clijson.SchemaFieldJSON{
"auth_method": {
Description: "How the role authenticates.",
LaunchStage: "GA",
},
},
},
})

annotations, err := p.extractAnnotations(reflect.TypeFor[resources.PostgresRole]())
require.NoError(t, err)

got := annotations[getPath(reflect.TypeFor[resources.PostgresRole]())].Fields["auth_method"]
assert.Equal(t, clijson.LaunchStagePublicBeta, got.LaunchStage)
}

// TestExtractAnnotationsStampsTypeLaunchStage asserts a resource type in the
// override map carries the override stage on its own (self) descriptor, so the
// type-level x-databricks-launch-stage is emitted, not just its fields'. The
// contract carries no type-level stage, so the override map is the only source.
func TestExtractAnnotationsStampsTypeLaunchStage(t *testing.T) {
p := newParser(map[string]*clijson.SchemaJSON{
"postgres.RoleRoleSpec": {Fields: map[string]*clijson.SchemaFieldJSON{}},
})

annotations, err := p.extractAnnotations(reflect.TypeFor[resources.PostgresRole]())
require.NoError(t, err)

self := annotations[getPath(reflect.TypeFor[resources.PostgresRole]())].Self
assert.Equal(t, clijson.LaunchStagePublicBeta, self.LaunchStage)
}

func TestNormalizeLaunchStage(t *testing.T) {
tests := []struct {
input string
Expand Down
Loading
Loading