Skip to content

Commit 41b531b

Browse files
authored
fix: handling empty schema for table level schemas (#6233)
# Description - Do validation of table-level schemas only in case if some schema is present. ## Linear Ticket - Resolves WAR-1017 ## Security - [x] The code changed/added as part of this pull request won't create any security issues with how the software is being used.
1 parent 5aaadfb commit 41b531b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

warehouse/internal/repo/schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ func (sh *WHSchema) GetForNamespace(ctx context.Context, destID, namespace strin
214214
if err != nil {
215215
return model.WHSchema{}, err
216216
}
217+
if len(originalSchema.Schema) == 0 {
218+
return originalSchema, nil
219+
}
217220

218221
var tableLevelSchemas model.Schema
219222
err = sh.WithTx(ctx, func(tx *sqlmiddleware.Tx) error {

warehouse/internal/repo/schema_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,26 @@ func TestWHSchemasRepo(t *testing.T) {
417417
{TableName: "table_name_2", Schema: schemaModel["table_name_2"]},
418418
}, tableLevelSchemasResult)
419419
})
420+
421+
t.Run("Empty schema", func(t *testing.T) {
422+
emptySchema := model.WHSchema{
423+
SourceID: "empty_source_id_1",
424+
Namespace: "empty_namespace_1",
425+
DestinationID: "empty_destination_id_1",
426+
DestinationType: destinationType,
427+
Schema: map[string]model.TableSchema{},
428+
CreatedAt: now,
429+
UpdatedAt: now,
430+
ExpiresAt: now.Add(time.Hour),
431+
}
432+
433+
err := r.Insert(ctx, &emptySchema)
434+
require.NoError(t, err)
435+
436+
expectedSchema, err := r.GetForNamespace(ctx, "empty_destination_id_1", "empty_namespace_1")
437+
require.NoError(t, err)
438+
require.Empty(t, expectedSchema.Schema)
439+
})
420440
})
421441
})
422442
}

0 commit comments

Comments
 (0)