Skip to content

Commit

Permalink
Fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Dec 7, 2023
1 parent ea2e35a commit 6f924bd
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 90 deletions.
49 changes: 27 additions & 22 deletions pkg/sdk/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,21 @@ type alterTableOptions struct {
name SchemaObjectIdentifier `ddl:"identifier"`

// One of
NewName *SchemaObjectIdentifier `ddl:"identifier" sql:"RENAME TO"`
SwapWith *SchemaObjectIdentifier `ddl:"identifier" sql:"SWAP WITH"`
ClusteringAction *TableClusteringAction `ddl:"keyword"`
ColumnAction *TableColumnAction `ddl:"keyword"`
ConstraintAction *TableConstraintAction `ddl:"keyword"`
ExternalTableAction *TableExternalTableAction `ddl:"keyword"`
SearchOptimizationAction *TableSearchOptimizationAction `ddl:"keyword"`
Set *TableSet `ddl:"keyword" sql:"SET"`
SetTags []TagAssociation `ddl:"parameter,no_equals" sql:"SET TAG"`
UnsetTags []ObjectIdentifier `ddl:"keyword" sql:"UNSET TAG"`
Unset *TableUnset `ddl:"keyword" sql:"UNSET"`
AddRowAccessPolicy *AddRowAccessPolicy `ddl:"keyword"`
DropRowAccessPolicy *string `ddl:"parameter,no_equals" sql:"DROP ROW ACCESS POLICY"`
DropAndAddRowAccessPolicy *DropAndAddRowAccessPolicy `ddl:"keyword"`
DropAllAccessRowPolicies *bool `ddl:"keyword" sql:"DROP ALL ROW ACCESS POLICIES"`
NewName *SchemaObjectIdentifier `ddl:"identifier" sql:"RENAME TO"`
SwapWith *SchemaObjectIdentifier `ddl:"identifier" sql:"SWAP WITH"`
ClusteringAction *TableClusteringAction `ddl:"keyword"`
ColumnAction *TableColumnAction `ddl:"keyword"`
ConstraintAction *TableConstraintAction `ddl:"keyword"`
ExternalTableAction *TableExternalTableAction `ddl:"keyword"`
SearchOptimizationAction *TableSearchOptimizationAction `ddl:"keyword"`
Set *TableSet `ddl:"keyword" sql:"SET"`
SetTags []TagAssociation `ddl:"parameter,no_equals" sql:"SET TAG"`
UnsetTags []ObjectIdentifier `ddl:"keyword" sql:"UNSET TAG"`
Unset *TableUnset `ddl:"keyword" sql:"UNSET"`
AddRowAccessPolicy *TableAddRowAccessPolicy `ddl:"keyword"`
DropRowAccessPolicy *TableDropRowAccessPolicy `ddl:"keyword"`
DropAndAddRowAccessPolicy *TableDropAndAddRowAccessPolicy `ddl:"list,no_parentheses"`
DropAllAccessRowPolicies *bool `ddl:"keyword" sql:"DROP ALL ROW ACCESS POLICIES"`
}

type TableClusteringAction struct {
Expand Down Expand Up @@ -458,15 +458,20 @@ type TableUnset struct {
Comment *bool `ddl:"keyword" sql:"COMMENT"`
}

type AddRowAccessPolicy struct {
PolicyName string `ddl:"parameter,no_equals" sql:"ADD ROW ACCESS POLICY"`
ColumnNames []string `ddl:"parameter,no_equals,parentheses" sql:"ON"`
type TableAddRowAccessPolicy struct {
add bool `ddl:"static" sql:"ADD"`
RowAccessPolicy SchemaObjectIdentifier `ddl:"identifier" sql:"ROW ACCESS POLICY"`
On []string `ddl:"keyword,parentheses" sql:"ON"`
}

type DropAndAddRowAccessPolicy struct {
DroppedPolicyName string `ddl:"parameter,no_equals" sql:"DROP ROW ACCESS POLICY"`
comma bool `ddl:"static" sql:","`
AddedPolicy *AddRowAccessPolicy `ddl:"keyword"`
type TableDropRowAccessPolicy struct {
drop bool `ddl:"static" sql:"DROP"`
RowAccessPolicy SchemaObjectIdentifier `ddl:"identifier" sql:"ROW ACCESS POLICY"`
}

type TableDropAndAddRowAccessPolicy struct {
Drop TableDropRowAccessPolicy `ddl:"keyword"`
Add TableAddRowAccessPolicy `ddl:"keyword"`
}

// dropTableOptions is based on https://docs.snowflake.com/en/sql-reference/sql/drop-table
Expand Down
27 changes: 18 additions & 9 deletions pkg/sdk/tables_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ type AlterTableRequest struct {
SetTags []TagAssociationRequest
UnsetTags []ObjectIdentifier
Unset *TableUnsetRequest
AddRowAccessPolicy *AddRowAccessPolicyRequest
DropRowAccessPolicy *string
DropAndAddRowAccessPolicy *DropAndAddRowAccessPolicyRequest
AddRowAccessPolicy *TableAddRowAccessPolicyRequest
DropRowAccessPolicy *TableDropRowAccessPolicyRequest
DropAndAddRowAccessPolicy *TableDropAndAddRowAccessPolicy
DropAllAccessRowPolicies *bool
}

Expand Down Expand Up @@ -227,9 +227,18 @@ func (s *ShowTableRequest) toOpts() *showTableOptions {
}
}

type DropAndAddRowAccessPolicyRequest struct {
DroppedPolicyName string // required
AddedPolicy AddRowAccessPolicyRequest // required
type TableAddRowAccessPolicyRequest struct {
RowAccessPolicy SchemaObjectIdentifier // required
On []string // required
}

type TableDropRowAccessPolicyRequest struct {
RowAccessPolicy SchemaObjectIdentifier // required
}

type TableDropAndAddRowAccessPolicyRequest struct {
Drop TableDropRowAccessPolicyRequest // required
Add TableAddRowAccessPolicyRequest // required
}

type TableUnsetRequest struct {
Expand Down Expand Up @@ -438,7 +447,7 @@ type TableConstraintAlterActionRequest struct {
Unique *bool
ForeignKey *bool

Columns []string
Columns []string // required
// Optional
Enforced *bool
NotEnforced *bool
Expand All @@ -455,7 +464,7 @@ type TableConstraintDropActionRequest struct {
Unique *bool
ForeignKey *bool

Columns []string
Columns []string // required

// Optional
Cascade *bool
Expand Down Expand Up @@ -499,7 +508,7 @@ type TableExternalTableColumnRenameActionRequest struct {
}

type TableExternalTableColumnDropActionRequest struct {
Columns []string
Columns []string //required

Check failure on line 511 in pkg/sdk/tables_dto.go

View workflow job for this annotation

GitHub Actions / reviewdog

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 511 in pkg/sdk/tables_dto.go

View workflow job for this annotation

GitHub Actions / reviewdog

[golangci] reported by reviewdog 🐶 commentFormatting: put a space between `//` and comment text (gocritic) Raw Output: pkg/sdk/tables_dto.go:511:20: commentFormatting: put a space between `//` and comment text (gocritic) Columns []string //required ^
IfExists *bool
}

Expand Down
71 changes: 40 additions & 31 deletions pkg/sdk/tables_dto_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,17 +629,17 @@ func (s *AlterTableRequest) WithUnset(unset *TableUnsetRequest) *AlterTableReque
return s
}

func (s *AlterTableRequest) WithAddRowAccessPolicy(addRowAccessPolicy *AddRowAccessPolicyRequest) *AlterTableRequest {
func (s *AlterTableRequest) WithAddRowAccessPolicy(addRowAccessPolicy *TableAddRowAccessPolicyRequest) *AlterTableRequest {
s.AddRowAccessPolicy = addRowAccessPolicy
return s
}

func (s *AlterTableRequest) WithDropRowAccessPolicy(dropRowAccessPolicy *string) *AlterTableRequest {
func (s *AlterTableRequest) WithDropRowAccessPolicy(dropRowAccessPolicy *TableDropRowAccessPolicyRequest) *AlterTableRequest {
s.DropRowAccessPolicy = dropRowAccessPolicy
return s
}

func (s *AlterTableRequest) WithDropAndAddRowAccessPolicy(dropAndAddRowAccessPolicy *DropAndAddRowAccessPolicyRequest) *AlterTableRequest {
func (s *AlterTableRequest) WithDropAndAddRowAccessPolicy(dropAndAddRowAccessPolicy *TableDropAndAddRowAccessPolicy) *AlterTableRequest {
s.DropAndAddRowAccessPolicy = dropAndAddRowAccessPolicy
return s
}
Expand Down Expand Up @@ -672,13 +672,31 @@ func (s *DropTableRequest) WithRestrict(restrict *bool) *DropTableRequest {
return s
}

func NewDropAndAddRowAccessPolicyRequest(
droppedPolicyName string,
addedPolicy AddRowAccessPolicyRequest,
) *DropAndAddRowAccessPolicyRequest {
s := DropAndAddRowAccessPolicyRequest{}
s.DroppedPolicyName = droppedPolicyName
s.AddedPolicy = addedPolicy
func NewTableAddRowAccessPolicyRequest(
RowAccessPolicy SchemaObjectIdentifier,

Check failure on line 676 in pkg/sdk/tables_dto_generated.go

View workflow job for this annotation

GitHub Actions / reviewdog

captLocal: `RowAccessPolicy' should not be capitalized (gocritic)

Check failure on line 676 in pkg/sdk/tables_dto_generated.go

View workflow job for this annotation

GitHub Actions / reviewdog

[golangci] reported by reviewdog 🐶 captLocal: `RowAccessPolicy' should not be capitalized (gocritic) Raw Output: pkg/sdk/tables_dto_generated.go:676:2: captLocal: `RowAccessPolicy' should not be capitalized (gocritic) RowAccessPolicy SchemaObjectIdentifier, ^
On []string,

Check failure on line 677 in pkg/sdk/tables_dto_generated.go

View workflow job for this annotation

GitHub Actions / reviewdog

captLocal: `On' should not be capitalized (gocritic)

Check failure on line 677 in pkg/sdk/tables_dto_generated.go

View workflow job for this annotation

GitHub Actions / reviewdog

[golangci] reported by reviewdog 🐶 captLocal: `On' should not be capitalized (gocritic) Raw Output: pkg/sdk/tables_dto_generated.go:677:2: captLocal: `On' should not be capitalized (gocritic) On []string, ^
) *TableAddRowAccessPolicyRequest {
s := TableAddRowAccessPolicyRequest{}
s.RowAccessPolicy = RowAccessPolicy
s.On = On
return &s
}

func NewTableDropRowAccessPolicyRequest(
RowAccessPolicy SchemaObjectIdentifier,

Check failure on line 686 in pkg/sdk/tables_dto_generated.go

View workflow job for this annotation

GitHub Actions / reviewdog

captLocal: `RowAccessPolicy' should not be capitalized (gocritic)

Check failure on line 686 in pkg/sdk/tables_dto_generated.go

View workflow job for this annotation

GitHub Actions / reviewdog

[golangci] reported by reviewdog 🐶 captLocal: `RowAccessPolicy' should not be capitalized (gocritic) Raw Output: pkg/sdk/tables_dto_generated.go:686:2: captLocal: `RowAccessPolicy' should not be capitalized (gocritic) RowAccessPolicy SchemaObjectIdentifier, ^
) *TableDropRowAccessPolicyRequest {
s := TableDropRowAccessPolicyRequest{}
s.RowAccessPolicy = RowAccessPolicy
return &s
}

func NewTableDropAndAddRowAccessPolicyRequest(
drop TableDropRowAccessPolicyRequest,
add TableAddRowAccessPolicyRequest,
) *TableDropAndAddRowAccessPolicyRequest {
s := TableDropAndAddRowAccessPolicyRequest{}
s.Drop = drop
s.Add = add
return &s
}

Expand Down Expand Up @@ -1351,8 +1369,10 @@ func (s *TableConstraintRenameActionRequest) WithNewName(newName string) *TableC
return s
}

func NewTableConstraintAlterActionRequest() *TableConstraintAlterActionRequest {
return &TableConstraintAlterActionRequest{}
func NewTableConstraintAlterActionRequest(columns []string) *TableConstraintAlterActionRequest {
return &TableConstraintAlterActionRequest{
Columns: columns,
}
}

func (s *TableConstraintAlterActionRequest) WithConstraintName(constraintName *string) *TableConstraintAlterActionRequest {
Expand All @@ -1375,11 +1395,6 @@ func (s *TableConstraintAlterActionRequest) WithForeignKey(foreignKey *bool) *Ta
return s
}

func (s *TableConstraintAlterActionRequest) WithColumns(columns []string) *TableConstraintAlterActionRequest {
s.Columns = columns
return s
}

func (s *TableConstraintAlterActionRequest) WithEnforced(enforced *bool) *TableConstraintAlterActionRequest {
s.Enforced = enforced
return s
Expand Down Expand Up @@ -1410,8 +1425,10 @@ func (s *TableConstraintAlterActionRequest) WithNoRely(noRely *bool) *TableConst
return s
}

func NewTableConstraintDropActionRequest() *TableConstraintDropActionRequest {
return &TableConstraintDropActionRequest{}
func NewTableConstraintDropActionRequest(columns []string) *TableConstraintDropActionRequest {
return &TableConstraintDropActionRequest{
Columns: columns,
}
}

func (s *TableConstraintDropActionRequest) WithConstraintName(constraintName *string) *TableConstraintDropActionRequest {
Expand All @@ -1434,11 +1451,6 @@ func (s *TableConstraintDropActionRequest) WithForeignKey(foreignKey *bool) *Tab
return s
}

func (s *TableConstraintDropActionRequest) WithColumns(columns []string) *TableConstraintDropActionRequest {
s.Columns = columns
return s
}

func (s *TableConstraintDropActionRequest) WithCascade(cascade *bool) *TableConstraintDropActionRequest {
s.Cascade = cascade
return s
Expand Down Expand Up @@ -1564,13 +1576,10 @@ func (s *TableExternalTableColumnRenameActionRequest) WithNewName(newName string
return s
}

func NewTableExternalTableColumnDropActionRequest() *TableExternalTableColumnDropActionRequest {
return &TableExternalTableColumnDropActionRequest{}
}

func (s *TableExternalTableColumnDropActionRequest) WithColumns(columns []string) *TableExternalTableColumnDropActionRequest {
s.Columns = columns
return s
func NewTableExternalTableColumnDropActionRequest(columns []string) *TableExternalTableColumnDropActionRequest {
return &TableExternalTableColumnDropActionRequest{
Columns: columns,
}
}

func (s *TableExternalTableColumnDropActionRequest) WithIfExists() *TableExternalTableColumnDropActionRequest {
Expand Down
33 changes: 21 additions & 12 deletions pkg/sdk/tables_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,31 @@ func (s *AlterTableRequest) toOpts() *alterTableOptions {
Comment: Bool(s.Unset.Comment),
}
}
var addRowAccessPolicy *AddRowAccessPolicy
var addRowAccessPolicy *TableAddRowAccessPolicy
if s.AddRowAccessPolicy != nil {
addRowAccessPolicy = &AddRowAccessPolicy{
PolicyName: s.AddRowAccessPolicy.PolicyName,
ColumnNames: s.AddRowAccessPolicy.ColumnName,
addRowAccessPolicy = &TableAddRowAccessPolicy{
RowAccessPolicy: s.AddRowAccessPolicy.RowAccessPolicy,
On: s.AddRowAccessPolicy.On,
}
}
var dropAndAddRowAccessPolicy *DropAndAddRowAccessPolicy
var dropRowAccessPolicy *TableDropRowAccessPolicy
if s.DropRowAccessPolicy != nil {
dropRowAccessPolicy = &TableDropRowAccessPolicy{
RowAccessPolicy: s.DropRowAccessPolicy.RowAccessPolicy,
}
}
var dropAndAddRowAccessPolicy *TableDropAndAddRowAccessPolicy
if s.DropAndAddRowAccessPolicy != nil {
addRowAccessPolicy := &AddRowAccessPolicy{
PolicyName: s.DropAndAddRowAccessPolicy.AddedPolicy.PolicyName,
ColumnNames: s.DropAndAddRowAccessPolicy.AddedPolicy.ColumnName,
add := TableAddRowAccessPolicy{
RowAccessPolicy: s.DropAndAddRowAccessPolicy.Add.RowAccessPolicy,
On: s.DropAndAddRowAccessPolicy.Add.On,
}
drop := TableDropRowAccessPolicy{
RowAccessPolicy: s.DropAndAddRowAccessPolicy.Drop.RowAccessPolicy,
}
dropAndAddRowAccessPolicy = &DropAndAddRowAccessPolicy{
DroppedPolicyName: s.DropAndAddRowAccessPolicy.DroppedPolicyName,
AddedPolicy: addRowAccessPolicy,
dropAndAddRowAccessPolicy = &TableDropAndAddRowAccessPolicy{
Drop: drop,
Add: add,
}
}

Expand All @@ -193,7 +202,7 @@ func (s *AlterTableRequest) toOpts() *alterTableOptions {
UnsetTags: s.UnsetTags,
Unset: tableUnset,
AddRowAccessPolicy: addRowAccessPolicy,
DropRowAccessPolicy: s.DropRowAccessPolicy,
DropRowAccessPolicy: dropRowAccessPolicy,
DropAndAddRowAccessPolicy: dropAndAddRowAccessPolicy,
DropAllAccessRowPolicies: s.DropAllAccessRowPolicies,
}
Expand Down
Loading

0 comments on commit 6f924bd

Please sign in to comment.