Skip to content

Commit

Permalink
feat: Migrate storage integration to the new sdk (#2339)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak authored Jan 16, 2024
1 parent bd72c05 commit d970a56
Show file tree
Hide file tree
Showing 15 changed files with 1,586 additions and 69 deletions.
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,59 +66,59 @@ Integration status - indicates if given resource / datasource is using new SDK.
| Object Type | SDK migration status | Resource name | Datasource name | Integration status |
|-------------------------------------|----------------------|------------------------------------------------|-------------------------------|--------------------|
| Account || snowflake_account | snowflake_account ||
| Managed Account | | snowflake_managed_account | snowflake_managed_account ||
| 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 | 👨‍💻 |
| 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 ||
| Grant Role | | snowflake_grant_role | snowflake_grants | |
| Grant Database Role || snowflake_grant_database_role | snowflake_grants | |
| Grant Application Role | | snowflake_grant_application_role | snowflake_grants ||
| 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 ||
| Grant Role | | snowflake_grant_role | snowflake_grants | 👨‍💻 |
| Grant Database Role || snowflake_grant_database_role | snowflake_grants | 👨‍💻 |
| Grant Application Role | | snowflake_grant_application_role | snowflake_grants ||
| Grant Privilege to Share || snowflake_grant_privileges_to_share | snowflake_grants ||
| Grant Ownership || snowflake_grant_ownership | snowflake_grants ||
| API Integration || snowflake_api_integration | snowflake_integrations ||
| Notification Integration || snowflake_notification_integration | snowflake_integrations ||
| Security Integration || snowflake_security_integration | snowflake_integrations ||
| Storage Integration | | snowflake_storage_integration | snowflake_integrations ||
| Storage Integration | | snowflake_storage_integration | snowflake_integrations ||
| Network Policy || snowflake_network_policy | snowflake_network_policy ||
| Password Policy || snowflake_password_policy | snowflake_password_policy ||
| Session Policy || snowflake_session_policy | snowflake_session_policy ||
| Replication Group || snowflake_replication_group | snowflake_replication_group ||
| Failover Group || snowflake_failover_group | snowflake_failover_group ||
| Connection || snowflake_connection | snowflake_connection ||
| Account Parameters || snowflake_account_parameter | snowflake_parameters | |
| Session Parameters || snowflake_session_parameter | snowflake_parameters | |
| Object Parameters || snowflake_object_parameter | snowflake_parameters | |
| Account Parameters || snowflake_account_parameter | snowflake_parameters | |
| Session Parameters || snowflake_session_parameter | snowflake_parameters | |
| Object Parameters || snowflake_object_parameter | snowflake_parameters | |
| Warehouse || snowflake_warehouse | snowflake_warehouse | 🟨 |
| Resource Monitor || snowflake_resource_monitor | snowflake_resource_monitor ||
| Database || snowflake_database | snowflake_database ||
| Schema || snowflake_schema | snowflake_schema ||
| 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 | |
| Event Table | | snowflake_event_table | snowflake_event_table ||
| View | | snowflake_view | snowflake_view ||
| Table | | snowflake_table | snowflake_table ||
| Dynamic Table || snowflake_dynamic_table | snowflake_dynamic_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 ||
| Sequence || snowflake_sequence | snowflake_sequence ||
| Function | | snowflake_function | snowflake_function ||
| External Function | | snowflake_external_function | snowflake_external_function ||
| Stored Procedure | | snowflake_stored_procedure | snowflake_stored_procedure ||
| Function | | snowflake_function | snowflake_function ||
| External Function | | snowflake_external_function | snowflake_external_function ||
| Stored Procedure | | snowflake_stored_procedure | snowflake_stored_procedure ||
| Stream || snowflake_stream | snowflake_stream ||
| Task || snowflake_task | snowflake_task | |
| Task || snowflake_task | snowflake_task | |
| Masking Policy || snowflake_masking_policy | snowflake_masking_policy ||
| Row Access Policy | | snowflake_row_access_policy | snowflake_row_access_policy ||
| Row Access Policy | 👨‍💻 | snowflake_row_access_policy | snowflake_row_access_policy ||
| Tag || snowflake_tag | snowflake_tag ||
| Secret || snowflake_secret | snowflake_secret ||
| Stage | | snowflake_stage | snowflake_stage ||
| Stage | 🟨 | snowflake_stage | snowflake_stage ||
| File Format || snowflake_file_format | snowflake_file_format ||
| Pipe || snowflake_pipe | snowflake_pipe ||
| Alert || snowflake_alert | snowflake_alert ||
| Application | | snowflake_application | snowflake_application ||
| Application Package | | snowflake_application_package | snowflake_application_package ||
| Application Role | | snowflake_application_role | snowflake_application_role ||
| Application | 👨‍💻 | snowflake_application | snowflake_application ||
| Application Package | 👨‍💻 | snowflake_application_package | snowflake_application_package ||
| Application Role | | snowflake_application_role | snowflake_application_role ||
| Streamlit || snowflake_streamlit | snowflake_streamlit ||
| Versioned Schema || snowflake_versioned_schema | snowflake_versioned_schema ||
| Tag Association || snowflake_tag_association | snowflake_tag_association ||
Expand Down
68 changes: 35 additions & 33 deletions pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,40 @@ type Client struct {
ReplicationFunctions ReplicationFunctions

// DDL Commands
Accounts Accounts
Alerts Alerts
ApplicationRoles ApplicationRoles
Comments Comments
DatabaseRoles DatabaseRoles
Databases Databases
DynamicTables DynamicTables
ExternalTables ExternalTables
EventTables EventTables
FailoverGroups FailoverGroups
FileFormats FileFormats
Functions Functions
Grants Grants
MaskingPolicies MaskingPolicies
NetworkPolicies NetworkPolicies
Parameters Parameters
PasswordPolicies PasswordPolicies
Pipes Pipes
Procedures Procedures
ResourceMonitors ResourceMonitors
Roles Roles
Schemas Schemas
SessionPolicies SessionPolicies
Sessions Sessions
Shares Shares
Stages Stages
Streams Streams
Tables Tables
Tags Tags
Tasks Tasks
Users Users
Views Views
Warehouses Warehouses
Accounts Accounts
Alerts Alerts
ApplicationRoles ApplicationRoles
Comments Comments
DatabaseRoles DatabaseRoles
Databases Databases
DynamicTables DynamicTables
ExternalTables ExternalTables
EventTables EventTables
FailoverGroups FailoverGroups
FileFormats FileFormats
Functions Functions
Grants Grants
MaskingPolicies MaskingPolicies
NetworkPolicies NetworkPolicies
Parameters Parameters
PasswordPolicies PasswordPolicies
Pipes Pipes
Procedures Procedures
ResourceMonitors ResourceMonitors
Roles Roles
Schemas Schemas
SessionPolicies SessionPolicies
Sessions Sessions
Shares Shares
Stages Stages
StorageIntegrations StorageIntegrations
Streams Streams
Tables Tables
Tags Tags
Tasks Tasks
Users Users
Views Views
Warehouses Warehouses
}

func (c *Client) GetAccountLocator() string {
Expand Down Expand Up @@ -206,6 +207,7 @@ func (c *Client) initialize() {
c.Sessions = &sessions{client: c}
c.Shares = &shares{client: c}
c.Stages = &stages{client: c}
c.StorageIntegrations = &storageIntegrations{client: c}
c.Streams = &streams{client: c}
c.SystemFunctions = &systemFunctions{client: c}
c.Tables = &tables{client: c}
Expand Down
4 changes: 4 additions & 0 deletions pkg/sdk/poc/generator/db_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (v *dbStruct) Text(dbName string) *dbStruct {
return v.Field(dbName, "string")
}

func (v *dbStruct) Time(dbName string) *dbStruct {
return v.Field(dbName, "time.Time")
}

func (v *dbStruct) OptionalText(dbName string) *dbStruct {
return v.Field(dbName, "sql.NullString")
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/sdk/poc/generator/field_transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ type FieldTransformer interface {
Transform(f *Field) *Field
}

func StaticOptions() *StaticTransformer {
return new(StaticTransformer)
}

type StaticTransformer struct {
sqlPrefix string
}

func (v *StaticTransformer) SQL(sqlPrefix string) *StaticTransformer {
v.sqlPrefix = sqlPrefix
return v
}

func (v *StaticTransformer) Transform(f *Field) *Field {
addTagIfMissing(f.Tags, "ddl", "static")
addTagIfMissing(f.Tags, "sql", v.sqlPrefix)
return f
}

type KeywordTransformer struct {
required bool
sqlPrefix string
Expand Down
4 changes: 4 additions & 0 deletions pkg/sdk/poc/generator/plain_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (v *plainStruct) Text(name string) *plainStruct {
return v.Field(name, "string")
}

func (v *plainStruct) Time(name string) *plainStruct {
return v.Field(name, "time.Time")
}

func (v *plainStruct) OptionalText(name string) *plainStruct {
return v.Field(name, "*string")
}
Expand Down
23 changes: 12 additions & 11 deletions pkg/sdk/poc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ import (
)

var definitionMapping = map[string]*generator.Interface{
"database_role_def.go": example.DatabaseRole,
"network_policies_def.go": sdk.NetworkPoliciesDef,
"session_policies_def.go": sdk.SessionPoliciesDef,
"tasks_def.go": sdk.TasksDef,
"streams_def.go": sdk.StreamsDef,
"application_roles_def.go": sdk.ApplicationRolesDef,
"views_def.go": sdk.ViewsDef,
"stages_def.go": sdk.StagesDef,
"functions_def.go": sdk.FunctionsDef,
"procedures_def.go": sdk.ProceduresDef,
"event_tables_def.go": sdk.EventTablesDef,
"database_role_def.go": example.DatabaseRole,
"network_policies_def.go": sdk.NetworkPoliciesDef,
"session_policies_def.go": sdk.SessionPoliciesDef,
"tasks_def.go": sdk.TasksDef,
"streams_def.go": sdk.StreamsDef,
"application_roles_def.go": sdk.ApplicationRolesDef,
"views_def.go": sdk.ViewsDef,
"stages_def.go": sdk.StagesDef,
"functions_def.go": sdk.FunctionsDef,
"procedures_def.go": sdk.ProceduresDef,
"event_tables_def.go": sdk.EventTablesDef,
"storage_integration_def.go": sdk.StorageIntegrationDef,
}

func main() {
Expand Down
Loading

0 comments on commit d970a56

Please sign in to comment.