Skip to content

Commit

Permalink
feat: Migrate external tables to new sdk (#2006)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak authored Sep 27, 2023
1 parent f85ec8b commit 5af17cf
Show file tree
Hide file tree
Showing 17 changed files with 3,328 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Integration status - indicates if given resource / datasource is using new SDK.
| Managed Account || snowflake_managed_account | snowflake_managed_account ||
| User || snowflake_user | snowflake_user ||
| Database Role || snowflake_database_role | snowflake_database_role ||
| Role | 👨‍💻 | snowflake_role | snowflake_role | 👨‍💻 |
| Role | | snowflake_role | snowflake_role | 👨‍💻 |
| Grant Privilege to Application Role || snowflake_grant_privileges_to_application_role | snowflake_grants ||
| Grant Privilege to Database Role || snowflake_grant_privileges_to_database_role | snowflake_grants | 👨‍💻 |
| Grant Privilege to Role || snowflake_grant_privileges_to_role | snowflake_grants ||
Expand Down Expand Up @@ -96,7 +96,7 @@ Integration status - indicates if given resource / datasource is using new SDK.
| Share || snowflake_share | snowflake_share ||
| Table | 👨‍💻 | snowflake_table | snowflake_table ||
| Dynamic Table || snowflake_dynamic_table | snowflake_dynamic_table ||
| External Table | 👨‍💻 | snowflake_external_table | snowflake_external_table ||
| External Table | | snowflake_external_table | snowflake_external_table ||
| Event Table || snowflake_event_table | snowflake_event_table ||
| View || snowflake_view | snowflake_view ||
| Materialized View || snowflake_materialized_view | snowflake_materialized_view ||
Expand Down
2 changes: 2 additions & 0 deletions pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Client struct {
Comments Comments
Databases Databases
DatabaseRoles DatabaseRoles
ExternalTables ExternalTables
FailoverGroups FailoverGroups
FileFormats FileFormats
Grants Grants
Expand Down Expand Up @@ -128,6 +129,7 @@ func (c *Client) initialize() {
c.ConversionFunctions = &conversionFunctions{client: c}
c.Databases = &databases{client: c}
c.DatabaseRoles = &databaseRoles{client: c}
c.ExternalTables = &externalTables{client: c}
c.FailoverGroups = &failoverGroups{client: c}
c.FileFormats = &fileFormats{client: c}
c.Grants = &grants{client: c}
Expand Down
59 changes: 59 additions & 0 deletions pkg/sdk/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,65 @@ func (row *propertyRow) toIntProperty() *IntProperty {
}
}

type RowAccessPolicy struct {
rowAccessPolicy bool `ddl:"static" sql:"ROW ACCESS POLICY"`
Name SchemaObjectIdentifier `ddl:"identifier"`
On []string `ddl:"keyword,parentheses" sql:"ON"`
}

type ColumnInlineConstraint struct {
NotNull *bool `ddl:"keyword" sql:"NOT NULL"`
Name *string `ddl:"parameter,no_equals" sql:"CONSTRAINT"`
Type *ColumnConstraintType `ddl:"keyword"`
ForeignKey *InlineForeignKey `ddl:"keyword" sql:"FOREIGN KEY"`

// optional
Enforced *bool `ddl:"keyword" sql:"ENFORCED"`
NotEnforced *bool `ddl:"keyword" sql:"NOT ENFORCED"`
Deferrable *bool `ddl:"keyword" sql:"DEFERRABLE"`
NotDeferrable *bool `ddl:"keyword" sql:"NOT DEFERRABLE"`
InitiallyDeferred *bool `ddl:"keyword" sql:"INITIALLY DEFERRED"`
InitiallyImmediate *bool `ddl:"keyword" sql:"INITIALLY IMMEDIATE"`
Enable *bool `ddl:"keyword" sql:"ENABLE"`
Disable *bool `ddl:"keyword" sql:"DISABLE"`
Validate *bool `ddl:"keyword" sql:"VALIDATE"`
NoValidate *bool `ddl:"keyword" sql:"NOVALIDATE"`
Rely *bool `ddl:"keyword" sql:"RELY"`
NoRely *bool `ddl:"keyword" sql:"NORELY"`
}

type ColumnConstraintType string

var (
ColumnConstraintTypeUnique ColumnConstraintType = "UNIQUE"
ColumnConstraintTypePrimaryKey ColumnConstraintType = "PRIMARY KEY"
ColumnConstraintTypeForeignKey ColumnConstraintType = "FOREIGN KEY"
)

type InlineForeignKey struct {
TableName string `ddl:"keyword" sql:"REFERENCES"`
ColumnName []string `ddl:"keyword,parentheses"`
Match *MatchType `ddl:"keyword" sql:"MATCH"`
On *ForeignKeyOnAction `ddl:"keyword" sql:"ON"`
}

func (v *InlineForeignKey) validate() error {
return nil
}

type MatchType string

var (
FullMatchType MatchType = "FULL"
SimpleMatchType MatchType = "SIMPLE"
PartialMatchType MatchType = "PARTIAL"
)

type ForeignKeyOnAction struct {
OnUpdate *bool `ddl:"parameter,no_equals" sql:"ON UPDATE"`
OnDelete *bool `ddl:"parameter,no_equals" sql:"ON DELETE"`
}

func (row *propertyRow) toBoolProperty() *BoolProperty {
var value bool
if row.Value != "" && row.Value != "null" {
Expand Down
2 changes: 2 additions & 0 deletions pkg/sdk/data_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const (
DataTypeNumber DataType = "NUMBER"
DataTypeFloat DataType = "FLOAT"
DataTypeVARCHAR DataType = "VARCHAR"
DataTypeString DataType = "STRING"
DataTypeBinary DataType = "BINARY"
DataTypeBoolean DataType = "BOOLEAN"
DataTypeDate DataType = "DATE"
DataTypeTime DataType = "TIME"
DataTypeTimestamp DataType = "TIMESTAMP"
DataTypeTimestampLTZ DataType = "TIMESTAMP_LTZ"
DataTypeTimestampNTZ DataType = "TIMESTAMP_NTZ"
DataTypeTimestampTZ DataType = "TIMESTAMP_TZ"
Expand Down
8 changes: 6 additions & 2 deletions pkg/sdk/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ var (
errInvalidObjectIdentifier = errors.New("invalid object identifier")
)

func errOneOf(fieldNames ...string) error {
return fmt.Errorf("fields %v are incompatible and cannot be set at once", fieldNames)
func errOneOf(structName string, fieldNames ...string) error {
return fmt.Errorf("%v fields: %v are incompatible and cannot be set at the same time", structName, fieldNames)
}

func errNotSet(structName string, fieldNames ...string) error {
return fmt.Errorf("%v fields: %v should be set", structName, fieldNames)
}

func errExactlyOneOf(fieldNames ...string) error {
Expand Down
Loading

0 comments on commit 5af17cf

Please sign in to comment.