Skip to content

Commit

Permalink
fix: removed transformers validation that does not have apply_for_ref…
Browse files Browse the repository at this point in the history
…erences (#236)

fix: removed transformers validation that does not have
apply_for_references

* Skip transformers validation when not apply_for_references
* Add regression test

Closes #235
  • Loading branch information
wwoytenko authored Nov 8, 2024
1 parent 08770a5 commit 98c4019
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/db/postgres/context/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ func checkApplyForReferenceMetRequirements(
) (bool, toolkit.ValidationWarnings) {
warnings := toolkit.ValidationWarnings{}
for _, tr := range tcm.config.Transformers {
if !tr.ApplyForReferences {
continue
}
allowed, w := isTransformerAllowedToApplyForReferences(tr, r)
if !allowed {
warnings = append(warnings, w...)
Expand Down
54 changes: 54 additions & 0 deletions internal/db/postgres/context/config_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,60 @@ func Test_validateAndBuildEntriesConfig(t *testing.T) {
}
}
})

t.Run("ApplyForReferences is true and only one col in PK", func(t *testing.T) {
tables, _, _, err := getDumpObjects(ctx, pgVer, tx, opt)
require.NoError(t, err)
graph, err := subset.NewGraph(ctx, tx, tables, nil)
require.NoError(t, err)

cfg := &domains.Dump{
Transformation: []*domains.Table{
{
Schema: "public",
Name: "tablea",
Transformers: []*domains.TransformerConfig{
{
ApplyForReferences: true,
Name: transformers.RandomIntTransformerName,
Params: toolkit.StaticParameters{
"column": toolkit.ParamsValue("id1"),
"engine": toolkit.ParamsValue("hash"),
},
},
{
ApplyForReferences: false,
Name: transformers.RandomIntTransformerName,
Params: toolkit.StaticParameters{
"column": toolkit.ParamsValue("id2"),
"engine": toolkit.ParamsValue("random"),
},
},
},
},
},
}
vw, err := validateAndBuildEntriesConfig(
ctx, tx, tables, typeMap, cfg,
utils.DefaultTransformerRegistry, pgVer, types, graph,
)
require.NoError(t, err)
require.False(t, vw.IsFatal())

expectedTablesWithTransformer := map[string]int{
"tablea": 2,
"tableb": 1,
"tablec": 1,
}

for _, table := range tables {
if _, ok := expectedTablesWithTransformer[table.Name]; ok {
assert.Equalf(t, expectedTablesWithTransformer[table.Name], len(table.TransformersContext), "Table %s", table.Name)
} else {
assert.Empty(t, table.TransformersContext, "Table %s", table.Name)
}
}
})
}

// runPostgresContainer starts a PostgreSQL container and returns the connection string
Expand Down

0 comments on commit 98c4019

Please sign in to comment.