Skip to content

Commit 8b2a735

Browse files
Waiwaitwai Laualexott
authored
[Fix] Recreate missing system schema (#4068)
## 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]>
1 parent faa6a89 commit 8b2a735

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

catalog/resource_system_schema.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,21 @@ func ResourceSystemSchema() common.Resource {
9393
if err != nil {
9494
return err
9595
}
96+
// only track enabled/legacy schemas
97+
if schema.State != catalog.SystemSchemaInfoStateEnableCompleted &&
98+
schema.State != catalog.SystemSchemaInfoStateEnableInitialized &&
99+
schema.State != catalog.SystemSchemaInfoStateUnavailable {
100+
log.Printf("[WARN] %s is not enabled, ignoring it", schemaName)
101+
d.SetId("")
102+
return nil
103+
}
104+
96105
d.Set("full_name", fmt.Sprintf("system.%s", schemaName))
97106
return nil
98107
}
99108
}
109+
log.Printf("[WARN] %s does not exist, ignoring it", schemaName)
110+
d.SetId("")
100111
return nil
101112
},
102113
Update: createOrUpdate,

catalog/resource_system_schema_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,74 @@ func TestSystemSchemaRead_Error(t *testing.T) {
239239
assert.Equal(t, "abc|access", d.Id(), "Id should not be empty for error reads")
240240
}
241241

242+
func TestSystemSchemaRead_NotEnabled(t *testing.T) {
243+
d, err := qa.ResourceFixture{
244+
Fixtures: []qa.HTTPFixture{
245+
{
246+
Method: http.MethodGet,
247+
Resource: "/api/2.1/unity-catalog/metastore_summary",
248+
Response: catalog.GetMetastoreSummaryResponse{
249+
MetastoreId: "abc",
250+
},
251+
},
252+
{
253+
Method: http.MethodGet,
254+
Resource: "/api/2.1/unity-catalog/metastores/abc/systemschemas?",
255+
Response: catalog.ListSystemSchemasResponse{
256+
Schemas: []catalog.SystemSchemaInfo{
257+
{
258+
Schema: "access",
259+
State: catalog.SystemSchemaInfoStateAvailable,
260+
},
261+
{
262+
Schema: "billing",
263+
State: catalog.SystemSchemaInfoStateEnableCompleted,
264+
},
265+
},
266+
},
267+
},
268+
},
269+
Resource: ResourceSystemSchema(),
270+
Read: true,
271+
Removed: true,
272+
ID: "abc|access",
273+
}.Apply(t)
274+
assert.NoError(t, err)
275+
assert.Equal(t, "", d.Id(), "Id should be empty if a schema is not enabled")
276+
}
277+
278+
func TestSystemSchemaRead_NotExists(t *testing.T) {
279+
d, err := qa.ResourceFixture{
280+
Fixtures: []qa.HTTPFixture{
281+
{
282+
Method: http.MethodGet,
283+
Resource: "/api/2.1/unity-catalog/metastore_summary",
284+
Response: catalog.GetMetastoreSummaryResponse{
285+
MetastoreId: "abc",
286+
},
287+
},
288+
{
289+
Method: http.MethodGet,
290+
Resource: "/api/2.1/unity-catalog/metastores/abc/systemschemas?",
291+
Response: catalog.ListSystemSchemasResponse{
292+
Schemas: []catalog.SystemSchemaInfo{
293+
{
294+
Schema: "billing",
295+
State: catalog.SystemSchemaInfoStateEnableCompleted,
296+
},
297+
},
298+
},
299+
},
300+
},
301+
Resource: ResourceSystemSchema(),
302+
Read: true,
303+
Removed: true,
304+
ID: "abc|access",
305+
}.Apply(t)
306+
assert.NoError(t, err)
307+
assert.Equal(t, "", d.Id(), "Id should be empty if a schema does not exist")
308+
}
309+
242310
func TestSystemSchemaDelete(t *testing.T) {
243311
d, err := qa.ResourceFixture{
244312
Fixtures: []qa.HTTPFixture{

0 commit comments

Comments
 (0)