Skip to content

Commit

Permalink
[Fix] Recreate missing system schema (#4068)
Browse files Browse the repository at this point in the history
## Changes

Addresses
#4066.
Makes read function more in line with rest of module to ignore non
`enabled` schemas.

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->

- [x] `make test` run locally
- [ ] ~relevant change in `docs/` folder~
- [ ] covered with integration tests in `internal/acceptance`
- [x] relevant acceptance tests are passing
- [ ] ~using Go SDK~

---------

Co-authored-by: wai Lau <[email protected]>
Co-authored-by: Alex Ott <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent faa6a89 commit 8b2a735
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
11 changes: 11 additions & 0 deletions catalog/resource_system_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,21 @@ func ResourceSystemSchema() common.Resource {
if err != nil {
return err
}
// only track enabled/legacy schemas
if schema.State != catalog.SystemSchemaInfoStateEnableCompleted &&
schema.State != catalog.SystemSchemaInfoStateEnableInitialized &&
schema.State != catalog.SystemSchemaInfoStateUnavailable {
log.Printf("[WARN] %s is not enabled, ignoring it", schemaName)
d.SetId("")
return nil
}

d.Set("full_name", fmt.Sprintf("system.%s", schemaName))
return nil
}
}
log.Printf("[WARN] %s does not exist, ignoring it", schemaName)
d.SetId("")
return nil
},
Update: createOrUpdate,
Expand Down
68 changes: 68 additions & 0 deletions catalog/resource_system_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,74 @@ func TestSystemSchemaRead_Error(t *testing.T) {
assert.Equal(t, "abc|access", d.Id(), "Id should not be empty for error reads")
}

func TestSystemSchemaRead_NotEnabled(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: http.MethodGet,
Resource: "/api/2.1/unity-catalog/metastore_summary",
Response: catalog.GetMetastoreSummaryResponse{
MetastoreId: "abc",
},
},
{
Method: http.MethodGet,
Resource: "/api/2.1/unity-catalog/metastores/abc/systemschemas?",
Response: catalog.ListSystemSchemasResponse{
Schemas: []catalog.SystemSchemaInfo{
{
Schema: "access",
State: catalog.SystemSchemaInfoStateAvailable,
},
{
Schema: "billing",
State: catalog.SystemSchemaInfoStateEnableCompleted,
},
},
},
},
},
Resource: ResourceSystemSchema(),
Read: true,
Removed: true,
ID: "abc|access",
}.Apply(t)
assert.NoError(t, err)
assert.Equal(t, "", d.Id(), "Id should be empty if a schema is not enabled")
}

func TestSystemSchemaRead_NotExists(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: http.MethodGet,
Resource: "/api/2.1/unity-catalog/metastore_summary",
Response: catalog.GetMetastoreSummaryResponse{
MetastoreId: "abc",
},
},
{
Method: http.MethodGet,
Resource: "/api/2.1/unity-catalog/metastores/abc/systemschemas?",
Response: catalog.ListSystemSchemasResponse{
Schemas: []catalog.SystemSchemaInfo{
{
Schema: "billing",
State: catalog.SystemSchemaInfoStateEnableCompleted,
},
},
},
},
},
Resource: ResourceSystemSchema(),
Read: true,
Removed: true,
ID: "abc|access",
}.Apply(t)
assert.NoError(t, err)
assert.Equal(t, "", d.Id(), "Id should be empty if a schema does not exist")
}

func TestSystemSchemaDelete(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand Down

0 comments on commit 8b2a735

Please sign in to comment.