Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-swinkler committed Jan 18, 2024
1 parent 1561301 commit a45ae52
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 89 deletions.
20 changes: 14 additions & 6 deletions pkg/sdk/application_packages_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ var applicationPackageSet = g.NewQueryStruct("ApplicationPackageSet").
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()).
PredefinedQueryStructField("Distribution", "*Distribution", g.ParameterOptions().SQL("DISTRIBUTION"))

var applicationPackageUnset = g.NewQueryStruct("ApplicationPackageUnset").
OptionalSQL("DATA_RETENTION_TIME_IN_DAYS").
OptionalSQL("MAX_DATA_EXTENSION_TIME_IN_DAYS").
OptionalSQL("DEFAULT_DDL_COLLATION").
OptionalSQL("COMMENT").
OptionalSQL("DISTRIBUTION").
WithValidation(g.ExactlyOneValueSet, "DataRetentionTimeInDays", "MaxDataExtensionTimeInDays", "DefaultDdlCollation", "Comment", "Distribution")

var ApplicationPackagesDef = g.NewInterface(
"ApplicationPackages",
"ApplicationPackage",
Expand Down Expand Up @@ -72,11 +80,11 @@ var ApplicationPackagesDef = g.NewInterface(
applicationPackageSet,
g.KeywordOptions().SQL("SET"),
).
OptionalSQL("UNSET DATA_RETENTION_TIME_IN_DAYS").
OptionalSQL("UNSET MAX_DATA_EXTENSION_TIME_IN_DAYS").
OptionalSQL("UNSET DEFAULT_DDL_COLLATION").
OptionalSQL("UNSET COMMENT").
OptionalSQL("UNSET DISTRIBUTION").
OptionalQueryStructField(
"Unset",
applicationPackageUnset,
g.KeywordOptions().SQL("UNSET"),
).
OptionalQueryStructField(
"ModifyReleaseDirective",
applicationPackageModifyReleaseDirective,
Expand Down Expand Up @@ -115,7 +123,7 @@ var ApplicationPackagesDef = g.NewInterface(
OptionalSetTags().
OptionalUnsetTags().
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ExactlyOneValueSet, "Set", "UnsetDataRetentionTimeInDays", "UnsetMaxDataExtensionTimeInDays", "UnsetDefaultDdlCollation", "UnsetComment", "UnsetDistribution", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"),
WithValidation(g.ExactlyOneValueSet, "Set", "Unset", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"),
).DropOperation(
"https://docs.snowflake.com/en/sql-reference/sql/drop-application-package",
g.NewQueryStruct("DropApplicationPackage").
Expand Down
53 changes: 31 additions & 22 deletions pkg/sdk/application_packages_dto_builders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 21 additions & 17 deletions pkg/sdk/application_packages_dto_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@ type CreateApplicationPackageRequest struct {
}

type AlterApplicationPackageRequest struct {
IfExists *bool
name AccountObjectIdentifier // required
Set *ApplicationPackageSetRequest
UnsetDataRetentionTimeInDays *bool
UnsetMaxDataExtensionTimeInDays *bool
UnsetDefaultDdlCollation *bool
UnsetComment *bool
UnsetDistribution *bool
ModifyReleaseDirective *ModifyReleaseDirectiveRequest
SetDefaultReleaseDirective *SetDefaultReleaseDirectiveRequest
SetReleaseDirective *SetReleaseDirectiveRequest
UnsetReleaseDirective *UnsetReleaseDirectiveRequest
AddVersion *AddVersionRequest
DropVersion *DropVersionRequest
AddPatchForVersion *AddPatchForVersionRequest
SetTags []TagAssociation
UnsetTags []ObjectIdentifier
IfExists *bool
name AccountObjectIdentifier // required
Set *ApplicationPackageSetRequest
Unset *ApplicationPackageUnsetRequest
ModifyReleaseDirective *ModifyReleaseDirectiveRequest
SetDefaultReleaseDirective *SetDefaultReleaseDirectiveRequest
SetReleaseDirective *SetReleaseDirectiveRequest
UnsetReleaseDirective *UnsetReleaseDirectiveRequest
AddVersion *AddVersionRequest
DropVersion *DropVersionRequest
AddPatchForVersion *AddPatchForVersionRequest
SetTags []TagAssociation
UnsetTags []ObjectIdentifier
}

type ApplicationPackageSetRequest struct {
Expand All @@ -48,6 +44,14 @@ type ApplicationPackageSetRequest struct {
Distribution *Distribution
}

type ApplicationPackageUnsetRequest struct {
DataRetentionTimeInDays *bool
MaxDataExtensionTimeInDays *bool
DefaultDdlCollation *bool
Comment *bool
Distribution *bool
}

type ModifyReleaseDirectiveRequest struct {
ReleaseDirective string // required
Version string // required
Expand Down
42 changes: 23 additions & 19 deletions pkg/sdk/application_packages_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,21 @@ type CreateApplicationPackageOptions struct {

// AlterApplicationPackageOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-application-package.
type AlterApplicationPackageOptions struct {
alter bool `ddl:"static" sql:"ALTER"`
applicationPackage bool `ddl:"static" sql:"APPLICATION PACKAGE"`
IfExists *bool `ddl:"keyword" sql:"IF EXISTS"`
name AccountObjectIdentifier `ddl:"identifier"`
Set *ApplicationPackageSet `ddl:"keyword" sql:"SET"`
UnsetDataRetentionTimeInDays *bool `ddl:"keyword" sql:"UNSET DATA_RETENTION_TIME_IN_DAYS"`
UnsetMaxDataExtensionTimeInDays *bool `ddl:"keyword" sql:"UNSET MAX_DATA_EXTENSION_TIME_IN_DAYS"`
UnsetDefaultDdlCollation *bool `ddl:"keyword" sql:"UNSET DEFAULT_DDL_COLLATION"`
UnsetComment *bool `ddl:"keyword" sql:"UNSET COMMENT"`
UnsetDistribution *bool `ddl:"keyword" sql:"UNSET DISTRIBUTION"`
ModifyReleaseDirective *ModifyReleaseDirective `ddl:"keyword" sql:"MODIFY RELEASE DIRECTIVE"`
SetDefaultReleaseDirective *SetDefaultReleaseDirective `ddl:"keyword" sql:"SET DEFAULT RELEASE DIRECTIVE"`
SetReleaseDirective *SetReleaseDirective `ddl:"keyword" sql:"SET RELEASE DIRECTIVE"`
UnsetReleaseDirective *UnsetReleaseDirective `ddl:"keyword" sql:"UNSET RELEASE DIRECTIVE"`
AddVersion *AddVersion `ddl:"keyword" sql:"ADD VERSION"`
DropVersion *DropVersion `ddl:"keyword" sql:"DROP VERSION"`
AddPatchForVersion *AddPatchForVersion `ddl:"keyword" sql:"ADD PATCH FOR VERSION"`
SetTags []TagAssociation `ddl:"keyword" sql:"SET TAG"`
UnsetTags []ObjectIdentifier `ddl:"keyword" sql:"UNSET TAG"`
alter bool `ddl:"static" sql:"ALTER"`
applicationPackage bool `ddl:"static" sql:"APPLICATION PACKAGE"`
IfExists *bool `ddl:"keyword" sql:"IF EXISTS"`
name AccountObjectIdentifier `ddl:"identifier"`
Set *ApplicationPackageSet `ddl:"keyword" sql:"SET"`
Unset *ApplicationPackageUnset `ddl:"keyword" sql:"UNSET"`
ModifyReleaseDirective *ModifyReleaseDirective `ddl:"keyword" sql:"MODIFY RELEASE DIRECTIVE"`
SetDefaultReleaseDirective *SetDefaultReleaseDirective `ddl:"keyword" sql:"SET DEFAULT RELEASE DIRECTIVE"`
SetReleaseDirective *SetReleaseDirective `ddl:"keyword" sql:"SET RELEASE DIRECTIVE"`
UnsetReleaseDirective *UnsetReleaseDirective `ddl:"keyword" sql:"UNSET RELEASE DIRECTIVE"`
AddVersion *AddVersion `ddl:"keyword" sql:"ADD VERSION"`
DropVersion *DropVersion `ddl:"keyword" sql:"DROP VERSION"`
AddPatchForVersion *AddPatchForVersion `ddl:"keyword" sql:"ADD PATCH FOR VERSION"`
SetTags []TagAssociation `ddl:"keyword" sql:"SET TAG"`
UnsetTags []ObjectIdentifier `ddl:"keyword" sql:"UNSET TAG"`
}

type ApplicationPackageSet struct {
Expand All @@ -58,6 +54,14 @@ type ApplicationPackageSet struct {
Distribution *Distribution `ddl:"parameter" sql:"DISTRIBUTION"`
}

type ApplicationPackageUnset struct {
DataRetentionTimeInDays *bool `ddl:"keyword" sql:"DATA_RETENTION_TIME_IN_DAYS"`
MaxDataExtensionTimeInDays *bool `ddl:"keyword" sql:"MAX_DATA_EXTENSION_TIME_IN_DAYS"`
DefaultDdlCollation *bool `ddl:"keyword" sql:"DEFAULT_DDL_COLLATION"`
Comment *bool `ddl:"keyword" sql:"COMMENT"`
Distribution *bool `ddl:"keyword" sql:"DISTRIBUTION"`
}

type ModifyReleaseDirective struct {
ReleaseDirective string `ddl:"keyword,no_quotes"`
Version string `ddl:"parameter,no_quotes" sql:"VERSION"`
Expand Down
26 changes: 18 additions & 8 deletions pkg/sdk/application_packages_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestApplicationPackages_Alter(t *testing.T) {

t.Run("validation: exactly one field should be present", func(t *testing.T) {
opts := defaultOpts()
assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterApplicationPackageOptions", "Set", "UnsetDataRetentionTimeInDays", "UnsetMaxDataExtensionTimeInDays", "UnsetDefaultDdlCollation", "UnsetComment", "UnsetDistribution", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"))
assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterApplicationPackageOptions", "Set", "Unset", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"))
})

t.Run("validation: exactly one field should be present", func(t *testing.T) {
Expand All @@ -76,7 +76,7 @@ func TestApplicationPackages_Alter(t *testing.T) {
opts.UnsetReleaseDirective = &UnsetReleaseDirective{
ReleaseDirective: "DEFAULT",
}
assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterApplicationPackageOptions", "Set", "UnsetDataRetentionTimeInDays", "UnsetMaxDataExtensionTimeInDays", "UnsetDefaultDdlCollation", "UnsetComment", "UnsetDistribution", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"))
assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterApplicationPackageOptions", "Set", "Unset", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"))
})

t.Run("alter: set options", func(t *testing.T) {
Expand All @@ -93,23 +93,33 @@ func TestApplicationPackages_Alter(t *testing.T) {

t.Run("alter: unset options", func(t *testing.T) {
opts := defaultOpts()
opts.UnsetComment = Bool(true)
opts.Unset = &ApplicationPackageUnset{
Comment: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET COMMENT`, id.FullyQualifiedName())

opts = defaultOpts()
opts.UnsetDataRetentionTimeInDays = Bool(true)
opts.Unset = &ApplicationPackageUnset{
DataRetentionTimeInDays: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET DATA_RETENTION_TIME_IN_DAYS`, id.FullyQualifiedName())

opts = defaultOpts()
opts.UnsetMaxDataExtensionTimeInDays = Bool(true)
opts.Unset = &ApplicationPackageUnset{
MaxDataExtensionTimeInDays: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET MAX_DATA_EXTENSION_TIME_IN_DAYS`, id.FullyQualifiedName())

opts = defaultOpts()
opts.UnsetDefaultDdlCollation = Bool(true)
opts.Unset = &ApplicationPackageUnset{
DefaultDdlCollation: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET DEFAULT_DDL_COLLATION`, id.FullyQualifiedName())

opts = defaultOpts()
opts.UnsetDistribution = Bool(true)
opts.Unset = &ApplicationPackageUnset{
Distribution: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET DISTRIBUTION`, id.FullyQualifiedName())
})

Expand Down Expand Up @@ -209,7 +219,7 @@ func TestApplicationPackages_Alter(t *testing.T) {
Using: "@hello_snowflake_code.core.hello_snowflake_stage",
Label: String("test"),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s ADD PATCH FOR VERSION v1_1 USING '@hello_snowflake_code.core.hello_snowflake_stage' Label = 'test'`, id.FullyQualifiedName())
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s ADD PATCH FOR VERSION v1_1 USING '@hello_snowflake_code.core.hello_snowflake_stage' LABEL = 'test'`, id.FullyQualifiedName())
})
}

Expand Down
15 changes: 9 additions & 6 deletions pkg/sdk/application_packages_impl_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ func (r *AlterApplicationPackageRequest) toOpts() *AlterApplicationPackageOption
IfExists: r.IfExists,
name: r.name,

UnsetDataRetentionTimeInDays: r.UnsetDataRetentionTimeInDays,
UnsetMaxDataExtensionTimeInDays: r.UnsetMaxDataExtensionTimeInDays,
UnsetDefaultDdlCollation: r.UnsetDefaultDdlCollation,
UnsetComment: r.UnsetComment,
UnsetDistribution: r.UnsetDistribution,

SetTags: r.SetTags,
UnsetTags: r.UnsetTags,
}
Expand All @@ -83,6 +77,15 @@ func (r *AlterApplicationPackageRequest) toOpts() *AlterApplicationPackageOption
Distribution: r.Set.Distribution,
}
}
if r.Unset != nil {
opts.Unset = &ApplicationPackageUnset{
DataRetentionTimeInDays: r.Unset.DataRetentionTimeInDays,
MaxDataExtensionTimeInDays: r.Unset.MaxDataExtensionTimeInDays,
DefaultDdlCollation: r.Unset.DefaultDdlCollation,
Comment: r.Unset.Comment,
Distribution: r.Unset.Distribution,
}
}
if r.ModifyReleaseDirective != nil {
opts.ModifyReleaseDirective = &ModifyReleaseDirective{
ReleaseDirective: r.ModifyReleaseDirective.ReleaseDirective,
Expand Down
9 changes: 7 additions & 2 deletions pkg/sdk/application_packages_validations_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ func (opts *AlterApplicationPackageOptions) validate() error {
if !ValidObjectIdentifier(opts.name) {
errs = append(errs, ErrInvalidObjectIdentifier)
}
if !exactlyOneValueSet(opts.Set, opts.UnsetDataRetentionTimeInDays, opts.UnsetMaxDataExtensionTimeInDays, opts.UnsetDefaultDdlCollation, opts.UnsetComment, opts.UnsetDistribution, opts.ModifyReleaseDirective, opts.SetDefaultReleaseDirective, opts.SetReleaseDirective, opts.UnsetReleaseDirective, opts.AddVersion, opts.DropVersion, opts.AddPatchForVersion, opts.SetTags, opts.UnsetTags) {
errs = append(errs, errExactlyOneOf("AlterApplicationPackageOptions", "Set", "UnsetDataRetentionTimeInDays", "UnsetMaxDataExtensionTimeInDays", "UnsetDefaultDdlCollation", "UnsetComment", "UnsetDistribution", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"))
if !exactlyOneValueSet(opts.Set, opts.Unset, opts.ModifyReleaseDirective, opts.SetDefaultReleaseDirective, opts.SetReleaseDirective, opts.UnsetReleaseDirective, opts.AddVersion, opts.DropVersion, opts.AddPatchForVersion, opts.SetTags, opts.UnsetTags) {
errs = append(errs, errExactlyOneOf("AlterApplicationPackageOptions", "Set", "Unset", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"))
}
if valueSet(opts.Unset) {
if !exactlyOneValueSet(opts.Unset.DataRetentionTimeInDays, opts.Unset.MaxDataExtensionTimeInDays, opts.Unset.DefaultDdlCollation, opts.Unset.Comment, opts.Unset.Distribution) {
errs = append(errs, errExactlyOneOf("AlterApplicationPackageOptions.Unset", "DataRetentionTimeInDays", "MaxDataExtensionTimeInDays", "DefaultDdlCollation", "Comment", "Distribution"))
}
}
return JoinErrors(errs...)
}
Expand Down
Loading

0 comments on commit a45ae52

Please sign in to comment.